Remove legacy gniza init CLI command

The WHM setup wizard handles all configuration (SSH, S3, GDrive),
making the interactive CLI init wizard redundant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shuki
2026-03-05 19:00:26 +02:00
parent efcd4844e9
commit a5ab2c788a
7 changed files with 11 additions and 194 deletions

View File

@@ -133,7 +133,7 @@ cmd_backup()
`bin/gniza` main() parses the first arg and routes to `cmd_*()` functions. Each command handles its own `--config`, `--remote`, `--account` flags via `get_opt()` and `has_flag()`. `bin/gniza` main() parses the first arg and routes to `cmd_*()` functions. Each command handles its own `--config`, `--remote`, `--account` flags via `get_opt()` and `has_flag()`.
Commands: `backup`, `restore`, `list`, `verify`, `status`, `remote`, `schedule`, `init`, `version`, `help` Commands: `backup`, `restore`, `list`, `verify`, `status`, `remote`, `schedule`, `version`, `help`
### Config Hierarchy ### Config Hierarchy
@@ -541,7 +541,6 @@ All restore functions dispatch by `_is_rclone_mode` — using `rclone_from_remot
| `_list_current_remote(account)` | Display listing for current remote context | | `_list_current_remote(account)` | Display listing for current remote context |
| `_test_connection()` | Dispatch `test_rclone_connection` or `test_ssh_connection` by type | | `_test_connection()` | Dispatch `test_rclone_connection` or `test_ssh_connection` by type |
| `_status_ssh_and_disk()` | Connection test + disk/storage usage display (SSH: df, cloud: rclone about) | | `_status_ssh_and_disk()` | Connection test + disk/storage usage display (SSH: df, cloud: rclone about) |
| `_init_remote(name)` | Interactive remote destination setup |
| `cmd_remote()` | Remote management: list, delete | | `cmd_remote()` | Remote management: list, delete |
| `cmd_schedule()` | Schedule CRUD: add, delete, list, install, show, remove | | `cmd_schedule()` | Schedule CRUD: add, delete, list, install, show, remove |

View File

@@ -35,11 +35,10 @@ The uninstall script removes the CLI, symlink, cron entries, and WHM plugin. Con
## Quick Start ## Quick Start
```bash ```bash
# Interactive setup (creates config + first remote + optional schedule) # Configure via WHM → GNIZA Backup Manager (setup wizard)
sudo gniza init # Or copy example configs manually:
sudo cp /etc/gniza/gniza.conf.example /etc/gniza/gniza.conf
# Add additional remote destinations sudo cp /etc/gniza/remote.conf.example /etc/gniza/remotes.d/nas.conf
sudo gniza init remote offsite
# Test backup (dry run) # Test backup (dry run)
sudo gniza backup --dry-run sudo gniza backup --dry-run
@@ -71,8 +70,6 @@ gniza schedule list
gniza schedule install gniza schedule install
gniza schedule show gniza schedule show
gniza schedule remove gniza schedule remove
gniza init
gniza init remote <name>
gniza version gniza version
gniza help gniza help
``` ```
@@ -124,11 +121,7 @@ Back up to one or more destinations with independent retention policies and band
#### Setup #### Setup
```bash ```bash
# Interactive setup (recommended) # Configure via WHM → Remotes, or copy the template manually
sudo gniza init remote nas
sudo gniza init remote offsite
# Or copy the template manually
sudo cp /etc/gniza/remote.conf.example /etc/gniza/remotes.d/nas.conf sudo cp /etc/gniza/remote.conf.example /etc/gniza/remotes.d/nas.conf
sudo vi /etc/gniza/remotes.d/nas.conf sudo vi /etc/gniza/remotes.d/nas.conf

172
bin/gniza
View File

@@ -881,7 +881,7 @@ cmd_status() {
done <<< "$remotes" done <<< "$remotes"
_restore_remote_globals _restore_remote_globals
else else
echo "No remotes configured. Run 'gniza init remote <name>' to add one." echo "No remotes configured."
fi fi
echo "" echo ""
@@ -918,7 +918,6 @@ cmd_remote() {
list|ls|"") list|ls|"")
if ! has_remotes; then if ! has_remotes; then
echo "No remotes configured." echo "No remotes configured."
echo "Run 'gniza init remote <name>' to add one."
return 0 return 0
fi fi
@@ -1176,170 +1175,6 @@ _schedule_list() {
echo "" echo ""
} }
cmd_init() {
local subcommand="${1:-}"
if [[ "$subcommand" == "remote" ]]; then
shift
_init_remote "$@"
return
fi
local config_dir="/etc/gniza"
local config_file="$config_dir/gniza.conf"
echo "${C_BOLD}gniza init${C_RESET} — Setup wizard"
echo ""
# Step 1: Create main config with local settings
if [[ -f "$config_file" ]]; then
echo "Config file already exists: $config_file"
read -rp "Overwrite? [y/N] " answer
[[ "$answer" =~ ^[Yy]$ ]] || {
echo "Skipping main config."
echo ""
# Still offer to add a remote
echo "Add a remote destination?"
read -rp "Remote name (e.g. nas, offsite): " init_remote_name
if [[ -n "$init_remote_name" ]]; then
_init_remote "$init_remote_name"
fi
return
}
fi
read -rp "Notification email (empty to disable): " init_email
# Create config
mkdir -p "$config_dir"
mkdir -p "$config_dir/remotes.d"
cat > "$config_file" <<CONF
# gniza configuration — generated by 'gniza init'
# $(date -u +"%d/%m/%Y %H:%M:%S UTC")
#
# Remote destinations are configured in /etc/gniza/remotes.d/<name>.conf
# Run 'gniza init remote <name>' to add one.
TEMP_DIR="/usr/local/gniza/workdir"
INCLUDE_ACCOUNTS=""
EXCLUDE_ACCOUNTS="nobody"
LOG_DIR="/var/log/gniza"
LOG_LEVEL="info"
LOG_RETAIN=90
NOTIFY_EMAIL="$init_email"
NOTIFY_ON="failure"
LOCK_FILE="/var/run/gniza.lock"
SSH_TIMEOUT=30
SSH_RETRIES=3
RSYNC_EXTRA_OPTS=""
CONF
echo ""
echo "Config written to $config_file"
# Create log directory
mkdir -p "${LOG_DIR:-$DEFAULT_LOG_DIR}"
# Step 2: Create first remote
echo ""
echo "Now let's set up your first remote destination."
read -rp "Remote name (e.g. nas, offsite): " init_remote_name
[[ -z "$init_remote_name" ]] && die "Remote name is required"
_init_remote "$init_remote_name"
}
_init_remote() {
local name="${1:-}"
[[ -z "$name" ]] && die "Usage: gniza init remote <name>"
# Validate name (alphanumeric, hyphens, underscores)
if ! [[ "$name" =~ ^[a-zA-Z0-9_-]+$ ]]; then
die "Remote name must be alphanumeric (hyphens and underscores allowed): $name"
fi
local config_dir="/etc/gniza/remotes.d"
local config_file="$config_dir/${name}.conf"
echo "${C_BOLD}gniza init remote${C_RESET} — Remote setup: ${C_BOLD}$name${C_RESET}"
echo ""
if [[ -f "$config_file" ]]; then
echo "Remote config already exists: $config_file"
read -rp "Overwrite? [y/N] " answer
[[ "$answer" =~ ^[Yy]$ ]] || { echo "Aborted."; exit 0; }
fi
read -rp "Remote host: " init_host
[[ -z "$init_host" ]] && die "Remote host is required"
read -rp "Remote port [22]: " init_port
init_port="${init_port:-22}"
read -rp "Remote user [root]: " init_user
init_user="${init_user:-root}"
read -rp "SSH key path [/root/.ssh/id_rsa]: " init_key
init_key="${init_key:-/root/.ssh/id_rsa}"
read -rp "Remote base directory [/backups]: " init_base
init_base="${init_base:-/backups}"
read -rp "Retention count [30]: " init_retention
init_retention="${init_retention:-30}"
read -rp "Bandwidth limit in KB/s [0 = unlimited]: " init_bwlimit
init_bwlimit="${init_bwlimit:-0}"
# Create config
mkdir -p "$config_dir"
cat > "$config_file" <<CONF
# gniza remote config: $name
# Generated by 'gniza init remote $name'
# $(date -u +"%d/%m/%Y %H:%M:%S UTC")
REMOTE_HOST="$init_host"
REMOTE_PORT=$init_port
REMOTE_USER="$init_user"
REMOTE_KEY="$init_key"
REMOTE_BASE="$init_base"
BWLIMIT=$init_bwlimit
RETENTION_COUNT=$init_retention
RSYNC_EXTRA_OPTS=""
CONF
echo ""
echo "Remote config written to $config_file"
echo ""
# Test SSH
# Load main config first for defaults, then load remote
local main_config="/etc/gniza/gniza.conf"
if [[ -f "$main_config" ]]; then
load_config "$main_config"
fi
load_remote "$name"
echo "Testing SSH connection to $name..."
if test_ssh_connection 2>/dev/null; then
echo "${C_GREEN}SSH connection successful!${C_RESET}"
echo "Creating remote base directory..."
ensure_remote_dir "${REMOTE_BASE}/$(hostname -f)/accounts"
echo "${C_GREEN}Remote directory created.${C_RESET}"
else
echo "${C_YELLOW}SSH connection failed. Check your settings in $config_file${C_RESET}"
fi
echo ""
echo "${C_GREEN}Remote '$name' configured!${C_RESET}"
echo "Run 'gniza schedule add <name>' to set up a backup schedule."
echo "Run 'gniza backup --remote=$name --dry-run' to test."
}
# ── System Backup / Restore ─────────────────────────────────── # ── System Backup / Restore ───────────────────────────────────
# Transfer + finalize + retention for system backup on the current remote. # Transfer + finalize + retention for system backup on the current remote.
@@ -1666,8 +1501,6 @@ ${C_BOLD}Commands:${C_RESET}
schedule list Show configured schedules schedule list Show configured schedules
schedule {install|show|remove} Manage cron entries schedule {install|show|remove} Manage cron entries
stats Collect backup statistics stats Collect backup statistics
init Setup config + first remote
init remote <name> Add a remote destination
version Show version version Show version
${C_BOLD}Global Options:${C_RESET} ${C_BOLD}Global Options:${C_RESET}
@@ -1676,7 +1509,6 @@ ${C_BOLD}Global Options:${C_RESET}
--debug Enable debug logging --debug Enable debug logging
${C_BOLD}Examples:${C_RESET} ${C_BOLD}Examples:${C_RESET}
gniza init
gniza backup --dry-run gniza backup --dry-run
gniza backup --account=johndoe gniza backup --account=johndoe
gniza backup --remote=nas gniza backup --remote=nas
@@ -1689,7 +1521,6 @@ ${C_BOLD}Examples:${C_RESET}
gniza schedule list gniza schedule list
gniza schedule install gniza schedule install
gniza remote list gniza remote list
gniza init remote nas
gniza sysbackup --dry-run gniza sysbackup --dry-run
gniza sysbackup --remote=nas gniza sysbackup --remote=nas
gniza sysrestore --remote=nas gniza sysrestore --remote=nas
@@ -1718,7 +1549,6 @@ main() {
remote) cmd_remote "$@" ;; remote) cmd_remote "$@" ;;
schedule) cmd_schedule "$@" ;; schedule) cmd_schedule "$@" ;;
stats) cmd_stats "$@" ;; stats) cmd_stats "$@" ;;
init) cmd_init "$@" ;;
version) echo "gniza v${GNIZA_VERSION}" ;; version) echo "gniza v${GNIZA_VERSION}" ;;
help|-h|--help) cmd_usage ;; help|-h|--help) cmd_usage ;;
"") cmd_usage ;; "") cmd_usage ;;

View File

@@ -28,7 +28,7 @@ load_config() {
local config_file="${1:-$DEFAULT_CONFIG_FILE}" local config_file="${1:-$DEFAULT_CONFIG_FILE}"
if [[ ! -f "$config_file" ]]; then if [[ ! -f "$config_file" ]]; then
die "Config file not found: $config_file (run 'gniza init' to create one)" die "Config file not found: $config_file (create via WHM or copy gniza.conf.example)"
fi fi
# Parse the config (safe key=value reader, no code execution) # Parse the config (safe key=value reader, no code execution)

View File

@@ -266,6 +266,6 @@ get_target_remotes() {
fi fi
# No remotes configured # No remotes configured
log_error "No remotes configured. Run 'gniza init remote <name>' to add one." log_error "No remotes configured. Add one via WHM → Remotes."
return 1 return 1
} }

View File

@@ -135,9 +135,4 @@ fi
echo "" echo ""
echo "Next steps:" echo "Next steps:"
if [[ -d /usr/local/cpanel ]]; then echo " Open WHM → GNIZA Backup Manager to configure via the setup wizard."
echo " Open WHM → GNIZA Backup Manager to configure via the setup wizard."
else
echo " 1. Run 'gniza init' to create your configuration"
echo " 2. Run 'gniza status' to verify your setup"
fi

View File

@@ -551,7 +551,7 @@ sub handle_add {
} }
my ($ok, $err) = GnizaWHM::Config::save($dest, \%data, \@GnizaWHM::Config::REMOTE_KEYS); my ($ok, $err) = GnizaWHM::Config::save($dest, \%data, \@GnizaWHM::Config::REMOTE_KEYS);
if ($ok) { if ($ok) {
# Init remote directory structure (like gniza init remote) # Initialize remote directory structure
my $type = $data{REMOTE_TYPE} || 'ssh'; my $type = $data{REMOTE_TYPE} || 'ssh';
my %init_args = ( my %init_args = (
type => $type, type => $type,