Files
gaming-image-files/usr/local/bin/live-update.sh

100 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Stop the screen reader if this closes for any reason
trap 'sudo -n /usr/bin/systemctl stop fenrirscreenreader.service' SIGINT SIGTERM SIGHUP EXIT
# Start Fenrir for interaction with the terminal
sudo -n /usr/bin/systemctl start fenrirscreenreader.service
# Clear the screen before loading
clear
# Setup logging
logDir="/home/stormux/Logs"
logFile="${logDir}/system-updates.log"
mkdir -p "${logDir}"
echo "=== System Update Started: $(date) ===" | tee "${logFile}"
# Track errors
errorCount=0
errorMessages=()
# Clean up old packages keeping currently installed versions only
pacman -Sc --noconfirm --quiet 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Package cleaning failed")
fi
# Upgrade the system
pacman -Syu --noconfirm --quiet 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Package update failed")
fi
gitUrl="https://git.stormux.org/storm/gaming-image-files"
gitPath="${gitUrl##*/}"
pushd /tmp || exit
git config --global credential.helper store
git clone --quiet "${gitUrl}" 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Git clone failed")
fi
pushd "${gitPath}" || exit
git checkout --quiet master 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Git checkout master failed")
fi
git lfs pull 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Git LFS pull failed")
fi
# Files and directories to ignore when copying
ignoreFiles=(".git" "./image" ".git*" "/home/stormux/.w3m" "/home/stormux/.irssi")
# Build find command with ignore patterns
findArgs=()
for ignore in "${ignoreFiles[@]}"; do
if [[ "$ignore" == .* && "$ignore" != ./* ]]; then
findArgs+=(-name "$ignore" -prune -o)
else
findArgs+=(-path "$ignore" -prune -o)
fi
done
# Copy all files as root (preserves permissions properly)
find . "${findArgs[@]}" -type f -exec bash -c 'for i ; do cp -a --preserve=all --parents "${i}" /;done' _ "{}" \; 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("File copy failed")
fi
# Fix ownership of home directory files (exclude immutable .baremetal)
find /home/stormux -path /home/stormux/.baremetal -prune -o -exec chown -h stormux:users '{}' \; 2>&1 | tee -a "${logFile}"
if [[ ${PIPESTATUS[0]} -ne 0 ]]; then
((errorCount++))
errorMessages+=("Ownership fix failed")
fi
popd || exit
rm -rf "${gitPath}"
popd || exit
echo "=== System Update Completed: $(date) ===" | tee -a "${logFile}"
echo | tee -a "${logFile}"
# Display summary
if [[ $errorCount -eq 0 ]]; then
echo "SUCCESS: All update operations completed successfully." | tee -a "${logFile}"
else
echo "ERRORS DETECTED: $errorCount error(s) occurred during update:" | tee -a "${logFile}"
for error in "${errorMessages[@]}"; do
echo " - $error" | tee -a "${logFile}"
done
fi
echo | tee -a "${logFile}"
read -r -p "Press enter to continue."
exit 0