Silent updates PPA included


As the built-in automatic update feature only applies to security updates, you may want to have automatic global updates including PPA. Yes, 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/

Set the command to the script with sudo (sudo /opt/ 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

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

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

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