Add --reinstall option to reinstall current version and show installation location when latest version is already installed

This commit is contained in:
kdusek
2025-11-13 17:51:07 +01:00
parent 979977d16e
commit 811f1b800c
3 changed files with 89 additions and 16 deletions

View File

@@ -198,7 +198,7 @@ check_update_needed() {
if compare_versions "$clean_latest" "$clean_current"; then if compare_versions "$clean_latest" "$clean_current"; then
if [[ "$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 if [[ "$force_reinstall" == "true" ]]; then
print_status "Force reinstall requested, proceeding..." print_status "Force reinstall requested, proceeding..."
return 0 return 0
@@ -492,12 +492,14 @@ show_usage() {
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo " -v, --version Install specific version (default: latest)" echo " -v, --version Install specific version (default: latest)"
echo " -f, --force Force reinstall even if up-to-date" 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 " -p, --package Force installation from package manager"
echo " -b, --binary Force installation from binary" echo " -b, --binary Force installation from binary"
echo echo
echo "Examples:" echo "Examples:"
echo " $0 # Install latest version using best method" echo " $0 # Install latest version using best method"
echo " $0 -v v1.2.7 # Install specific version" 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 --package # Force installation from package manager"
echo " $0 --binary # Force installation from binary" echo " $0 --binary # Force installation from binary"
echo echo
@@ -507,6 +509,7 @@ show_usage() {
main() { main() {
local target_version="" local target_version=""
local force_reinstall=false local force_reinstall=false
local reinstall_current=false
local install_method="auto" local install_method="auto"
# Parse command line arguments # Parse command line arguments
@@ -524,6 +527,10 @@ main() {
force_reinstall=true force_reinstall=true
shift shift
;; ;;
-r|--reinstall)
reinstall_current=true
shift
;;
-p|--package) -p|--package)
install_method="package" install_method="package"
shift shift
@@ -554,6 +561,19 @@ main() {
detect_os detect_os
ARCH=$(get_arch) 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 # Get latest version if not specified
if [[ -z "$target_version" ]]; then if [[ -z "$target_version" ]]; then
get_latest_release get_latest_release

View File

@@ -91,7 +91,7 @@ get_arch() {
esac esac
} }
# Function to get current installed version # Function to get current installed version and location
get_current_version() { get_current_version() {
if command_exists git-credential-manager; then if command_exists git-credential-manager; then
# Extract version from output like "2.6.1+786ab03440ddc82e807a97c0e540f5247e44cec6" # Extract version from output like "2.6.1+786ab03440ddc82e807a97c0e540f5247e44cec6"
@@ -102,10 +102,21 @@ get_current_version() {
else else
CURRENT_VERSION="unknown" CURRENT_VERSION="unknown"
fi 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 else
CURRENT_VERSION="not_installed" CURRENT_VERSION="not_installed"
INSTALL_TYPE="none"
fi fi
echo "$CURRENT_VERSION" echo "$CURRENT_VERSION:$INSTALL_TYPE"
} }
# Function to compare versions (returns 0 if first >= second, 1 if first < second) # 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 # Function to check if update is needed
check_update_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" local latest_version="$1"
print_status "Current version: $current_version" print_status "Current version: $current_version ($install_type)"
print_status "Latest version: $latest_version" print_status "Latest version: $latest_version"
if [[ "$current_version" == "not_installed" ]]; then if [[ "$current_version" == "not_installed" ]]; then
print_status "git-credential-manager is not installed" print_status "git-credential-manager is not installed"
return 0 # Need to install return 0 # Need to install
fi fi
if [[ "$current_version" == "unknown" ]]; then if [[ "$current_version" == "unknown" ]]; then
print_warning "Cannot determine current version, proceeding with update" print_warning "Cannot determine current version, proceeding with update"
return 0 # Assume update needed return 0 # Assume update needed
fi fi
if compare_versions "$latest_version" "$current_version"; then if compare_versions "$latest_version" "$current_version"; then
if [[ "$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 if [[ "$force_reinstall" == "true" ]]; then
print_status "Force reinstall requested, proceeding..." print_status "Force reinstall requested, proceeding..."
return 0 return 0
@@ -490,6 +503,7 @@ show_usage() {
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo " -v, --version Install specific version (default: latest)" echo " -v, --version Install specific version (default: latest)"
echo " -f, --force Force reinstall even if already installed" 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 " -p, --package Force installation from package manager"
echo " -d, --deb Force installation from DEB package" echo " -d, --deb Force installation from DEB package"
echo " -t, --tarball Force installation from tarball" echo " -t, --tarball Force installation from tarball"
@@ -498,6 +512,7 @@ show_usage() {
echo "Examples:" echo "Examples:"
echo " $0 # Install latest version using best method" echo " $0 # Install latest version using best method"
echo " $0 -v v2.6.0 # Install specific version" 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 --package # Force installation from package manager"
echo " $0 --deb # Force installation from DEB package" echo " $0 --deb # Force installation from DEB package"
echo " $0 --checks # Check configuration without installing" echo " $0 --checks # Check configuration without installing"
@@ -533,6 +548,7 @@ run_checks_only() {
main() { main() {
local target_version="" local target_version=""
local force_reinstall=false local force_reinstall=false
local reinstall_current=false
local install_method="auto" local install_method="auto"
local checks_only=false local checks_only=false
@@ -551,6 +567,10 @@ main() {
force_reinstall=true force_reinstall=true
shift shift
;; ;;
-r|--reinstall)
reinstall_current=true
shift
;;
-p|--package) -p|--package)
install_method="package" install_method="package"
shift shift
@@ -580,12 +600,25 @@ main() {
run_checks_only run_checks_only
exit 0 exit 0
fi fi
echo "========================================" echo "========================================"
echo "Git Credential Manager Installer" echo "Git Credential Manager Installer"
echo "========================================" echo "========================================"
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 # Get latest version if not specified
if [[ -z "$target_version" ]]; then if [[ -z "$target_version" ]]; then
get_latest_release get_latest_release

View File

@@ -286,7 +286,7 @@ check_update_needed() {
if compare_versions "$clean_latest" "$clean_current"; then if compare_versions "$clean_latest" "$clean_current"; then
if [[ "$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 if [[ "$force_reinstall" == "true" ]]; then
print_status "Force reinstall requested, proceeding..." print_status "Force reinstall requested, proceeding..."
return 0 return 0
@@ -476,12 +476,14 @@ show_usage() {
echo " -h, --help Show this help message" echo " -h, --help Show this help message"
echo " -v, --version Install specific version (default: latest)" echo " -v, --version Install specific version (default: latest)"
echo " -f, --force Force reinstall even if up-to-date" 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 " -p, --package Force installation from package manager"
echo " -b, --binary Force installation from binary" echo " -b, --binary Force installation from binary"
echo echo
echo "Examples:" echo "Examples:"
echo " $0 # Install latest version using best method" echo " $0 # Install latest version using best method"
echo " $0 -v v0.10.0 # Install specific version" 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 --package # Force installation from package manager"
echo " $0 --binary # Force installation from binary" echo " $0 --binary # Force installation from binary"
echo echo
@@ -491,8 +493,9 @@ show_usage() {
main() { main() {
local target_version="" local target_version=""
local force_reinstall=false local force_reinstall=false
local reinstall_current=false
local install_method="auto" local install_method="auto"
# Parse command line arguments # Parse command line arguments
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
@@ -508,6 +511,10 @@ main() {
force_reinstall=true force_reinstall=true
shift shift
;; ;;
-r|--reinstall)
reinstall_current=true
shift
;;
-p|--package) -p|--package)
install_method="package" install_method="package"
shift shift
@@ -533,11 +540,24 @@ main() {
if [[ $EUID -ne 0 ]]; then if [[ $EUID -ne 0 ]]; then
print_warning "Not running as root. Some operations may require sudo." print_warning "Not running as root. Some operations may require sudo."
fi fi
# Detect system # Detect system
detect_os detect_os
ARCH=$(get_arch) 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 # Get latest version if not specified
if [[ -z "$target_version" ]]; then if [[ -z "$target_version" ]]; then
get_latest_release get_latest_release