From 1e930c27758bc9733b592ed527f01fe9c3376e00 Mon Sep 17 00:00:00 2001 From: zaphod-black Date: Sun, 2 Nov 2025 00:41:23 -0500 Subject: [PATCH] Feature: System-wide installation with PBSClientTool command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added ability to install the script system-wide, making it available as a command from anywhere on the system. No more need to navigate to the script directory or remember the path. NEW FEATURES: 1. Command-line argument support: - --install : Install to /usr/local/bin/PBSClientTool - --uninstall : Remove from system (keeps configs) - --help, -h : Show comprehensive help message - --version, -v : Show version information - (no args) : Run interactive menu (default) 2. Installation function (install_script): - Detects if already installed - Asks for confirmation before overwriting - Copies script to /usr/local/bin/PBSClientTool - Sets executable permissions - Shows usage examples after installation 3. Uninstallation function (uninstall_script): - Removes /usr/local/bin/PBSClientTool - Preserves backup targets and configurations - Warns about difference vs complete removal (uninstaller.sh) - Requires confirmation before proceeding 4. Help system: - Comprehensive --help message with examples - Documents all command-line options - Shows features and documentation link - Formatted for easy reading IMPLEMENTATION: - Added SCRIPT_NAME and INSTALL_PATH constants (lines 13-14) - Added install_script() function (lines 1995-2032) - Added uninstall_script() function (lines 2035-2067) - Added show_help() function (lines 2070-2113) - Added show_version() function (lines 2116-2118) - Added argument parsing before main() (lines 2325-2348) - Updated README with installation instructions - Updated CHANGELOG with new features USAGE EXAMPLES: Install to system: cd PBSClientTool sudo ./pbs-client-installer.sh --install Run from anywhere: sudo PBSClientTool Show help: sudo PBSClientTool --help Uninstall: sudo PBSClientTool --uninstall Update after git pull: git pull sudo ./pbs-client-installer.sh --install # Overwrites old version BENEFITS: - More convenient access from any directory - Follows standard Unix tool conventions - Easy to update (git pull + reinstall) - Safer workflow (don't need to cd into dev directory as root) - Professional user experience 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- CHANGELOG.md | 10 +++ README.md | 52 ++++++++++++++ pbs-client-installer.sh | 155 +++++++++++++++++++++++++++++++++++++++- 3 files changed, 215 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12f2db0..a729400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Script version bumped to 1.1.0 for multi-target support ### Added +- **System-wide installation support** + - New `--install` flag to install PBSClientTool to /usr/local/bin + - Run from anywhere with `sudo PBSClientTool` command + - No need to navigate to script directory + - Includes `--uninstall` to remove from system + - Added `--help` and `--version` flags for command-line usage + - Installation preserves original script (safe to update via git pull) + - install_script() function handles installation with overwrite confirmation + - uninstall_script() function removes command but keeps configurations + - Command-line argument parsing before main() execution - **Automatic connection testing at startup** - All configured targets are automatically tested when script starts - Quick authentication check (5 second timeout per target) diff --git a/README.md b/README.md index 95972cb..aee7979 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Interactive bash script that automatically installs and configures Proxmox Backu ## Features +- **Multi-target backup support** - Backup to multiple PBS servers for redundancy - **Auto-detects Linux distribution** (Ubuntu 20.04/22.04/24.04, Debian 10/11/12, Arch Linux) - **Installs correct PBS client version** for your system - **Interactive configuration** via console prompts @@ -12,6 +13,57 @@ Interactive bash script that automatically installs and configures Proxmox Backu - **Configurable retention policies** (daily, weekly, monthly) - **Connection testing** before finalizing setup - **Immediate backup option** after installation +- **System-wide installation** - Run from anywhere with `PBSClientTool` command + +## Installation + +### Quick Install + +```bash +# Clone the repository +git clone https://github.com/zaphod-black/PBSClientTool.git +cd PBSClientTool + +# Install PBSClientTool to your system +sudo ./pbs-client-installer.sh --install +``` + +After installation, you can run the tool from anywhere: + +```bash +sudo PBSClientTool +``` + +### Manual Usage (Without Installing) + +You can also run the script directly without installing: + +```bash +sudo ./pbs-client-installer.sh +``` + +### Command-Line Options + +```bash +sudo PBSClientTool --help # Show help message +sudo PBSClientTool --version # Show version +sudo PBSClientTool --install # Install to /usr/local/bin +sudo PBSClientTool --uninstall # Remove from system +``` + +### Uninstallation + +To remove the PBSClientTool command from your system: + +```bash +sudo PBSClientTool --uninstall +``` + +**Note:** This only removes the command. Your backup targets and configurations are preserved. To completely remove all backups and configurations, use: + +```bash +sudo ./uninstaller.sh +``` ## Prerequisites diff --git a/pbs-client-installer.sh b/pbs-client-installer.sh index b22ef0a..c83769b 100755 --- a/pbs-client-installer.sh +++ b/pbs-client-installer.sh @@ -10,6 +10,8 @@ NC='\033[0m' # No Color # Script configuration SCRIPT_VERSION="1.1.0" +SCRIPT_NAME="PBSClientTool" +INSTALL_PATH="/usr/local/bin/$SCRIPT_NAME" CONFIG_DIR="/etc/proxmox-backup-client" TARGETS_DIR="$CONFIG_DIR/targets" LOG_FILE="/var/log/pbs-client-installer.log" @@ -1989,6 +1991,132 @@ show_summary() { log "Setup completed successfully!" } +# Install script to system PATH +install_script() { + check_root + + echo + echo "╔════════════════════════════════════════╗" + echo "║ Install PBSClientTool ║" + echo "╚════════════════════════════════════════╝" + echo + + # Get the absolute path of this script + SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")" + + if [ -f "$INSTALL_PATH" ]; then + warn "PBSClientTool is already installed at $INSTALL_PATH" + OVERWRITE=$(prompt "Do you want to overwrite it? (yes/no)" "no") + if [ "$OVERWRITE" != "yes" ]; then + info "Installation cancelled" + return 0 + fi + fi + + log "Installing PBSClientTool to $INSTALL_PATH..." + + # Copy script to /usr/local/bin/ + cp "$SCRIPT_PATH" "$INSTALL_PATH" + chmod +x "$INSTALL_PATH" + + log "Installation complete!" + echo + info "You can now run the tool from anywhere using:" + echo " sudo $SCRIPT_NAME" + echo + info "Available commands:" + echo " sudo $SCRIPT_NAME - Run interactive menu" + echo " sudo $SCRIPT_NAME --help - Show help message" + echo " sudo $SCRIPT_NAME --version - Show version" + echo +} + +# Uninstall script from system PATH +uninstall_script() { + check_root + + echo + echo "╔════════════════════════════════════════╗" + echo "║ Uninstall PBSClientTool ║" + echo "╚════════════════════════════════════════╝" + echo + + if [ ! -f "$INSTALL_PATH" ]; then + error "PBSClientTool is not installed at $INSTALL_PATH" + return 1 + fi + + warn "This will remove the PBSClientTool command from your system" + warn "Your backup targets and configurations will NOT be removed" + echo + CONFIRM=$(prompt "Do you want to continue? (yes/no)" "no") + + if [ "$CONFIRM" != "yes" ]; then + info "Uninstall cancelled" + return 0 + fi + + log "Removing $INSTALL_PATH..." + rm -f "$INSTALL_PATH" + + log "Uninstall complete!" + echo + info "To completely remove all backup configurations, use the uninstaller:" + echo " sudo ./uninstaller.sh" + echo +} + +# Show help message +show_help() { + cat << EOF + +Proxmox Backup Client Tool v${SCRIPT_VERSION} + +A tool for managing Proxmox Backup Server client installations and multi-target backups. + +USAGE: + sudo $SCRIPT_NAME [OPTIONS] + +OPTIONS: + --install Install PBSClientTool to /usr/local/bin (makes it available system-wide) + --uninstall Uninstall PBSClientTool from system + --help, -h Show this help message + --version, -v Show version information + +INTERACTIVE MODE (default): + Run without arguments to launch the interactive menu for managing backup targets. + +EXAMPLES: + # Install to system PATH + sudo ./pbs-client-installer.sh --install + + # Run from anywhere after installation + sudo $SCRIPT_NAME + + # Show version + sudo $SCRIPT_NAME --version + + # Uninstall from system + sudo $SCRIPT_NAME --uninstall + +FEATURES: + - Multi-target backup support (backup to multiple PBS servers) + - File-level and block device backups + - Automated backup scheduling with systemd timers + - Connection testing and validation + - Easy target management (add, edit, delete, view) + +DOCUMENTATION: + https://github.com/zaphod-black/PBSClientTool + +EOF +} + +# Show version +show_version() { + echo "PBSClientTool version $SCRIPT_VERSION" +} + # Main script execution main() { echo @@ -2193,5 +2321,28 @@ main() { exit 1 } -# Run main function -main "$@" +# Parse command-line arguments +case "${1:-}" in + --install) + install_script + ;; + --uninstall) + uninstall_script + ;; + --help|-h) + show_help + ;; + --version|-v) + show_version + ;; + "") + # No arguments - run interactive mode + main + ;; + *) + error "Unknown option: $1" + echo + echo "Run with --help for usage information" + exit 1 + ;; +esac