142 lines
5.0 KiB
Bash
Executable File
142 lines
5.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# TA-Proxmenu preloader
|
|
|
|
[ "${2}" != "q" ] && source /opt/idssys/defaults/colors.inc
|
|
source /opt/idssys/defaults/default.inc
|
|
source /opt/idssys/ta-proxmenu/defaults.inc
|
|
|
|
SWITCH_TO_V2() {
|
|
local repository='/opt/idssys/ta-proxmenu'
|
|
local current_branch
|
|
local local_commit
|
|
local remote_commit
|
|
|
|
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 [[ -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 [[ "$current_branch" == "V2" ]]; then
|
|
echo -e "${idsCL[Green]}TA-ProxMenu is already using 'V2'.${idsCL[Default]}"
|
|
return 0
|
|
fi
|
|
if [[ -n "$(git -C "$repository" status --porcelain --untracked-files=normal)" ]]; 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/V2:refs/remotes/origin/V2' >/dev/null 2>&1; then
|
|
echo -e "${idsCL[Red]}Could not fetch branch 'V2' from origin.${idsCL[Default]}"
|
|
return 1
|
|
fi
|
|
|
|
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
|
|
else
|
|
git -C "$repository" switch --create V2 \
|
|
--track origin/V2 >/dev/null || 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'.${idsCL[Default]}"
|
|
}
|
|
|
|
if [[ "${1:-}" == "V2" ]]; then
|
|
SWITCH_TO_V2
|
|
exit $?
|
|
fi
|
|
|
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
else
|
|
echo -e "${idsCL[Red]}Could not connect to 'git.scity.us' for updates${idsCL[Default]}"
|
|
fi
|
|
fi
|
|
|
|
if [ "${1}" != "tapm" ] && [ "${1}" != "update" ] && [ "${1}" != "u" ]; then
|
|
/opt/idssys/ta-proxmenu/proxmenu-scripts.sh $1 $2 $3 $4
|
|
fi
|
|
|
|
exit 0
|