bazzite/system_files/deck/usr/bin/steamos-update

62 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/bash
2023-02-09 11:08:39 -08:00
if command -v ublue-update > /dev/null; then
if [ "$1" == "check" ]; then
if [ -f '/tmp/upgrade-installed' ]; then
exit 7 # Upgrade already installed
else
# Check system state
ublue-update --check
if [ $? -eq 0 ]; then
# Perform connectivity check
wget -q --spider https://github.com
if [ $? -eq 0 ]; then
# Compare installation digest to latest image
IMAGE=$(rpm-ostree status | grep -m1 ghcr | sed 's/^.*ghcr/ghcr/')
CURRENT=$(rpm-ostree status | grep -m1 Digest | tr -d '[:space:]' | sed 's/'Digest:'//g')
LATEST=$(skopeo inspect docker://${IMAGE} | jq '.Digest' | tr -d '"')
if [ ${CURRENT} == ${LATEST} ]; then
exit 7 # Up to date
else
exit 0 # Upgrade available
fi
else
exit 7 # Connectivity check failed
fi
else
exit 7 # System in use
fi
fi
elif [ "$1" == "--supports-duplicate-detection" ]; then
exit 0
else
# Fake upgrade progress bar
fake_progress() {
local value=0
while read -r line; do
if [ ${value} -lt '100' ]; then
echo ${value}'%'
value=$(( value + 3 ))
fi
done
echo 100%
}
upgrade() {
# Pull exit code from ublue-update
ublue-update --force
echo $? > /tmp/upgrade-check
}
upgrade | fake_progress
# Check if upgrade failed
UPGRADE_CHECK=/tmp/upgrade-check
rm /tmp/upgrade-check
if [ ${UPGRADE_CHECK} -eq 0 ]; then
touch /tmp/upgrade-installed
else
exit 0 # Upgrade failed
fi
fi
else
exit 7 # ublue-update not installed
fi