Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 49 lines (46 sloc) 1.59 KB
#! /bin/bash
set -e
if [ -e /.pdist_status ]; then
now=$(date +%s)
if [ $now -lt $(date +%s -d 2023-06-01) ]; then
echo $(date -d $now): implausible system time
exit 1
fi
echo "system time: $(date -d @$now)"
pdist_time=$(stat -c%Y /.pdist_status)
echo "pdist time: $(date -d @$pdist_time)"
pdist_age=$(( ($now - $pdist_time) /60 /60 /24 ))
echo "pdist age: $pdist_age days"
if [ $pdist_age -ge 7 ]; then
need_pdist_and_reboot=1
elif [ $pdist_age -ge 1 ]; then
need_async_pdist=1
else
echo no update required
fi
else
echo "no recorded update time"
need_pdist_and_reboot=1
fi
if [ "$need_async_pdist" ]; then
systemd-run --unit pdist-async-update --service-type=simple --remain-after-exit \
netcat $(distmaster) 237
echo triggered background update
elif [ "$need_pdist_and_reboot" ]; then
if [[ -e /var/run/updatecheck.reboot-triggered ]]; then
echo "Update and reboot required but prevented due to previous attempt"
rm /var/run/updatecheck.reboot-triggered
exit 1
fi
if (( $(stat -f -c %f /) * $(stat -f -c %s /) /1024/1024/1024 < 10)); then
echo "Update and reboot required but prevented because of insufficient free disk space (<10G)"
exit 1
fi
echo "Update and reboot required"
touch /var/run/updatecheck.reboot-triggered
sync /
while true; do sleep 5; echo "System update in progress. Please be patient..."; done &
netcat $(distmaster) 237
mxgrub default
systemctl start reboot.target --job-mode=replace-irreversibly
fi