#!/bin/bash # Copyright (C) 2019 Ian Kelling # SPDX-License-Identifier: AGPL-3.0-or-later if [ -z "$BASH_VERSION" ]; then echo "error: shell is not bash" >&2; exit 1; fi source /usr/local/lib/err pre="${0##*/}:" m() { printf "$pre %s\n" "$*"; "$@"; } e() { printf "$pre %s\n" "$*"; } err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; } if [[ $EUID == 0 ]]; then err "run as nonroot" exit 1 fi hn=$(hostname -f) source /a/bin/bash_unpublished/source-state l() { "$@" |& systemd-cat -t myupgrade } l /a/bin/buildscripts/rust has_x=false for pkg in xorg wayland; do if dpkg -s -- $x |& grep -Fx "Status: install ok installed" &> /dev/null; then has_x=true break fi done if $has_x; then l /a/bin/buildscripts/tor-browser l /a/bin/buildscripts/misc fi source /a/bin/distro-setup/path-add-function export GOPATH=$HOME/go path-add $GOPATH/bin path-add /usr/local/go/bin l /a/bin/buildscripts/go l go get -u mvdan.cc/fdroidcl cmd="sudo /usr/sbin/checkrestart -p" if [[ $($cmd | sed '/^Found 0 processes using old versions of upgraded files$/d' | wc -l) != 0 ]]; then $cmd -v | pee cat "wall -n" fi # no automatic reboot for these hosts if [[ $HOSTNAME == "$MAIL_HOST" || $hn == li.b8.nz ]]; then exit 0 fi if [[ -s /var/log/checkrestart.log ]]; then for x in {30..1}; do echo "pid $PID. unattended upgrade, rebooting in $((x*10)) seconds" | sudo wall -n sleep 10 done for x in {30..1}; do if ! fuser /var/lib/dpkg/lock &> /dev/null; then echo "pid $PID. unattended upgrade, rebooting now" | pee cat "sudo wall -n" sudo /sbin/reboot exit 0 fi echo "pid $PID. unattended upgrade reboot waiting 10 seconds for dpkg lock" | sudo wall -n sleep 10 done echo "pid $PID. dpkg locked for 5 minutes, automatic reboot failed" | pee cat "sudo wall -n" fi