diff --git a/InitMate.sh b/InitMate.sh index 77675a7..7cca37b 100644 --- a/InitMate.sh +++ b/InitMate.sh @@ -15,6 +15,28 @@ check_root() { fi } +# Function to check for updates +check_for_updates() { + SCRIPT_DIR=$(dirname "$0") + if [ -d "$SCRIPT_DIR/.git" ]; then + log "Checking for updates..." + cd "$SCRIPT_DIR" || exit + git fetch + LOCAL=$(git rev-parse @) + REMOTE=$(git rev-parse "@{u}") + if [ "$LOCAL" != "$REMOTE" ]; then + log "Updates available. Pulling the latest changes..." + git pull + log "InitMate updated. Please rerun." + exit 0 + else + log "No updates available." + fi + else + log "This is not a Git repository. Skipping update check." + fi +} + # Function to detect the OS and package manager detect_os() { if [[ -f /etc/os-release ]]; then @@ -199,6 +221,7 @@ prompt_reboot() { # Main script execution check_root +check_for_updates detect_os log "Detected OS: $OS, Package Manager: $PKG_MANAGER" if ! prompt_yes_no "Is this correct?"; then