summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Bachmann2022-04-03 02:01:24 +0200
committerFerdinand Bachmann2022-04-03 02:01:24 +0200
commitc4381d0d7ec720f983b413e6c0cecadde2dcb090 (patch)
tree8ef1ad5e27e7f5853903d5d6d13359466cbcba6c
parent8d54daf056c6453b185fc87e327f7c314b654c2e (diff)
downloadaur-c4381d0d7ec720f983b413e6c0cecadde2dcb090.tar.gz
implement module copying
-rw-r--r--.SRCINFO2
-rw-r--r--PKGBUILD2
-rwxr-xr-xpreserve-modules.script86
3 files changed, 81 insertions, 9 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 08bfa0d9c837..86b703763050 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -10,6 +10,6 @@ pkgbase = linux-preserve-modules
source = preserve-modules.script
sha256sums = a38ad3600f174f1882d78191706f668eb1da585bf21ffbd6a0bf63057453f874
sha256sums = 276d479596bac1120162ba65229f5253fd4d44b3c44a57a9c4aeb8125fcf01b2
- sha256sums = a5bd0cef8a5f803f62bd6091f616474ee4a896226650cd4ad53978527dbb4682
+ sha256sums = c4d1a56a5207736e9f3f2c145b621e60a9d99a93b953ced4ed02917b75f33fc3
pkgname = linux-preserve-modules
diff --git a/PKGBUILD b/PKGBUILD
index ee994c95cd82..e63042216ac4 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -13,7 +13,7 @@ source=(preserve-modules-copy.hook
preserve-modules.script)
sha256sums=('a38ad3600f174f1882d78191706f668eb1da585bf21ffbd6a0bf63057453f874'
'276d479596bac1120162ba65229f5253fd4d44b3c44a57a9c4aeb8125fcf01b2'
- 'a5bd0cef8a5f803f62bd6091f616474ee4a896226650cd4ad53978527dbb4682')
+ 'c4d1a56a5207736e9f3f2c145b621e60a9d99a93b953ced4ed02917b75f33fc3')
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 abbf4b81aabc..c7bd3f5e17a5 100755
--- a/preserve-modules.script
+++ b/preserve-modules.script
@@ -1,11 +1,83 @@
-#!/bin/sh
+#!/bin/bash
-preserve_modules_copy() {
- cat > /home/yrlf/wtf.log
+KERNEL="$(uname -r)"
+TARGET="usr/lib/modules/$KERNEL"
+PRESERVE_MODULES_DIR=/run/linux-preserve-modules
+
+not() {
+ if "$@"; then
+ return 1
+ else
+ return 0
+ fi
+}
+
+preserve-modules-copy() {
+ # exit early if kernel version empty
+ if [[ -z "$KERNEL" ]]; then
+ echo "error: unknown kernel version" >&2
+ exit 1
+ fi
+
+ # exit early if currently running kernel modules untouched
+ if not grep -F -q "$TARGET"; then
+ echo "info: nothing to copy" >&2
+ exit 0
+ fi
+
+ # exit early if the target directory does not exist
+ if [[ ! -d "/$TARGET" ]]; 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"
+
+ # exit early if kernel modules already copied
+ if [[ -d "$PRESERVE_MODULES_DIR/modules/$KERNEL" ]]; 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"
+
+ echo "info: copied modules" >&2
+ exit 0
}
-preserve_modules_link() {
+preserve-modules-link() {
+ # exit early if kernel version empty
+ if [[ -z "$KERNEL" ]]; then
+ echo "error: unknown kernel version" >&2
+ exit 1
+ fi
+
+ # exit early if no kernel modules copied
+ if [[ ! -d "$PRESERVE_MODULES_DIR/modules/$KERNEL" ]]; 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") )
+ if [[ "${#OWNERS[@]}" -ne 0 ]]; then
+ echo "info: modules still there" >&2
+ exit 0
+ fi
+
+ # 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"
+ echo "info: linked modules" >&2
+ exit 0
}
usage() {
@@ -13,12 +85,12 @@ usage() {
exit 1
}
-if [ "$#" -ne 1 ]; then
+if [[ "$#" -ne 1 ]]; then
usage
fi
case "$1" in
- copy) preserve_modules_copy;;
- link) preserve_modules_link;;
+ copy) preserve-modules-copy;;
+ link) preserve-modules-link;;
*) usage;;
esac