From c646bac921a043687ac8f87d0e49010b179547ee Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Wed, 18 Jun 2014 08:42:36 +0200 Subject: [PATCH] Upgrade system via apt This script upgrades the installed packages in an apt-based system. After a kernel upgrade, the old kernel is removed (in order to save space), and so are packages and package files that are no longer needed. Partial-Bug: 1312764 Implements: blueprint openstack-training-labs Change-Id: Iaadcebc424572787d3a2d77f6b19ab636d65ee58 --- labs/scripts/apt_upgrade.sh | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 labs/scripts/apt_upgrade.sh diff --git a/labs/scripts/apt_upgrade.sh b/labs/scripts/apt_upgrade.sh new file mode 100644 index 00000000..328bd51a --- /dev/null +++ b/labs/scripts/apt_upgrade.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +TOP_DIR=$(cd $(dirname "$0")/.. && pwd) +source "$TOP_DIR/config/paths" +source "$CONFIG_DIR/openstack" +source "$LIB_DIR/functions.guest" + +indicate_current_auto + +exec_logfile + +# XXX We assume that apt_init.sh set up repos and updated the apt index files + +# Upgrade installed packages and the kernel +sudo DEBIAN_FRONTEND=noninteractive apt-get -y upgrade +sudo apt-get -y dist-upgrade + +# XXX Not a great location for Vagrant specific code +if [[ $VM_SHELL_USER = vagrant ]]; then + if is_ubuntu; then + sudo apt-get -y install virtualbox-guest-dkms + fi +fi + +# If we upgraded the kernel, remove the old one +INSTALLED_KERNEL=$(readlink /vmlinuz) +INSTALLED_KERNEL=${INSTALLED_KERNEL#boot/vmlinuz-} +RUNNING_KERNEL=$(uname -r) + +if [[ $INSTALLED_KERNEL != $RUNNING_KERNEL ]]; then + echo "Kernel $INSTALLED_KERNEL installed. Removing $RUNNING_KERNEL." + sudo dpkg --purge "linux-image-$RUNNING_KERNEL" + sudo dpkg --purge "linux-headers-$RUNNING_KERNEL" +fi + +# Clean apt cache +sudo apt-get -y autoremove +sudo apt-get -y clean