update to V2

This commit is contained in:
David Schroeder
2026-08-12 21:50:50 -05:00
parent 873bb17b62
commit 72d61e5785
41 changed files with 9421 additions and 477 deletions
+159 -114
View File
@@ -1,151 +1,196 @@
#!/usr/bin/env bash
# TA-Proxmenu preloader
# TA-ProxMenu preloader
[ "${2}" != "q" ] && source /opt/idssys/defaults/colors.inc
source /opt/idssys/defaults/default.inc
source /opt/idssys/ta-proxmenu/inc/runtime-config.inc
TAPM_ENSURE_RUNTIME_CONFIG || exit 1
source /opt/idssys/ta-proxmenu/inc/git-update.inc
source /opt/idssys/ta-proxmenu/inc/cluster-update.inc
[ "${2:-}" != "q" ] && source /opt/idssys/ta-proxmenu/colors.inc
source /opt/idssys/ta-proxmenu/defaults.inc
TAPM_FLEET_START "$VERS"
trap 'TAPM_FLEET_FINISH "$?"' EXIT
SWITCH_TO_V2() {
UPDATE_REPOSITORY() {
local repository="$1"
local branch="$2"
local label="$3"
local current_branch
local state
if [[ ! -d "${repository}/.git" ]]; then
echo -e "${idsCL[Red]}${label} is not a Git repository.${idsCL[Default]}"
return 1
fi
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
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
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
}
SWITCH_TAPM_BRANCH() {
local target_branch="$1"
local repository='/opt/idssys/ta-proxmenu'
local current_branch
local head_commit
local local_commit
local main_commit
local remote_commit
local target_state=''
if ! git check-ref-format --branch "$target_branch" >/dev/null 2>&1; then
echo -e "${idsCL[Red]}'${target_branch}' is not a valid Git branch name.${idsCL[Default]}"
return 1
fi
if [[ ! -d "${repository}/.git" ]]; then
echo -e "${idsCL[Red]}TA-ProxMenu is not a Git repository.${idsCL[Default]}"
return 1
fi
current_branch="$(git -C "$repository" branch --show-current 2>/dev/null)"
if [[ "$current_branch" == "V2" ]]; then
exec /opt/idssys/ta-proxmenu/run.sh
if [[ -z "$current_branch" ]]; then
echo -e "${idsCL[Red]}TA-ProxMenu is in a detached HEAD state; branch switching was refused.${idsCL[Default]}"
return 1
fi
if [[ -n "$(git -C "$repository" status --porcelain --untracked-files=normal)" ]]; then
if [[ "$target_branch" == "$current_branch" ]]; then
echo -e "${idsCL[Green]}TA-ProxMenu is already using '${target_branch}'.${idsCL[Default]}"
return 0
fi
if TAPM_GIT_WORKTREE_DIRTY "$repository"; then
echo -e "${idsCL[LightYellow]}TA-ProxMenu has local changes; branch switching was refused to preserve them.${idsCL[Default]}"
git -C "$repository" status --short
return 1
fi
echo -e "${idsCL[LightCyan]}Fetching TA-ProxMenu branch 'V2'...${idsCL[Default]}"
if ! timeout 30 git -C "$repository" fetch --prune origin \
'+refs/heads/main:refs/remotes/origin/main' \
'+refs/heads/V2:refs/remotes/origin/V2' >/dev/null 2>&1; then
echo -e "${idsCL[Red]}Could not fetch branch 'V2' from origin.${idsCL[Default]}"
echo -e "${idsCL[LightCyan]}Fetching TA-ProxMenu branch '${target_branch}'...${idsCL[Default]}"
if ! TAPM_GIT_FETCH_BRANCH "$repository" "$target_branch" 30 >/dev/null 2>&1; then
echo -e "${idsCL[Red]}Could not fetch branch '${target_branch}' from origin.${idsCL[Default]}"
return 1
fi
if [[ -z "$current_branch" ]]; then
head_commit="$(git -C "$repository" rev-parse --verify 'HEAD^{commit}' 2>/dev/null)"
main_commit="$(git -C "$repository" rev-parse --verify \
'refs/remotes/origin/main^{commit}' 2>/dev/null)"
if [[ -z "$head_commit" || "$head_commit" != "$main_commit" ]]; then
echo -e "${idsCL[Red]}TA-ProxMenu has an unrecognized detached HEAD; branch switching was refused.${idsCL[Default]}"
if git -C "$repository" show-ref --verify --quiet "refs/heads/${target_branch}"; then
target_state="$(
TAPM_GIT_RELATION "$repository" "refs/heads/${target_branch}" \
"refs/remotes/origin/${target_branch}"
)" || {
echo -e "${idsCL[Red]}Could not compare local and remote '${target_branch}'.${idsCL[Default]}"
return 1
fi
echo -e "${idsCL[LightCyan]}Recovered the legacy updater's detached main checkout.${idsCL[Default]}"
fi
}
case "$target_state" in
ahead)
echo -e "${idsCL[LightYellow]}Local branch '${target_branch}' has commits not on origin; switching was refused.${idsCL[Default]}"
return 1
;;
diverged)
echo -e "${idsCL[LightYellow]}Local branch '${target_branch}' has diverged from origin; switching was refused.${idsCL[Default]}"
return 1
;;
esac
remote_commit="$(git -C "$repository" rev-parse --verify \
'refs/remotes/origin/V2^{commit}' 2>/dev/null)" || {
echo -e "${idsCL[Red]}Origin does not provide a usable V2 branch.${idsCL[Default]}"
return 1
}
if git -C "$repository" show-ref --verify --quiet refs/heads/V2; then
local_commit="$(git -C "$repository" rev-parse --verify \
'refs/heads/V2^{commit}' 2>/dev/null)" || return 1
if [[ "$local_commit" != "$remote_commit" ]] &&
! git -C "$repository" merge-base --is-ancestor \
"$local_commit" "$remote_commit"; then
echo -e "${idsCL[LightYellow]}Local branch 'V2' has local-only or diverged commits; switching was refused.${idsCL[Default]}"
return 1
fi
git -C "$repository" switch V2 >/dev/null || return 1
if [[ "$local_commit" != "$remote_commit" ]] &&
! git -C "$repository" merge --ff-only \
refs/remotes/origin/V2 >/dev/null; then
echo -e "${idsCL[Red]}Could not fast-forward V2; no commits were discarded.${idsCL[Default]}"
return 1
fi
git -C "$repository" switch "$target_branch" >/dev/null || return 1
else
git -C "$repository" switch --create V2 \
--track origin/V2 >/dev/null || return 1
git -C "$repository" switch --create "$target_branch" \
--track "origin/${target_branch}" >/dev/null || return 1
fi
if [[ "$target_state" == "behind" ]] &&
! TAPM_GIT_FAST_FORWARD "$repository" "$target_branch" >/dev/null; then
echo -e "${idsCL[Red]}Could not fast-forward '${target_branch}'; no commits were discarded.${idsCL[Default]}"
return 1
fi
rm -f /var/cache/ta-proxmenu/update-status 2>/dev/null || true
echo -e "${idsCL[Green]}TA-ProxMenu is now using branch 'V2'. Loading the V2 menu...${idsCL[Default]}"
echo -e "${idsCL[Green]}TA-ProxMenu is now using branch '${target_branch}'. Loading its menu...${idsCL[Default]}"
exec /opt/idssys/ta-proxmenu/run.sh
}
if [[ "${1:-}" == "V2" ]]; then
SWITCH_TO_V2
exit $?
fi
INSTALL_LOCAL_UPDATES() {
local current_branch
local update_failed=0
if [[ "${noupdate}" != *" ${1} "* ]] && [[ "${noupdate}" != *" ${2} "* ]]; then
if curl -m 3 -s --head --request GET https://git.scity.us | grep "HTTP/2 200" > /dev/null; then
if [ "${1}" != "tapm" ]; then
echo -en "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}"
echo ""
udtd=0
fi
echo -e "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}"
if [ "${1}" != "tapm" ]; then
if [ ! -d /opt/idssys/defaults ]; then
git clone https://git.scity.us/voltron/iDS-Defaults.git /opt/idssys/defaults
else
cd /opt/idssys/defaults
if [ "`git log --pretty=%H ...refs/heads/master^ | head -n 1`" != "`git ls-remote origin -h refs/heads/master |cut -f1`" ]; then
if [ "${1}" != "tapm" ]; then
echo -en "\e[1A";
echo -en "\e[0K\r${idsCL[LightCyan]}Updating iDSSYS-Defaults...${idsCL[Default]}"
udtd=1
fi
git fetch origin master >/dev/null 2>&1
git reset --hard origin/master >/dev/null 2>&1
git reflog expire --expire=now --all >/dev/null 2>&1
git repack -ad >/dev/null 2>&1
git prune >/dev/null 2>&1
git pull >/dev/null 2>&1
[ "${1}" != "tapm" ] && echo -e "${idsCL[Green]}Done${idsCL[Default]}"
fi
fi
fi
current_branch="$(git -C /opt/idssys/ta-proxmenu branch --show-current)"
if [ -z "$current_branch" ]; then
echo -e "${idsCL[Red]}TA-ProxMenu is in a detached HEAD state; update skipped${idsCL[Default]}"
update_failed=1
else
UPDATE_REPOSITORY /opt/idssys/ta-proxmenu "$current_branch" "TA-ProxMenu" ||
update_failed=1
fi
cd /opt/idssys/ta-proxmenu
if [ "`git log --pretty=%H ...refs/heads/main^ | head -n 1`" != "`git ls-remote origin -h refs/heads/main |cut -f1`" ]; then
if [ "${1}" != "tapm" ]; then
[ ${udtd} -eq 0 ] && echo -en "\e[1A";
echo -en "\e[0K\r${idsCL[LightCyan]}Updating TA-Proxmenu...${idsCL[Default]}"
fi
git fetch origin main >/dev/null 2>&1
git reset --hard origin/main >/dev/null 2>&1
git reflog expire --expire=now --all >/dev/null 2>&1
git repack -ad >/dev/null 2>&1
git prune >/dev/null 2>&1
git pull >/dev/null 2>&1
if [ "${1}" != "tapm" ]; then
source /opt/idssys/ta-proxmenu/defaults.inc
# echo -en "\e[1A";
# echo -e "\e[0K\r ${idsCL[Green]}Updated to v${VERS}${idsCL[Default]}"
echo -e " ${idsCL[Green]}Updated to v${VERS}${idsCL[Default]}\n"
fi
elif [ "${1}" != "tapm" ] && [ ${udtd} -eq 0 ]; then
echo -e "\e[1A\e[0K\r ${idsCL[Green]}No updates available${idsCL[Default]}\n"
fi
rm -f /var/cache/ta-proxmenu/update-status 2>/dev/null || true
else
echo -e "${idsCL[Red]}Could not connect to 'git.scity.us' for updates${idsCL[Default]}"
fi
fi
if (( update_failed == 0 )); then
source /opt/idssys/ta-proxmenu/defaults.inc
echo -e "${idsCL[Green]}Update check complete. Installed version: ${VERS}${idsCL[Default]}"
return 0
fi
if [ "${1}" != "tapm" ] && [ "${1}" != "update" ] && [ "${1}" != "u" ]; then
/opt/idssys/ta-proxmenu/proxmenu-scripts.sh $1 $2 $3 $4
fi
return 1
}
exit 0
case "${1:-}" in
update|u)
if [[ "${2:-}" == "--local-only" ]]; then
INSTALL_LOCAL_UPDATES
else
INSTALL_CLUSTER_UPDATES
fi
exit $?
;;
main)
SWITCH_TAPM_BRANCH "$1"
exit $?
;;
tapm)
exit 0
;;
esac
/opt/idssys/ta-proxmenu/proxmenu-scripts.sh \
"${1:-}" "${2:-}" "${3:-}" "${4:-}"
exit $?