update
This commit is contained in:
@@ -1,79 +1,87 @@
|
||||
#!/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/defaults.inc
|
||||
|
||||
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
|
||||
UPDATE_REPOSITORY() {
|
||||
local repository="$1"
|
||||
local branch="$2"
|
||||
local label="$3"
|
||||
local local_commit
|
||||
local remote_commit
|
||||
|
||||
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 rev-parse HEAD)" != "$(git ls-remote origin 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 "$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)"
|
||||
|
||||
cd /opt/idssys/ta-proxmenu
|
||||
current_branch="$(git branch --show-current)"
|
||||
remote_commit=""
|
||||
if [ -n "$current_branch" ]; then
|
||||
remote_commit="$(git ls-remote origin "refs/heads/${current_branch}" | cut -f1)"
|
||||
if [ -z "$remote_commit" ]; then
|
||||
echo -e "${idsCL[Red]}Could not find branch '${branch}' for ${label}${idsCL[Default]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$local_commit" = "$remote_commit" ]; then
|
||||
echo -e "${idsCL[Green]}${label} is current (${branch})${idsCL[Default]}"
|
||||
return 0
|
||||
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
|
||||
fi
|
||||
|
||||
echo -e " ${idsCL[Red]}Failed${idsCL[Default]}"
|
||||
return 1
|
||||
}
|
||||
|
||||
INSTALL_UPDATES() {
|
||||
local current_branch
|
||||
local update_failed=0
|
||||
|
||||
echo -e "${idsCL[LightCyan]}Checking for updates...${idsCL[Default]}"
|
||||
if ! curl --fail --silent --show-error --head \
|
||||
--connect-timeout 3 --max-time 10 https://git.scity.us >/dev/null; then
|
||||
echo -e "${idsCL[Red]}Could not connect to git.scity.us${idsCL[Default]}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
UPDATE_REPOSITORY /opt/idssys/defaults master "iDSSYS Defaults" ||
|
||||
update_failed=1
|
||||
|
||||
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; automatic updates were skipped${idsCL[Default]}"
|
||||
elif [ -z "$remote_commit" ]; then
|
||||
echo -e "${idsCL[Red]}Could not find branch '${current_branch}' on the TA-Proxmenu origin; automatic updates were skipped${idsCL[Default]}"
|
||||
elif [ "$(git rev-parse HEAD)" != "$remote_commit" ]; then
|
||||
if [ "${1}" != "tapm" ]; then
|
||||
[ ${udtd} -eq 0 ] && echo -en "\e[1A";
|
||||
echo -en "\e[0K\r${idsCL[LightCyan]}Updating TA-Proxmenu (${current_branch})...${idsCL[Default]}"
|
||||
fi
|
||||
git fetch origin "$current_branch" >/dev/null 2>&1
|
||||
git reset --hard "origin/${current_branch}" >/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
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
else
|
||||
echo -e "${idsCL[Red]}Could not connect to 'git.scity.us' for updates${idsCL[Default]}"
|
||||
fi
|
||||
fi
|
||||
rm -f /var/cache/ta-proxmenu/update-status 2>/dev/null || true
|
||||
|
||||
if [ "${1}" != "tapm" ] && [ "${1}" != "update" ] && [ "${1}" != "u" ]; then
|
||||
/opt/idssys/ta-proxmenu/proxmenu-scripts.sh "${1:-}" "${2:-}" "${3:-}" "${4:-}"
|
||||
fi
|
||||
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]}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
exit 0
|
||||
return 1
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
update|u)
|
||||
INSTALL_UPDATES
|
||||
exit $?
|
||||
;;
|
||||
tapm)
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
/opt/idssys/ta-proxmenu/proxmenu-scripts.sh \
|
||||
"${1:-}" "${2:-}" "${3:-}" "${4:-}"
|
||||
|
||||
exit $?
|
||||
|
||||
Reference in New Issue
Block a user