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 set -e; .
/usr
/local
/lib
/bash-bear
; set +e
14 m
() { printf "$pre %s\n" "$*"; "$@"; }
15 e
() { printf "$pre %s\n" "$*"; }
16 err
() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
18 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
21 source /a
/bin
/bash_unpublished
/source-state
27 # 2>/dev/null hopefully gets rid of errors like: wall: /dev/pts/0: No such file or directory
28 sed 's/^/myupgrade /' | pee logger
"wall -n" 2>/dev
/null
33 echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall
-n 2>/dev
/null
37 if ! fuser
/var
/lib
/dpkg
/lock
&> /dev
/null
; then
38 echo "pid $$. unattended upgrade, rebooting now" | d
39 /a
/bin
/ds
/keyscript-on
43 echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall
-n 2>/dev
/null
46 echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | d
52 /c
/roles
/prom
/files
/simple
/usr
/local
/bin
/fsf-install-prometheus
53 /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
-l 127.0.0.1
56 /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
-l 127.0.0.1
59 /c
/roles
/prom_export
/files
/simple
/usr
/local
/bin
/fsf-install-node-exporter
64 # TODO: executed from cron, this doesnt sent an email when we reboot,
65 # because rebooting from the script stops the ability to send email.
66 # We should figure some workaround.
68 # I originally had the idea that for MAIL_HOST, I'd just send an email
69 # if something needs restarting. But atm, I have a bad habit of ignoring
72 if ! needrestart
-p -k &>/dev
/null
; then
76 needrestart
-b -l -r a |
& logger
-t myupgrade
79 # Restart based on library doesnt always work. If we still
80 # detect outdated libraries after trying to automatically restart,
81 # then do a reboot unless we are on systems we care a bit more about
82 # uptime, then send us an email.
84 # Note: I've noticed restart based on library has tended to screw up
85 # desktop related daemons because they have bugs when restarted in
86 # isolation instead of as part of bring up and down the whole desktop.
87 # But, I'd rather something gets messed up than things not get
89 if ! /sbin
/needrestart
-p -l &>/dev
/null
; then
90 if [[ $hn == "$MAIL_HOST" ||
$hn == kd
]]; then
91 # send us an email so we can decide what to do