8b7b601bbea712fb7e624ff469b9eef0b27a634c
[distro-setup] / zelous-unattended-reboot
1 #!/bin/bash
2 if [[ $(/usr/sbin/checkrestart | wc -l) != 1 ]]; then
3 for x in {30..1}; do
4 echo "pid $PID. unattended upgrade, rebooting in $((x*10)) seconds" | wall
5 sleep 10
6 done
7 for x in {30..1}; do
8 if ! fuser /var/lib/dpkg/lock &> /dev/null; then
9 /sbin/reboot
10 exit 0
11 fi
12 echo "pid $PID. unattended upgrade reboot waiting 10 seconds for dpkg lock" | wall
13 sleep 10
14 done
15 echo "dpkg locked for 5 minutes, automatic reboot failed" | pee cat wall
16 fi