minor fix and add automatic updates
authorIan Kelling <ian@iankelling.org>
Wed, 3 Jul 2019 15:57:56 +0000 (11:57 -0400)
committerIan Kelling <ian@iankelling.org>
Wed, 3 Jul 2019 15:57:56 +0000 (11:57 -0400)
distro-end
filesystem/usr/local/bin/zelous-unattended-reboot [new file with mode: 0755]

index b54285878e17a743de221ca36550294640aa5dda..91c7a832ebd0b5e5af1d9b2eae1bbe08d172b200 100755 (executable)
@@ -181,6 +181,18 @@ sgo certbotmail.timer
 
 pi ${p1[@]}
 
+##### begin automatic upgrades ####
+# this makes it so we upgrade everything
+debconf-set-selections <<'EOF'
+unattended-upgrades unattended-upgrades/origins_pattern string "codename=${distro_codename}";
+EOF
+dpkg-reconfigure -u -fnoninteractive unattended-upgrades
+
+# Setup daily reboots, so all unattended upgrades go into affect
+# unattended upgrades happen at 6 am + rand(60 min).
+echo '20 7 * * * root /usr/local/bin/zelous-unattended-reboot' >/etc/cron.d/unattended-upgrade-reboot
+##### end automatic upgrades ####
+
 
 ## prometheus node exporter setup
 web-conf -f 9100 -p 9101 apache2 $(hostname -f) <<'EOF'
@@ -1306,8 +1318,11 @@ EOF
 
   rpc_pass=$(</p/transmission-rpc-pass)
   for f in /home/*; do
-    d=$f/.config/transmission-remote-gtk
     u=${f##*/}
+    if [[ ! $(id -u $u) -ge 1000 ]]; then
+      continue
+    fi
+    d=$f/.config/transmission-remote-gtk
     s -u $u mkdir -p $d
     s -u $u dd of=$d/config.json <<EOF
 {
diff --git a/filesystem/usr/local/bin/zelous-unattended-reboot b/filesystem/usr/local/bin/zelous-unattended-reboot
new file mode 100755 (executable)
index 0000000..8b7b601
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+if [[ $(/usr/sbin/checkrestart | wc -l) != 1 ]]; then
+  for x in {30..1}; do
+    echo "pid $PID. unattended upgrade, rebooting in $((x*10)) seconds" | wall
+    sleep 10
+  done
+  for x in {30..1}; do
+    if ! fuser /var/lib/dpkg/lock &> /dev/null; then
+      /sbin/reboot
+      exit 0
+    fi
+    echo "pid $PID. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall
+    sleep 10
+  done
+  echo "dpkg locked for 5 minutes, automatic reboot failed" | pee cat wall
+fi