Skip to content

Commit

Permalink
bw/bundles/apt: add script to install updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Jul 1, 2024
1 parent 38c1a9c commit fe08268
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
28 changes: 28 additions & 0 deletions bundlewrap/bundles/apt/files/do-unattended-upgrades
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -xeuo pipefail

apt-get update

DEBIAN_FRONTEND=noninteractive apt-get -y -q -o Dpkg::Options::=--force-confold dist-upgrade

DEBIAN_FRONTEND=noninteractive apt-get -y -q autoremove

DEBIAN_FRONTEND=noninteractive apt-get -y -q clean

existing=$(dpkg --get-selections | grep -E '^linux-(image|headers)-[0-9]' || true)

if [[ -z "$existing" ]]
then
echo "ERROR: No installed kernels found! Aborting!" >&2
exit 1
fi

current=$(uname -r | sed -r 's/-[a-zA-Z]+$//')
latest=$(echo "$existing" | sort --version-sort -t- -k 3,4 | tail -n 1 | sed -r 's/[^0-9]+([0-9]\.[^-]+-[0-9]+).*/\1/')
todelete=$(echo "$existing" | grep -v -E "($current|$latest)" | awk '{ print $1 }' || true)

if [[ -n "$todelete" ]]
then
DEBIAN_FRONTEND=noninteractive apt-get -qy purge $todelete
fi
3 changes: 3 additions & 0 deletions bundlewrap/bundles/apt/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
'/etc/netplan': {
'delete': True,
},
'/usr/local/sbin/do-unattended-upgrades': {
'mode': '0700',
},
'/var/lib/cloud': {
'delete': True,
},
Expand Down

0 comments on commit fe08268

Please sign in to comment.