From 811f1b800c92a796646eb275196a61aac272909a Mon Sep 17 00:00:00 2001 From: kdusek Date: Thu, 13 Nov 2025 17:51:07 +0100 Subject: [PATCH] Add --reinstall option to reinstall current version and show installation location when latest version is already installed --- install-borg-cli.sh | 22 ++++++++++++- install-git-credential-manager.sh | 55 ++++++++++++++++++++++++------- install-tea-cli.sh | 28 +++++++++++++--- 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/install-borg-cli.sh b/install-borg-cli.sh index cb216a3..f13c55f 100755 --- a/install-borg-cli.sh +++ b/install-borg-cli.sh @@ -198,7 +198,7 @@ check_update_needed() { if compare_versions "$clean_latest" "$clean_current"; then if [[ "$clean_latest" == "$clean_current" ]]; then - print_success "You already have the latest version ($current_version)" + print_success "You already have the latest version ($current_version) installed at $install_type location" if [[ "$force_reinstall" == "true" ]]; then print_status "Force reinstall requested, proceeding..." return 0 @@ -492,12 +492,14 @@ show_usage() { echo " -h, --help Show this help message" echo " -v, --version Install specific version (default: latest)" echo " -f, --force Force reinstall even if up-to-date" + echo " -r, --reinstall Reinstall the current installed version" echo " -p, --package Force installation from package manager" echo " -b, --binary Force installation from binary" echo echo "Examples:" echo " $0 # Install latest version using best method" echo " $0 -v v1.2.7 # Install specific version" + echo " $0 --reinstall # Reinstall current version" echo " $0 --package # Force installation from package manager" echo " $0 --binary # Force installation from binary" echo @@ -507,6 +509,7 @@ show_usage() { main() { local target_version="" local force_reinstall=false + local reinstall_current=false local install_method="auto" # Parse command line arguments @@ -524,6 +527,10 @@ main() { force_reinstall=true shift ;; + -r|--reinstall) + reinstall_current=true + shift + ;; -p|--package) install_method="package" shift @@ -554,6 +561,19 @@ main() { detect_os ARCH=$(get_arch) + # Handle reinstall current version + if [[ "$reinstall_current" == "true" ]]; then + local current_info=$(get_current_version) + local current_version=$(echo "$current_info" | cut -d: -f1) + if [[ "$current_version" == "not_installed" ]]; then + print_error "No current version installed to reinstall" + exit 1 + fi + target_version="$current_version" + force_reinstall=true + print_status "Reinstalling current version: $target_version" + fi + # Get latest version if not specified if [[ -z "$target_version" ]]; then get_latest_release diff --git a/install-git-credential-manager.sh b/install-git-credential-manager.sh index ca1642d..9c1c3a3 100755 --- a/install-git-credential-manager.sh +++ b/install-git-credential-manager.sh @@ -91,7 +91,7 @@ get_arch() { esac } -# Function to get current installed version +# Function to get current installed version and location get_current_version() { if command_exists git-credential-manager; then # Extract version from output like "2.6.1+786ab03440ddc82e807a97c0e540f5247e44cec6" @@ -102,10 +102,21 @@ get_current_version() { else CURRENT_VERSION="unknown" fi + + # Determine installation location + GCM_PATH=$(which git-credential-manager) + if [[ "$GCM_PATH" == "$HOME/bin"* ]]; then + INSTALL_TYPE="user" + elif [[ "$GCM_PATH" == "/usr/local/bin"* ]] || [[ "$GCM_PATH" == "/usr/bin"* ]]; then + INSTALL_TYPE="system" + else + INSTALL_TYPE="other" + fi else CURRENT_VERSION="not_installed" + INSTALL_TYPE="none" fi - echo "$CURRENT_VERSION" + echo "$CURRENT_VERSION:$INSTALL_TYPE" } # Function to compare versions (returns 0 if first >= second, 1 if first < second) @@ -167,25 +178,27 @@ get_latest_release() { # Function to check if update is needed check_update_needed() { - local current_version=$(get_current_version) + local current_info=$(get_current_version) + local current_version=$(echo "$current_info" | cut -d: -f1) + local install_type=$(echo "$current_info" | cut -d: -f2) local latest_version="$1" - - print_status "Current version: $current_version" + + print_status "Current version: $current_version ($install_type)" print_status "Latest version: $latest_version" - + if [[ "$current_version" == "not_installed" ]]; then print_status "git-credential-manager is not installed" return 0 # Need to install fi - + if [[ "$current_version" == "unknown" ]]; then print_warning "Cannot determine current version, proceeding with update" return 0 # Assume update needed fi - + if compare_versions "$latest_version" "$current_version"; then if [[ "$latest_version" == "$current_version" ]]; then - print_success "You already have the latest version ($current_version)" + print_success "You already have the latest version ($current_version) installed at $install_type location" if [[ "$force_reinstall" == "true" ]]; then print_status "Force reinstall requested, proceeding..." return 0 @@ -490,6 +503,7 @@ show_usage() { echo " -h, --help Show this help message" echo " -v, --version Install specific version (default: latest)" echo " -f, --force Force reinstall even if already installed" + echo " -r, --reinstall Reinstall the current installed version" echo " -p, --package Force installation from package manager" echo " -d, --deb Force installation from DEB package" echo " -t, --tarball Force installation from tarball" @@ -498,6 +512,7 @@ show_usage() { echo "Examples:" echo " $0 # Install latest version using best method" echo " $0 -v v2.6.0 # Install specific version" + echo " $0 --reinstall # Reinstall current version" echo " $0 --package # Force installation from package manager" echo " $0 --deb # Force installation from DEB package" echo " $0 --checks # Check configuration without installing" @@ -533,6 +548,7 @@ run_checks_only() { main() { local target_version="" local force_reinstall=false + local reinstall_current=false local install_method="auto" local checks_only=false @@ -551,6 +567,10 @@ main() { force_reinstall=true shift ;; + -r|--reinstall) + reinstall_current=true + shift + ;; -p|--package) install_method="package" shift @@ -580,12 +600,25 @@ main() { run_checks_only exit 0 fi - + echo "========================================" echo "Git Credential Manager Installer" echo "========================================" echo - + + # Handle reinstall current version + if [[ "$reinstall_current" == "true" ]]; then + local current_info=$(get_current_version) + local current_version=$(echo "$current_info" | cut -d: -f1) + if [[ "$current_version" == "not_installed" ]]; then + print_error "No current version installed to reinstall" + exit 1 + fi + target_version="$current_version" + force_reinstall=true + print_status "Reinstalling current version: $target_version" + fi + # Get latest version if not specified if [[ -z "$target_version" ]]; then get_latest_release diff --git a/install-tea-cli.sh b/install-tea-cli.sh index 634226f..7f2b7dd 100755 --- a/install-tea-cli.sh +++ b/install-tea-cli.sh @@ -286,7 +286,7 @@ check_update_needed() { if compare_versions "$clean_latest" "$clean_current"; then if [[ "$clean_latest" == "$clean_current" ]]; then - print_success "You already have the latest version ($current_version)" + print_success "You already have the latest version ($current_version) installed at $install_type location" if [[ "$force_reinstall" == "true" ]]; then print_status "Force reinstall requested, proceeding..." return 0 @@ -476,12 +476,14 @@ show_usage() { echo " -h, --help Show this help message" echo " -v, --version Install specific version (default: latest)" echo " -f, --force Force reinstall even if up-to-date" + echo " -r, --reinstall Reinstall the current installed version" echo " -p, --package Force installation from package manager" echo " -b, --binary Force installation from binary" echo echo "Examples:" echo " $0 # Install latest version using best method" echo " $0 -v v0.10.0 # Install specific version" + echo " $0 --reinstall # Reinstall current version" echo " $0 --package # Force installation from package manager" echo " $0 --binary # Force installation from binary" echo @@ -491,8 +493,9 @@ show_usage() { main() { local target_version="" local force_reinstall=false + local reinstall_current=false local install_method="auto" - + # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in @@ -508,6 +511,10 @@ main() { force_reinstall=true shift ;; + -r|--reinstall) + reinstall_current=true + shift + ;; -p|--package) install_method="package" shift @@ -533,11 +540,24 @@ main() { if [[ $EUID -ne 0 ]]; then print_warning "Not running as root. Some operations may require sudo." fi - + # Detect system detect_os ARCH=$(get_arch) - + + # Handle reinstall current version + if [[ "$reinstall_current" == "true" ]]; then + local current_info=$(get_current_version) + local current_version=$(echo "$current_info" | cut -d: -f1) + if [[ "$current_version" == "not_installed" ]]; then + print_error "No current version installed to reinstall" + exit 1 + fi + target_version="$current_version" + force_reinstall=true + print_status "Reinstalling current version: $target_version" + fi + # Get latest version if not specified if [[ -z "$target_version" ]]; then get_latest_release