diff options
author | chrisjbillington | 2020-02-28 12:33:30 -0500 |
---|---|---|
committer | chrisjbillington | 2020-02-28 12:33:30 -0500 |
commit | 974d80ea5a070c1c961d7faaaa0dc7fe8072c621 (patch) | |
tree | 83cbe85a296d54579b78fc7130fc962d990c3eea | |
download | aur-974d80ea5a070c1c961d7faaaa0dc7fe8072c621.tar.gz |
Initial commit
-rw-r--r-- | .SRCINFO | 14 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | PKGBUILD | 16 | ||||
-rwxr-xr-x | remove-orphaned-kernels | 74 |
4 files changed, 107 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..c9dde7d5678a --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,14 @@ +pkgbase = remove-orphaned-kernels + pkgdesc = pacman -Rs orphaned kernel and driver packages, excluding currently-running. + pkgver = 1.0 + pkgrel = 1 + url = https://aur.archlinux.org/packages/remove-orphaned-kernels/ + arch = any + license = GPL + depends = python + depends = sudo + source = remove-orphaned-kernels + sha256sums = a6939f973aa8013944354db38d4b42e0bcf69673fbabbc804af9842d27101649 + +pkgname = remove-orphaned-kernels + diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..e72c9f355319 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +pkg +src +*.pkg.*
\ No newline at end of file diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..fb5d1a369546 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,16 @@ +# Maintainer: Chris Billington <chrisjbillington@gmail.com> +pkgname=remove-orphaned-kernels +pkgver=1.0 +pkgrel=1 +pkgdesc="pacman -Rs orphaned kernel and driver packages, excluding currently-running." +arch=('any') +url="https://aur.archlinux.org/packages/${pkgname}/" +license=('GPL') +depends=('python' 'sudo') +source=("${pkgname}") +sha256sums=('a6939f973aa8013944354db38d4b42e0bcf69673fbabbc804af9842d27101649') + +package() { + install -m755 -d "${pkgdir}/usr/bin/" + install -m755 "${srcdir}/${pkgname}" "${pkgdir}/usr/bin/${pkgname}" +}
\ No newline at end of file diff --git a/remove-orphaned-kernels b/remove-orphaned-kernels new file mode 100755 index 000000000000..9e257f2cba38 --- /dev/null +++ b/remove-orphaned-kernels @@ -0,0 +1,74 @@ +#! /usr/bin/python +from subprocess import run +import sys +import os + +MODULES = '/usr/lib/modules' + + +def get_output(*cmd): + return run(cmd, capture_output=True).stdout.decode('utf8').strip() + + +def yn_choice(message, default='y'): + try: + choices = 'Y/n' if default.lower() in ('y', 'yes') else 'y/N' + choice = input("%s\n(%s): " % (message, choices)) + values = ('y', 'yes', '') if default == 'y' else ('y', 'yes') + return choice.strip().lower() in values + except (KeyboardInterrupt, EOFError): + sys.exit(1) + + +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 = get_output('pacman', '-Qdtq', *all_pkgs).split() + +non_orphaned = [] +orphaned_not_running = [] +orphaned_running = [] + +for pkg in sorted(all_pkgs): + orphaned = pkg in orphaned_packages + running = pkg in running_pkgs + + if orphaned and not running: + orphaned_not_running.append(pkg) + elif orphaned: + orphaned_running.append(pkg) + else: + non_orphaned.append(pkg) + +if non_orphaned: + print( + "The following required or explicitly-installed kernel packages will be kept:" + ) + for pkg in non_orphaned: + print(' ', pkg) + + print() + +if orphaned_running: + print( + "The following orphaned packages for the currently running kernel will be kept:" + ) + for pkg in orphaned_running: + print(' ', pkg) + + print() + +if orphaned_not_running: + print("The following orphaned kernel packages will be removed:") + for pkg in orphaned_not_running: + print(' ', pkg) + + print() + +if not orphaned_not_running: + print("Nothing to do") + sys.exit(0) + +if yn_choice("Continue?"): + sys.exit(run(['sudo', 'pacman', '-Rs'] + orphaned_not_running).returncode) |