c358fcb5c59a8894e79df07837d9cda8417a0ee8
2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 # Note: running this inside a cronjob, it wont mail any output if we end
6 # up rebooting from this script.
8 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
10 source /usr
/local
/lib
/err
13 m
() { printf "$pre %s\n" "$*"; "$@"; }
14 e
() { printf "$pre %s\n" "$*"; }
15 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
17 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
20 source /a
/bin
/bash_unpublished
/source-state
23 "$@" |
& systemd-cat
-t myupgrade
33 if checkrestart
-b /a
/bin
/ds
/checkrestart-blacklist
-p -t &>/dev
/null
; then
37 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
38 # no automatic reboot for this host, just make an alert
39 checkrestart
-b /a
/bin
/ds
/checkrestart-blacklist
-p 2>/dev
/null ||
:
42 l checkrestart
-b /a
/bin
/ds
/checkrestart-blacklist
-p 2>/dev
/null ||
:
46 echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall
-n
50 if ! fuser
/var
/lib
/dpkg
/lock
&> /dev
/null
; then
51 echo "pid $$. unattended upgrade, rebooting now" | pee
cat "wall -n"
52 /a
/bin
/ds
/keyscript-on
56 echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall
-n
59 echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | pee
cat "wall -n"