diff options
author | Ferdinand Bachmann | 2022-04-03 02:26:09 +0200 |
---|---|---|
committer | Ferdinand Bachmann | 2022-04-03 02:26:09 +0200 |
commit | b87dc1442541197378808cf8c65519d11d2ad88c (patch) | |
tree | ea64aebbdcb07caa75ecfeb3b0a5e6e91366bc54 | |
parent | c4381d0d7ec720f983b413e6c0cecadde2dcb090 (diff) | |
download | aur-b87dc1442541197378808cf8c65519d11d2ad88c.tar.gz |
initial version (partly broken)
-rw-r--r-- | PKGBUILD | 2 | ||||
-rwxr-xr-x | preserve-modules.script | 54 |
2 files changed, 40 insertions, 16 deletions
@@ -13,7 +13,7 @@ source=(preserve-modules-copy.hook preserve-modules.script) sha256sums=('a38ad3600f174f1882d78191706f668eb1da585bf21ffbd6a0bf63057453f874' '276d479596bac1120162ba65229f5253fd4d44b3c44a57a9c4aeb8125fcf01b2' - 'c4d1a56a5207736e9f3f2c145b621e60a9d99a93b953ced4ed02917b75f33fc3') + '98820ebc17f2420092e947f60181729046cf656e537d364f6a965dccd30d9149') package() { install -Dm644 "$srcdir/preserve-modules-copy.hook" "$pkgdir/usr/share/libalpm/hooks/10-linux-preserve-modules-copy.hook" diff --git a/preserve-modules.script b/preserve-modules.script index c7bd3f5e17a5..cb9cc9d3ca2e 100755 --- a/preserve-modules.script +++ b/preserve-modules.script @@ -1,5 +1,7 @@ #!/bin/bash +shopt -s nullglob + KERNEL="$(uname -r)" TARGET="usr/lib/modules/$KERNEL" PRESERVE_MODULES_DIR=/run/linux-preserve-modules @@ -13,6 +15,9 @@ not() { } preserve-modules-copy() { + TARGET_DIR="/$TARGET" + PRESERVE_DIR="$PRESERVE_MODULES_DIR/modules/$KERNEL" + # exit early if kernel version empty if [[ -z "$KERNEL" ]]; then echo "error: unknown kernel version" >&2 @@ -26,31 +31,40 @@ preserve-modules-copy() { fi # exit early if the target directory does not exist - if [[ ! -d "/$TARGET" ]]; then + if [[ ! -d "$TARGET_DIR" ]]; then echo "info: nothing to copy" >&2 exit 0 fi - # unmount bind mounts before transaction for safety - mountpoint -q "/$TARGET/kernel" && umount "/$TARGET/kernel" - mountpoint -q "/$TARGET/updates" && umount "/$TARGET/updates" + # clean preserved files before transaction + if [[ -f "$TARGET_DIR/.preserved" ]]; then + rm "$TARGET_DIR/.preserved" + rm "$TARGET_DIR/modules".* + + mountpoint -q "$TARGET_DIR/kernel" && umount "$TARGET_DIR/kernel" + mountpoint -q "$TARGET_DIR/updates" && umount "$TARGET_DIR/updates" + fi # exit early if kernel modules already copied - if [[ -d "$PRESERVE_MODULES_DIR/modules/$KERNEL" ]]; then + if [[ -d "$PRESERVE_DIR" ]]; then echo "info: already copied" >&2 exit 0 fi - # copy over kernel modules - mkdir -p "$PRESERVE_MODULES_DIR/modules/$KERNEL" - [[ -d "/$TARGET/kernel" ]] && cp -r "/$TARGET/kernel" "$PRESERVE_MODULES_DIR/modules/$KERNEL/kernel" - [[ -d "/$TARGET/updates" ]] && cp -r "/$TARGET/updates" "$PRESERVE_MODULES_DIR/modules/$KERNEL/updates" + # copy over kernel modules and dep files + mkdir -p "$PRESERVE_DIR" + cp -r "$TARGET_DIR/modules".* "$PRESERVE_DIR/" + [[ -d "$TARGET_DIR/kernel" ]] && cp -r "$TARGET_DIR/kernel" "$PRESERVE_DIR/kernel" + [[ -d "$TARGET_DIR/updates" ]] && cp -r "$TARGET_DIR/updates" "$PRESERVE_DIR/updates" echo "info: copied modules" >&2 exit 0 } preserve-modules-link() { + TARGET_DIR="/$TARGET" + PRESERVE_DIR="$PRESERVE_MODULES_DIR/modules/$KERNEL" + # exit early if kernel version empty if [[ -z "$KERNEL" ]]; then echo "error: unknown kernel version" >&2 @@ -58,23 +72,33 @@ preserve-modules-link() { fi # exit early if no kernel modules copied - if [[ ! -d "$PRESERVE_MODULES_DIR/modules/$KERNEL" ]]; then + if [[ ! -d "$PRESERVE_DIR" ]]; then echo "info: nothing to link" >&2 exit 0 fi # exit early if mount targets still owned by a package - OWNERS=( $(pacman -Qoq "/$TARGET/kernel") $(pacman -Qoq "/$TARGET/updates") ) + OWNERS=( + $(pacman -Qoq "$TARGET_DIR/kernel" 2>/dev/null) + $(pacman -Qoq "$TARGET_DIR/updates" 2>/dev/null) + ) if [[ "${#OWNERS[@]}" -ne 0 ]]; then echo "info: modules still there" >&2 exit 0 fi + # copy over dep files and mark kernel version as preserved + touch "$TARGET_DIR/.preserved" + cp -r "$PRESERVE_DIR/modules".* "$TARGET_DIR/" + # bind mount preserved kernel modules - mkdir -p "/$TARGET/kernel" - mkdir -p "/$TARGET/updates" - [[ -d "$PRESERVE_MODULES_DIR/modules/$KERNEL/kernel" ]] && mount --bind "$PRESERVE_MODULES_DIR/modules/$KERNEL/kernel" "/$TARGET/kernel" - [[ -d "$PRESERVE_MODULES_DIR/modules/$KERNEL/updates" ]] && mount --bind "$PRESERVE_MODULES_DIR/modules/$KERNEL/updates" "/$TARGET/updates" + mkdir -p "$TARGET_DIR/kernel" + mkdir -p "$TARGET_DIR/updates" + [[ -d "$PRESERVE_DIR/kernel" ]] && mount --bind "$PRESERVE_DIR/kernel" "$TARGET_DIR/kernel" + [[ -d "$PRESERVE_DIR/updates" ]] && mount --bind "$PRESERVE_DIR/updates" "$TARGET_DIR/updates" + + # trigger depmod + depmod "$KERNEL" echo "info: linked modules" >&2 exit 0 |