summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorchrisjbillington2021-07-04 14:05:26 +1000
committerchrisjbillington2021-07-04 14:05:26 +1000
commit8a7f66104b6098499809e266c38005d62807eb93 (patch)
tree15afdad7ec3bb520edb01fca2ac5d7dd2dc9a970
parent329c1a498266aa4b9a08ed6c72377af160db578a (diff)
downloadaur-8a7f66104b6098499809e266c38005d62807eb93.tar.gz
Fix bug where explicitly installed package would be uninstalled
-rw-r--r--.SRCINFO4
-rw-r--r--PKGBUILD4
-rwxr-xr-xremove-orphaned-kernels9
3 files changed, 12 insertions, 5 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 7a4b4a5bdb8b..e931fe625050 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,6 +1,6 @@
pkgbase = remove-orphaned-kernels
pkgdesc = pacman -Rs orphaned kernel and driver packages, excluding currently-running.
- pkgver = 1.1
+ pkgver = 1.1.1
pkgrel = 1
url = https://aur.archlinux.org/packages/remove-orphaned-kernels/
arch = any
@@ -8,6 +8,6 @@ pkgbase = remove-orphaned-kernels
depends = python
depends = sudo
source = remove-orphaned-kernels
- sha256sums = a6939f973aa8013944354db38d4b42e0bcf69673fbabbc804af9842d27101649
+ sha256sums = d041487cf36a813ca2cf8abe023bdc6ec13921574580c3fbbbc4eb73f4c0f0fb
pkgname = remove-orphaned-kernels
diff --git a/PKGBUILD b/PKGBUILD
index bc1612efb78d..112499e6d50b 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,6 +1,6 @@
# Maintainer: Chris Billington <chrisjbillington@gmail.com>
pkgname=remove-orphaned-kernels
-pkgver=1.1
+pkgver=1.1.1
pkgrel=1
pkgdesc="pacman -Rs orphaned kernel and driver packages, excluding currently-running."
arch=('any')
@@ -8,7 +8,7 @@ url="https://aur.archlinux.org/packages/${pkgname}/"
license=('GPL')
depends=('python' 'sudo')
source=("${pkgname}")
-sha256sums=('53e18eb9ba1def9400210467380175ce019af3f7ca35fbd085b27e17fe5cbf8d')
+sha256sums=('d041487cf36a813ca2cf8abe023bdc6ec13921574580c3fbbbc4eb73f4c0f0fb')
package() {
install -m755 -d "${pkgdir}/usr/bin/"
diff --git a/remove-orphaned-kernels b/remove-orphaned-kernels
index 15e861ea78d3..b8757c07c06d 100755
--- a/remove-orphaned-kernels
+++ b/remove-orphaned-kernels
@@ -46,12 +46,19 @@ def is_directly_required(pkg):
return True
return False
+def is_explicitly_installed(pkg):
+ pkginfo = get_output('pacman', '-Qi', pkg)
+ reason = pkginfo.split('Install Reason')[1].split(':')[1].rsplit('\n', 1)[0].strip()
+ return reason == 'Explicitly installed'
+
+def is_orphan(pkg):
+ return not (is_explicitly_installed(pkg) or is_directly_required(pkg))
running_kernel = get_output('uname', '-r')
running_pkgs = get_output('pacman', '-Qoq', f'{MODULES}/{running_kernel}')
all_kernels = [f'{MODULES}/{k}' for k in os.listdir(MODULES)]
all_pkgs = get_output('pacman', '-Qoq', *all_kernels).split()
-orphaned_packages = [pkg for pkg in all_pkgs if not is_directly_required(pkg)]
+orphaned_packages = [pkg for pkg in all_pkgs if is_orphan(pkg)]
non_orphaned = []
orphaned_not_running = []