update
This commit is contained in:
@@ -1,6 +1,69 @@
|
||||
#!/usr/bin/env bash
|
||||
# TA-ProxMenu preloader
|
||||
|
||||
DEFAULTS_REPOSITORY='/opt/idssys/defaults'
|
||||
DEFAULTS_CACHE_DIR='/var/cache/ta-proxmenu'
|
||||
DEFAULTS_CHECK_FILE="${DEFAULTS_CACHE_DIR}/defaults-last-check"
|
||||
DEFAULTS_CHECK_SECONDS=14400
|
||||
|
||||
AUTO_UPDATE_DEFAULTS() {
|
||||
local checked_at=0
|
||||
local local_commit
|
||||
local now
|
||||
local remote_commit
|
||||
|
||||
mkdir -p "$DEFAULTS_CACHE_DIR" 2>/dev/null || true
|
||||
now="$(date +%s)"
|
||||
[[ -r "$DEFAULTS_CHECK_FILE" ]] && read -r checked_at <"$DEFAULTS_CHECK_FILE"
|
||||
|
||||
if [[ "$checked_at" =~ ^[0-9]+$ ]] &&
|
||||
(( now - checked_at < DEFAULTS_CHECK_SECONDS )); then
|
||||
return
|
||||
fi
|
||||
|
||||
exec 9>"${DEFAULTS_CACHE_DIR}/defaults-update.lock" || return
|
||||
flock -n 9 || return
|
||||
|
||||
# Another process may have completed the update while this one waited.
|
||||
checked_at=0
|
||||
[[ -r "$DEFAULTS_CHECK_FILE" ]] && read -r checked_at <"$DEFAULTS_CHECK_FILE"
|
||||
if [[ "$checked_at" =~ ^[0-9]+$ ]] &&
|
||||
(( now - checked_at < DEFAULTS_CHECK_SECONDS )); then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ ! -d "${DEFAULTS_REPOSITORY}/.git" ]]; then
|
||||
echo "iDSSYS Defaults is missing; restoring it from origin..."
|
||||
mkdir -p /opt/idssys
|
||||
if ! timeout 60 git clone \
|
||||
https://git.scity.us/voltron/iDS-Defaults.git "$DEFAULTS_REPOSITORY"; then
|
||||
echo "WARNING: Unable to restore iDSSYS Defaults." >&2
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! timeout 20 git -C "$DEFAULTS_REPOSITORY" fetch origin master \
|
||||
>/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
|
||||
echo "WARNING: Unable to update iDSSYS Defaults; using the installed copy." >&2
|
||||
return
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
date +%s >"$DEFAULTS_CHECK_FILE"
|
||||
}
|
||||
|
||||
AUTO_UPDATE_DEFAULTS
|
||||
|
||||
[ "${2:-}" != "q" ] && source /opt/idssys/defaults/colors.inc
|
||||
source /opt/idssys/defaults/default.inc
|
||||
source /opt/idssys/ta-proxmenu/defaults.inc
|
||||
|
||||
Reference in New Issue
Block a user