commit 58df3042b16a14e42beb2a2bcaea6769ee0983ed Author: Alexandre CATTEAU Date: Sat Jun 24 19:57:57 2023 +0200 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..4dca0ab --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# APT autoremove + +The purpose is to run `apt-get autoremove` regularly on systems. Main use-case is to remove old kernels on Ubuntu-based +systems, to free space in `/boot`. + +### Files +* `systemd-templates/` contains Systemd units templates for running the the command unattended. +#### Installation +* `install.sh` script copies Systemd templates to their destination, and enables timer. + +### TODO +* RAS diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..5eb7714 --- /dev/null +++ b/install.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +run_directory=$(dirname "$0") +user=$(whoami) + +if [ -f $run_directory/.disabled ]; then + echo "Installation is disabled. Exiting..." + exit 0 +fi + +if [[ $user != 'root' ]]; then + sudo="sudo" +else + sudo="" +fi + +echo "Copying Systemd units to system directory..." +$sudo cp systemd-templates/apt-autoremove.service systemd-templates/apt-autoremove.timer /etc/systemd/system/ + +echo "Reloading Systemd..." +$sudo systemctl daemon-reload + +echo "Enabling timer (not starting it, either do it manually or reboot)..." +$sudo systemctl enable apt-autoremove.timer + +echo "Finished install. Exiting..." +exit 0 diff --git a/systemd-templates/apt-autoremove.service b/systemd-templates/apt-autoremove.service new file mode 100644 index 0000000..bacac4c --- /dev/null +++ b/systemd-templates/apt-autoremove.service @@ -0,0 +1,6 @@ +[Unit] +Description=Run apt autoremove + +[Service] +Type=oneshot +ExecStart=/usr/bin/apt-get autoremove -y diff --git a/systemd-templates/apt-autoremove.timer b/systemd-templates/apt-autoremove.timer new file mode 100644 index 0000000..daf8213 --- /dev/null +++ b/systemd-templates/apt-autoremove.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Run apt-autoremove after boot (for desktops) + +[Timer] +Unit=apt-autoremove.service +OnBootSec=2min + +[Install] +WantedBy=timers.target