Add --reinstall option to reinstall current version and show installation location when latest version is already installed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,10 +178,12 @@ 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
|
||||
@@ -185,7 +198,7 @@ check_update_needed() {
|
||||
|
||||
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
|
||||
@@ -586,6 +606,19 @@ main() {
|
||||
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
|
||||
|
||||
@@ -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,6 +493,7 @@ show_usage() {
|
||||
main() {
|
||||
local target_version=""
|
||||
local force_reinstall=false
|
||||
local reinstall_current=false
|
||||
local install_method="auto"
|
||||
|
||||
# Parse command line arguments
|
||||
@@ -508,6 +511,10 @@ main() {
|
||||
force_reinstall=true
|
||||
shift
|
||||
;;
|
||||
-r|--reinstall)
|
||||
reinstall_current=true
|
||||
shift
|
||||
;;
|
||||
-p|--package)
|
||||
install_method="package"
|
||||
shift
|
||||
@@ -538,6 +545,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
|
||||
|
||||
Reference in New Issue
Block a user