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

@@ -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