4

I wrote this script,

#!/bin/bash
# if not root, run as root
if (( $EUID != 0 )); then
    sudo /home/jb/bash/update.sh
    exit
fi
apt-get update
apt-get -y upgrade
apt-get -y dist-upgrade
apt-get clean
apt-get -y autoremove

the goal being to have a one-stop-shop for updating everything and removing any unnecessary packages.

Is the above sufficient? Is there anything redundant or unnecessary about it? Any dangers/cautions that need to be considered? Other (fill in the blank)?

Edit: If I only use the built in Ubuntu 12.04 Update Manager, do things get cleaned and autoremoved?

1
  • 3
    It might fail sometimes. From the man page "If an undesirable situation, such as changing a held package, trying to install a unauthenticated package or removing an essential package occurs then apt-get will abort."
    – asheeshr
    May 8, 2014 at 1:02

2 Answers 2

2

Basically, yes. However, as AsheeshR pointed out in his comment, it will abort if doing things deemed "undesirable". A way to make sure it works every time is to add the option --force-yes, but PLEASE READ THE MAN PAGE. It is VERY dangerous to implement this option, so you should probably stick with what you have now. In fact, the man page on apt-get says that this option "may break your system", so you would only use it manually if the above didn't work and only in very special (and rare) situations.

1

This is a script I use to perform upgrades on Debian (Testing) and Ubuntu:

#!/bin/bash
apt update
apt -y dist-upgrade
apt -y autoremove
apt clean
apt purge -y $(dpkg -l | awk '/^rc/ { print $2 }')

It basically includes additionally to your script:

apt purge -y $(dpkg -l | awk '/^rc/ { print $2 }')

which deletes package configuration files and helps to save space.

I do like your # if not root, run as root section and I think I'm going to steal it :-)

Over the past years I've never had incidents running this script daily. They have happened but are very rare and easily repairable.

I discovered this recently:

apt -y dist-upgrade --auto-remove --purge

which suggests some commands can be merged into a line, but I'm not sure.

Ubuntu Update Manager is more involved it seems.

Not the answer you're looking for? Browse other questions tagged or ask your own question.