2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: AGPL-3.0-or-later
5 # usage: set DEBUG env var to anything to output to stdout
7 # Note: running this inside a cronjob, it wont mail any output if we end
8 # up rebooting from this script.
10 if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi
12 source /usr
/local
/lib
/err
15 m
() { printf "$pre %s\n" "$*"; "$@"; }
16 e
() { printf "$pre %s\n" "$*"; }
17 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
19 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
22 source /a
/bin
/bash_unpublished
/source-state
28 # 2>/dev/null hopefully gets rid of errors like: wall: /dev/pts/0: No such file or directory
29 sed 's/^/myupgrade /' | pee logger
"wall -n" 2>/dev
/null
34 echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall
-n 2>/dev
/null
38 if ! fuser
/var
/lib
/dpkg
/lock
&> /dev
/null
; then
39 echo "pid $$. unattended upgrade, rebooting now" | d
40 /a
/bin
/ds
/keyscript-on
44 echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall
-n 2>/dev
/null
47 echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | d
53 /a
/bin
/buildscripts
/prometheus
58 # TODO: executed from cron, this doesnt sent an email when we reboot,
59 # because rebooting from the script stops the ability to send email.
60 # We should figure some workaround.
62 if ! out
=$
(/sbin
/needrestart
-p 2>&1); then
63 if [[ $HOSTNAME == "$MAIL_HOST" ]]; then