Add script to purge packages only removed
authorJulien Valroff <julien@kirya.net>
Sat, 2 May 2020 12:02:36 +0000 (14:02 +0200)
committerJulien Valroff <julien@kirya.net>
Sat, 2 May 2020 12:02:36 +0000 (14:02 +0200)
purge-removed-packages [new file with mode: 0755]

diff --git a/purge-removed-packages b/purge-removed-packages
new file mode 100755 (executable)
index 0000000..f38b451
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+#
+# Purge all packages marked as deinstall
+
+
+if [ $UID != 0 ]; then
+       echo "This script requires to be root"
+       exit 1;
+fi
+
+dpkg --get-selections | awk '$2 == "deinstall" {print $1}' | xargs apt-get purge -y
+
+if [ $? = 0 ]
+then
+  echo "Done."
+else
+  echo "Script exited with code $?."
+fi