Silent updates PPA included

Hello,
As the built-in automatic update feature only applies to security updates, you may want to have automatic global updates including PPA.

We can use the unattended-upgrades, but according to my experience, the function is unreliable and packages needs to be repaired sometimes. That's why I use the following script that starts with each login. Its purpose is to do all updates, silently, including PPAs, with package repair and cleanup, at every login.

Put the script in /opt/ make it executable and with the help of sudoers, we can start the script with sudo without typing password:

sudo visudo -f /etc/sudoers.d/custom
UserName ALL=NOPASSWD: /opt/updates.sh

Set the command to the script with sudo (sudo /opt/updates.sh) in the Startup Applications Preferences. The script need yad: sudo apt install yad because it will show an icon in the panel while updates. It will run only if battery>80% or on AC. Tested and works fine on 18.04 and 16.04

#!/bin/bash
sleep 9m
# AC or battery
level=$(cat /sys/class/power_supply/BAT0/capacity)
# Get battery level
status=$(cat /sys/class/power_supply/BAT0/status)
flag="true"
if [ "${status}" != "Discharging" ]; then
 echo "AC: OK"
 flag="true"
else
 if [ "${level}" -ge 80 ]; then
  flag="true"
  echo "battery > 80%: OK"
 else
  flag="false"
  echo "low battery: cancel"
 fi
fi

if [ "$flag" == "false" ]; then
 echo "cancel"
 exit 0
fi

MSG="Updates in progress..."
doupdate () { (sudo apt update ; sudo apt full-upgrade -y ; sudo apt-get install -fy ; sudo apt-get autoclean ; sudo apt-get autoremove --purge -y) > /dev/null; quit ; }
doupdate | yad --notification --no-middle --text="$MSG" --image="system-software-update" --command="yad --center --title=Information --image=dialog-information --text=\"$MSG\" --text-align=left --fixed --button=OK" --listen
sudo dpkg --configure -a
exit 0
2 Likes