137 lines
3.7 KiB
Bash
Executable File
137 lines
3.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
repoUrl="${STORMUX_UPDATE_REPO:-https://git.stormux.org/storm/gaming-image-files}"
|
|
repoBranch="${STORMUX_UPDATE_BRANCH:-testing}"
|
|
homeDir="${STORMUX_UPDATE_HOME:-/home/stormux}"
|
|
logDir="${homeDir}/Logs"
|
|
logFile="${logDir}/system-updates.log"
|
|
menuCommand="${STORMUX_MENU_COMMAND:-${homeDir}/.local/bin/game_launcher.py}"
|
|
workRoot=""
|
|
beepPid=""
|
|
runtimeScript="${0}"
|
|
|
|
if [[ "${STORMUX_UPDATE_SELF_COPY:-0}" != "1" ]]; then
|
|
runtimeScript="$(mktemp /tmp/stormux-system-update.XXXXXX)"
|
|
cp -f -- "$0" "${runtimeScript}"
|
|
chmod 755 "${runtimeScript}"
|
|
export STORMUX_UPDATE_SELF_COPY=1
|
|
exec "${runtimeScript}" "$@"
|
|
fi
|
|
|
|
speak() {
|
|
local message="$1"
|
|
local waitForSpeech="${2:-0}"
|
|
|
|
printf '%s\n' "${message}"
|
|
if [[ "$waitForSpeech" == "1" ]]; then
|
|
spd-say -Cw "${message}" 2> /dev/null || true
|
|
else
|
|
spd-say "${message}" 2> /dev/null || true
|
|
fi
|
|
}
|
|
|
|
progress_beep() {
|
|
[[ "${STORMUX_UPDATE_BEEPS:-1}" == "1" ]] || return 0
|
|
command -v play > /dev/null 2>&1 || return 0
|
|
|
|
while true; do
|
|
play -q -n synth 0.06 sine 520 vol 0.35 > /dev/null 2>&1 || true
|
|
sleep 2
|
|
done
|
|
}
|
|
|
|
start_progress() {
|
|
local message="$1"
|
|
|
|
speak "${message}"
|
|
progress_beep &
|
|
beepPid="$!"
|
|
}
|
|
|
|
stop_progress() {
|
|
if [[ -n "${beepPid}" ]] && kill -0 "${beepPid}" 2> /dev/null; then
|
|
kill "${beepPid}" 2> /dev/null || true
|
|
wait "${beepPid}" 2> /dev/null || true
|
|
fi
|
|
beepPid=""
|
|
}
|
|
|
|
cleanup() {
|
|
local exitCode="${1:-$?}"
|
|
|
|
stop_progress
|
|
if [[ -n "${workRoot}" && -d "${workRoot}" ]]; then
|
|
rm -rf "${workRoot}"
|
|
fi
|
|
if [[ "${STORMUX_UPDATE_SELF_COPY:-0}" == "1" && "${runtimeScript}" == /tmp/stormux-system-update.* ]]; then
|
|
rm -f "${runtimeScript}"
|
|
fi
|
|
if [[ "${exitCode}" -ne 0 ]]; then
|
|
speak "System update failed. Check ${logFile} for details." 1
|
|
read -r -p "Press enter to return to the menu."
|
|
exec "${menuCommand}"
|
|
fi
|
|
}
|
|
|
|
abort_update() {
|
|
trap - EXIT INT TERM HUP
|
|
cleanup 130
|
|
exit 130
|
|
}
|
|
|
|
run_logged() {
|
|
"$@" 2>&1 | tee -a "${logFile}"
|
|
return "${PIPESTATUS[0]}"
|
|
}
|
|
|
|
main() {
|
|
local sourceHome
|
|
|
|
mkdir -p "${logDir}"
|
|
printf 'System update started [%s]\n' "$(date)" | tee "${logFile}"
|
|
|
|
workRoot="$(mktemp -d)"
|
|
|
|
start_progress "Downloading updates."
|
|
run_logged git clone --depth 1 --filter=blob:none --sparse --branch "${repoBranch}" "${repoUrl}" "${workRoot}"
|
|
run_logged git -C "${workRoot}" sparse-checkout set home
|
|
if command -v git-lfs > /dev/null 2>&1; then
|
|
run_logged git -C "${workRoot}" lfs pull --include='home/**'
|
|
elif git -C "${workRoot}" lfs version > /dev/null 2>&1; then
|
|
run_logged git -C "${workRoot}" lfs pull --include='home/**'
|
|
fi
|
|
stop_progress
|
|
|
|
sourceHome="${workRoot}/home/stormux"
|
|
if [[ ! -d "${sourceHome}" ]]; then
|
|
printf 'Missing update home directory: %s\n' "${sourceHome}" | tee -a "${logFile}"
|
|
return 1
|
|
fi
|
|
|
|
start_progress "Applying updates."
|
|
run_logged rsync -a \
|
|
--exclude='.baremetal' \
|
|
--exclude='.cache/' \
|
|
--exclude='.config/stormux/game_launcher.conf' \
|
|
--exclude='.irssi/' \
|
|
--exclude='.local/.services/' \
|
|
--exclude='.local/etc/NetworkManager/' \
|
|
--exclude='.local/games/' \
|
|
--exclude='.local/var/' \
|
|
--exclude='.w3m/' \
|
|
--exclude='Downloads/' \
|
|
--exclude='Logs/' \
|
|
"${sourceHome}/" "${homeDir}/"
|
|
stop_progress
|
|
|
|
printf 'System update completed [%s]\n' "$(date)" | tee -a "${logFile}"
|
|
speak "Finalizing updates." 1
|
|
exec "${menuCommand}"
|
|
}
|
|
|
|
trap 'cleanup "$?"' EXIT
|
|
trap abort_update INT TERM HUP
|
|
main "$@"
|