This commit is contained in:
2026-07-25 16:47:09 -05:00
parent b324d31273
commit bd005495ce
5 changed files with 250 additions and 51 deletions
+90 -30
View File
@@ -6,11 +6,13 @@ DEFAULTS_CACHE_DIR='/var/cache/ta-proxmenu'
DEFAULTS_CHECK_FILE="${DEFAULTS_CACHE_DIR}/defaults-last-check"
DEFAULTS_CHECK_SECONDS=14400
source /opt/idssys/ta-proxmenu/inc/git-update.inc
AUTO_UPDATE_DEFAULTS() {
local checked_at=0
local local_commit
local current_branch
local now
local remote_commit
local state
mkdir -p "$DEFAULTS_CACHE_DIR" 2>/dev/null || true
now="$(date +%s)"
@@ -41,22 +43,46 @@ AUTO_UPDATE_DEFAULTS() {
return
fi
else
if ! timeout 20 git -C "$DEFAULTS_REPOSITORY" fetch origin master \
current_branch="$(git -C "$DEFAULTS_REPOSITORY" branch --show-current 2>/dev/null)"
if [[ "$current_branch" != "master" ]]; then
echo "WARNING: iDSSYS Defaults is not on master; automatic update skipped." >&2
date +%s >"$DEFAULTS_CHECK_FILE"
return
fi
if TAPM_GIT_WORKTREE_DIRTY "$DEFAULTS_REPOSITORY"; then
echo "WARNING: iDSSYS Defaults has local changes; automatic update skipped." >&2
date +%s >"$DEFAULTS_CHECK_FILE"
return
fi
if ! TAPM_GIT_FETCH_BRANCH "$DEFAULTS_REPOSITORY" master 20 \
>/dev/null 2>&1; then
echo "WARNING: Unable to check iDSSYS Defaults; using the installed copy." >&2
return
fi
local_commit="$(git -C "$DEFAULTS_REPOSITORY" rev-parse HEAD)"
remote_commit="$(git -C "$DEFAULTS_REPOSITORY" rev-parse origin/master)"
if [[ "$local_commit" != "$remote_commit" ]]; then
echo "Updating required iDSSYS Defaults..."
if ! git -C "$DEFAULTS_REPOSITORY" reset --hard origin/master \
>/dev/null 2>&1; then
state="$(TAPM_GIT_BRANCH_STATE "$DEFAULTS_REPOSITORY" master)"
case "$state" in
behind)
echo "Updating required iDSSYS Defaults..."
if ! TAPM_GIT_FAST_FORWARD "$DEFAULTS_REPOSITORY" master \
>/dev/null 2>&1; then
echo "WARNING: Unable to update iDSSYS Defaults; using the installed copy." >&2
return
fi
;;
current)
;;
ahead)
echo "WARNING: iDSSYS Defaults has local commits not on origin; automatic update skipped." >&2
;;
diverged)
echo "WARNING: iDSSYS Defaults has diverged from origin; automatic update skipped." >&2
;;
*)
echo "WARNING: Unable to update iDSSYS Defaults; using the installed copy." >&2
return
fi
fi
;;
esac
fi
date +%s >"$DEFAULTS_CHECK_FILE"
@@ -72,36 +98,67 @@ UPDATE_REPOSITORY() {
local repository="$1"
local branch="$2"
local label="$3"
local local_commit
local remote_commit
local current_branch
local state
cd "$repository" || return 1
local_commit="$(git rev-parse HEAD 2>/dev/null)" || return 1
remote_commit="$(git ls-remote origin "refs/heads/${branch}" | cut -f1)"
if [ -z "$remote_commit" ]; then
echo -e "${idsCL[Red]}Could not find branch '${branch}' for ${label}${idsCL[Default]}"
if [[ ! -d "${repository}/.git" ]]; then
echo -e "${idsCL[Red]}${label} is not a Git repository.${idsCL[Default]}"
return 1
fi
if [ "$local_commit" = "$remote_commit" ]; then
echo -e "${idsCL[Green]}${label} is current (${branch})${idsCL[Default]}"
return 0
current_branch="$(git -C "$repository" branch --show-current 2>/dev/null)"
if [[ -z "$current_branch" ]]; then
echo -e "${idsCL[Red]}${label} is in a detached HEAD state; update skipped.${idsCL[Default]}"
return 1
fi
if [[ "$current_branch" != "$branch" ]]; then
echo -e "${idsCL[Red]}${label} is on '${current_branch}', not '${branch}'; update skipped.${idsCL[Default]}"
return 1
fi
if TAPM_GIT_WORKTREE_DIRTY "$repository"; then
echo -e "${idsCL[LightYellow]}${label} has local changes; update skipped to preserve them.${idsCL[Default]}"
git -C "$repository" status --short
return 1
fi
echo -en "${idsCL[LightCyan]}Updating ${label} (${branch})...${idsCL[Default]}"
if git fetch origin "$branch" >/dev/null 2>&1 &&
git reset --hard "origin/${branch}" >/dev/null 2>&1; then
echo -e " ${idsCL[Green]}Done${idsCL[Default]}"
return 0
if ! TAPM_GIT_FETCH_BRANCH "$repository" "$branch" 30 >/dev/null 2>&1; then
echo -e "${idsCL[Red]}Could not fetch branch '${branch}' for ${label}.${idsCL[Default]}"
return 1
fi
echo -e " ${idsCL[Red]}Failed${idsCL[Default]}"
return 1
state="$(TAPM_GIT_BRANCH_STATE "$repository" "$branch")"
case "$state" in
current)
echo -e "${idsCL[Green]}${label} is current (${branch}).${idsCL[Default]}"
return 0
;;
behind)
echo -en "${idsCL[LightCyan]}Updating ${label} (${branch})...${idsCL[Default]}"
if TAPM_GIT_FAST_FORWARD "$repository" "$branch" >/dev/null 2>&1; then
echo -e " ${idsCL[Green]}Done${idsCL[Default]}"
return 0
fi
echo -e " ${idsCL[Red]}Failed; local files were preserved.${idsCL[Default]}"
return 1
;;
ahead)
echo -e "${idsCL[LightYellow]}${label} is ahead of origin; its local commits were preserved.${idsCL[Default]}"
return 1
;;
diverged)
echo -e "${idsCL[LightYellow]}${label} has diverged from origin; automatic update was refused.${idsCL[Default]}"
return 1
;;
*)
echo -e "${idsCL[Red]}Could not determine the update state for ${label}.${idsCL[Default]}"
return 1
;;
esac
}
INSTALL_UPDATES() {
local current_branch
local defaults_warning=0
local update_failed=0
echo -e "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}"
@@ -112,7 +169,7 @@ INSTALL_UPDATES() {
fi
UPDATE_REPOSITORY /opt/idssys/defaults master "iDSSYS Defaults" ||
update_failed=1
defaults_warning=1
current_branch="$(git -C /opt/idssys/ta-proxmenu branch --show-current)"
if [ -z "$current_branch" ]; then
@@ -128,6 +185,9 @@ INSTALL_UPDATES() {
if (( update_failed == 0 )); then
source /opt/idssys/ta-proxmenu/defaults.inc
echo -e "\n${idsCL[Green]}Update check complete. Installed version: ${VERS}${idsCL[Default]}"
if (( defaults_warning == 1 )); then
echo -e "${idsCL[LightYellow]}TA-ProxMenu was processed, but iDSSYS Defaults requires attention.${idsCL[Default]}"
fi
return 0
fi