bunch of fixes, change sy host, deploy some new stuff
[distro-setup] / filesystem / usr / local / bin / myupgrade
index c358fcb5c59a8894e79df07837d9cda8417a0ee8..e5401dc836675ab54f9aafb31490ca5cf08ed7e7 100755 (executable)
@@ -19,41 +19,35 @@ err() { echo "[$(date +'%Y-%m-%d %H:%M:%S%z')]: $pre: $*" >&2; }
 hn=$(hostname -f)
 source /a/bin/bash_unpublished/source-state
 
-l() {
-  "$@" |& systemd-cat -t myupgrade
+myreboot() {
+  for x in {30..1}; do
+    echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall -n
+    sleep 10
+  done
+  for x in {30..1}; do
+    if ! fuser /var/lib/dpkg/lock &> /dev/null; then
+      echo "pid $$. unattended upgrade, rebooting now" | pee cat "wall -n"
+      /a/bin/ds/keyscript-on
+      /sbin/reboot
+      exit 0
+    fi
+    echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall -n
+    sleep 10
+  done
+  echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | pee cat "wall -n"
 }
 
-## temporary
-case $HOSTNAME in
-  kd)
-    exit 0
-    ;;
-esac
 
-if checkrestart -b /a/bin/ds/checkrestart-blacklist -p -t &>/dev/null; then
-  exit 0
+if [[ $HOSTNAME != "$MAIL_HOST" ]]; then
+  ksta=$(needrestart -b | sed -n 's/NEEDRESTART-KSTA: *//p');
+  case $ksta in
+    1) : ;;
+    [023]) myreboot ;;
+    *) err error: unknown kernel status ;;
+  esac
 fi
 
-if [[ $HOSTNAME == "$MAIL_HOST" ]]; then
-  # no automatic reboot for this host, just make an alert
-  checkrestart -b /a/bin/ds/checkrestart-blacklist -p 2>/dev/null ||:
-  exit 0
-else
-  l checkrestart -b /a/bin/ds/checkrestart-blacklist -p 2>/dev/null ||:
+# needsrestarts automatic restarts failed.
+if ! out=$(/sbin/needrestart -p 2>&1); then
+  e "$out"
 fi
-
-for x in {30..1}; do
-  echo "pid $$. unattended upgrade, rebooting in $((x*10)) seconds" | wall -n
-  sleep 10
-done
-for x in {30..1}; do
-  if ! fuser /var/lib/dpkg/lock &> /dev/null; then
-    echo "pid $$. unattended upgrade, rebooting now" | pee cat "wall -n"
-    /a/bin/ds/keyscript-on
-    /sbin/reboot
-    exit 0
-  fi
-  echo "pid $$. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall -n
-  sleep 10
-done
-echo "pid $$. dpkg locked for 5 minutes, automatic reboot failed" | pee cat "wall -n"