diff options
author | Ferdinand Bachmann | 2022-05-31 15:03:50 +0200 |
---|---|---|
committer | Ferdinand Bachmann | 2022-06-13 03:20:07 +0200 |
commit | 780e928906668714ac562b39f4b1349b8610503a (patch) | |
tree | e63f4c8879a059f90d1811b41f417c0911dd18c4 | |
parent | 82c9fe7f8e479bdc864405a8b455b3dd46f44f74 (diff) | |
download | aur-780e928906668714ac562b39f4b1349b8610503a.tar.gz |
linux-preserve-modules: add unlink-all
-rwxr-xr-x | linux-preserve-modules | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/linux-preserve-modules b/linux-preserve-modules index 2e40066051c9..a0dae5ebea08 100755 --- a/linux-preserve-modules +++ b/linux-preserve-modules @@ -27,7 +27,7 @@ set-vars() { preserve-modules-copy() { if [[ $# -gt 1 ]]; then - echo "usage: preserve-modules copy [release]" >&2 + echo "usage: linux-preserve-modules copy [release]" >&2 exit 1 elif [[ $# -eq 1 ]]; then set-vars "$1" @@ -63,7 +63,7 @@ preserve-modules-copy() { preserve-modules-link() { if [[ $# -gt 1 ]]; then - echo "usage: preserve-modules link [release]" >&2 + echo "usage: linux-preserve-modules link [release]" >&2 exit 1 elif [[ $# -eq 1 ]]; then set-vars "$1" @@ -111,7 +111,7 @@ preserve-modules-link() { preserve-modules-unlink() { if [[ $# -gt 1 ]]; then - echo "usage: preserve-modules unlink [release]" >&2 + echo "usage: linux-preserve-modules unlink [release]" >&2 exit 1 elif [[ $# -eq 1 ]]; then set-vars "$1" @@ -129,12 +129,35 @@ preserve-modules-unlink() { mountpoint -q "$TARGET_DIR/kernel" && umount "$TARGET_DIR/kernel" mountpoint -q "$TARGET_DIR/updates" && umount "$TARGET_DIR/updates" + # remove mount points if empty + rmdir --ignore-fail-on-non-empty "$TARGET_DIR/kernel" + rmdir --ignore-fail-on-non-empty "$TARGET_DIR/updates" + rmdir --ignore-fail-on-non-empty "$TARGET_DIR" + echo "info: unlinked modules" >&2 exit 0 } +preserve-modules-unlink-all() { + if [[ $# -gt 0 ]]; then + echo "usage: linux-preserve-modules unlink-all" >&2 + exit 1 + fi + + # find kernels with .preserved marker file + LINKED_KERNELS=( $(find /usr/lib/modules -maxdepth 2 -type f -name .preserved | cut -d/ -f5) ) + echo "info: found ${#LINKED_KERNELS[@]} kernels with linked modules" >&2 + + # unlink modules for each + for kernel in ${LINKED_KERNELS[@]}; do + linux-preserve-modules unlink "$kernel" + done + + exit 0 +} + usage() { - echo "usage: linux-preserve-modules <copy|link|unlink> [release]" >&2 + echo "usage: linux-preserve-modules <copy|link|unlink|unlink-all> [release]" >&2 exit 1 } @@ -156,6 +179,7 @@ main() { copy) preserve-modules-copy "$@";; link) preserve-modules-link "$@";; unlink) preserve-modules-unlink "$@";; + unlink-all) preserve-modules-unlink-all "$@";; *) usage;; esac } |