From 16d17277c608d995ad4d0b495d029c753509930c Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 11 Jul 2022 11:22:21 +0200 Subject: [PATCH 1/5] Only gitignore built packages This looks wrong to ignore files in the repostory. --- .gitignore | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 6febc73..0012882 100644 --- a/.gitignore +++ b/.gitignore @@ -1,20 +1 @@ -# ignore everything -* -!.gitignore - -# except PKGBUILD needed files -!PKGBUILD -!.SRCINFO -!*.install - -# common wing-man files -!*.diff -!*.patch - -# add files that don't have an online source -kernel-modules-hook.install -linux-modules-cleanup.conf -linux-modules-cleanup.service -10-linux-modules-post.hook -10-linux-modules-pre.hook -UNLICENSE +*pkg.tar* From ded83bc7f31df14b2e9a8d7bdfa1e95eee2bf5c1 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 11 Jul 2022 11:28:57 +0200 Subject: [PATCH 2/5] Clean up PKGBUILD The Unlicense license is include in the licenses packages, not need to include it. --- PKGBUILD | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index 8ffb97b..e7e88a8 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -6,24 +6,20 @@ pkgrel=1 pkgdesc="Keeps your system fully functional after a kernel upgrade" arch=('any') url="https://github.com/saber-nyan/kernel-modules-hook" -license=('UNLICENSE') depends=('rsync') install="${pkgname}.install" +license=('Unlicense') source=("linux-modules-cleanup.conf" "linux-modules-cleanup.service" "10-linux-modules-post.hook" - "10-linux-modules-pre.hook" - "UNLICENSE") + "10-linux-modules-pre.hook") sha256sums=('4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf' '5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24' '900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2' - 'f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116' - '7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c') + 'f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116') package() { install -Dm644 'linux-modules-cleanup.conf' "${pkgdir}/usr/lib/tmpfiles.d/linux-modules-cleanup.conf" install -Dm644 'linux-modules-cleanup.service' "${pkgdir}/usr/lib/systemd/system/linux-modules-cleanup.service" - install -Dm644 '10-linux-modules-post.hook' "${pkgdir}/usr/share/libalpm/hooks/10-linux-modules-post.hook" - install -Dm644 '10-linux-modules-pre.hook' "${pkgdir}/usr/share/libalpm/hooks/10-linux-modules-pre.hook" - install -Dm644 'UNLICENSE' "${pkgdir}/usr/share/licenses/${pkgname}/UNLICENSE" + install -Dm644 10-linux-modules-{pre,post}.hook -t "${pkgdir}/usr/share/libalpm/hooks/" } From c554030c41ca7a070067102f69ef8c575800b823 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 11 Jul 2022 16:51:22 +0200 Subject: [PATCH 3/5] Use cp instead of rsync + systemd-tmpfiles for cleaning This use cp with hardlinks + a bind mount for keeping the removed kernel modules accessible. Cleaning up the backup is done by systemd-tmpfiles on next boot. Cleaning up the mount is either done on shutdown implicitly, or when we reinstall the running kernel by the pre-hook script. No systemd service enabling is needed. --- .SRCINFO | 19 ++++++++----------- 10-linux-modules-post.hook | 8 +++----- 10-linux-modules-pre.hook | 8 ++++---- PKGBUILD | 21 +++++++++++---------- kernel-modules-hook.install | 16 ---------------- linux-modules-cleanup.conf | 3 ++- linux-modules-cleanup.service | 9 --------- linux-modules-restore | 11 +++++++++++ linux-modules-save | 24 ++++++++++++++++++++++++ 9 files changed, 63 insertions(+), 56 deletions(-) delete mode 100644 kernel-modules-hook.install delete mode 100644 linux-modules-cleanup.service create mode 100644 linux-modules-restore create mode 100644 linux-modules-save diff --git a/.SRCINFO b/.SRCINFO index fe5355d..58daf13 100644 --- a/.SRCINFO +++ b/.SRCINFO @@ -3,20 +3,17 @@ pkgbase = kernel-modules-hook pkgver = 0.1.7 pkgrel = 1 url = https://github.com/saber-nyan/kernel-modules-hook - install = kernel-modules-hook.install arch = any - license = UNLICENSE - depends = rsync + license = Unlicense source = linux-modules-cleanup.conf - source = linux-modules-cleanup.service source = 10-linux-modules-post.hook source = 10-linux-modules-pre.hook - source = UNLICENSE - sha256sums = 4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf - sha256sums = 5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24 - sha256sums = 900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2 - sha256sums = f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116 - sha256sums = 7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c + source = linux-modules-restore + source = linux-modules-save + sha256sums = 950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29 + sha256sums = 0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f + sha256sums = 2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10 + sha256sums = 7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a + sha256sums = 3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424 pkgname = kernel-modules-hook - diff --git a/10-linux-modules-post.hook b/10-linux-modules-post.hook index 55174ac..3f2f930 100644 --- a/10-linux-modules-post.hook +++ b/10-linux-modules-post.hook @@ -1,12 +1,10 @@ [Trigger] -Operation = Install -Operation = Upgrade +Operation = Remove Type = Path Target = usr/lib/modules/*/vmlinuz [Action] Description = Restoring Linux kernel modules... When = PostTransaction -Depends = coreutils -Depends = rsync -Exec = /bin/sh -xc 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/backup/${KVER}"; then rsync -AHXal --ignore-existing "/usr/lib/modules/backup/${KVER}" /usr/lib/modules/; fi; rm -rf /usr/lib/modules/backup' +Exec = /usr/share/libalpm/scripts/linux-modules-restore +NeedsTarget diff --git a/10-linux-modules-pre.hook b/10-linux-modules-pre.hook index 34e7221..f6ff54a 100644 --- a/10-linux-modules-pre.hook +++ b/10-linux-modules-pre.hook @@ -1,11 +1,11 @@ [Trigger] Operation = Install -Operation = Upgrade +Operation = Remove Type = Path Target = usr/lib/modules/*/vmlinuz [Action] -Description = Saving Linux kernel modules... +Description = Saving Linux kernel modules directory (hardlinks)... When = PreTransaction -Depends = rsync -Exec = /bin/sh -c 'KVER="${KVER:-$(uname -r)}"; if test -e "/usr/lib/modules/${KVER}"; then rsync -AHXal --delete-after "/usr/lib/modules/${KVER}" /usr/lib/modules/backup/; fi' +Exec = /usr/share/libalpm/scripts/linux-modules-save +NeedsTarget diff --git a/PKGBUILD b/PKGBUILD index e7e88a8..0659962 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -6,20 +6,21 @@ pkgrel=1 pkgdesc="Keeps your system fully functional after a kernel upgrade" arch=('any') url="https://github.com/saber-nyan/kernel-modules-hook" -depends=('rsync') -install="${pkgname}.install" license=('Unlicense') source=("linux-modules-cleanup.conf" - "linux-modules-cleanup.service" - "10-linux-modules-post.hook" - "10-linux-modules-pre.hook") -sha256sums=('4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf' - '5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24' - '900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2' - 'f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116') + "10-linux-modules-post.hook" + "10-linux-modules-pre.hook" + "linux-modules-restore" + "linux-modules-save" +) +sha256sums=('950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29' + '0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f' + '2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10' + '7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a' + '3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424') package() { install -Dm644 'linux-modules-cleanup.conf' "${pkgdir}/usr/lib/tmpfiles.d/linux-modules-cleanup.conf" - install -Dm644 'linux-modules-cleanup.service' "${pkgdir}/usr/lib/systemd/system/linux-modules-cleanup.service" install -Dm644 10-linux-modules-{pre,post}.hook -t "${pkgdir}/usr/share/libalpm/hooks/" + install -Dm755 linux-modules-{save,restore} -t "${pkgdir}/usr/share/libalpm/scripts/" } diff --git a/kernel-modules-hook.install b/kernel-modules-hook.install deleted file mode 100644 index b0af4a3..0000000 --- a/kernel-modules-hook.install +++ /dev/null @@ -1,16 +0,0 @@ -post_install() { - cat << EOF - -Please execute - - $ sudo systemctl daemon-reload - $ sudo systemctl enable linux-modules-cleanup - -Report any issues to: -https://github.com/saber-nyan/kernel-modules-hook/issues - - - ~desu - -EOF -} diff --git a/linux-modules-cleanup.conf b/linux-modules-cleanup.conf index 80bc0cf..1dd8d3b 100644 --- a/linux-modules-cleanup.conf +++ b/linux-modules-cleanup.conf @@ -1 +1,2 @@ -R! /usr/lib/modules/.old/* - - - 4w +R! /usr/lib/modules/running-kernel +r /usr/lib/modules/* diff --git a/linux-modules-cleanup.service b/linux-modules-cleanup.service deleted file mode 100644 index 35a60dc..0000000 --- a/linux-modules-cleanup.service +++ /dev/null @@ -1,9 +0,0 @@ -[Unit] -Description=Clean up modules from old kernels - -[Service] -Type=oneshot -ExecStart=/bin/bash -exc 'for i in /usr/lib/modules/[0-9]*; do if [[ $${i##*/} = \'%v\' ]] || pacman -Qo "$${i}"; then continue; fi; rsync -AHXal "$${i}" /usr/lib/modules/.old/; rm -rf "$${i}"; done' - -[Install] -WantedBy=basic.target diff --git a/linux-modules-restore b/linux-modules-restore new file mode 100644 index 0000000..8115940 --- /dev/null +++ b/linux-modules-restore @@ -0,0 +1,11 @@ +#!/bin/bash -e + +kver = $(uname -r) +while read -r line; do + # We only care about the running kernel + if [[ "$line" == usr/lib/modules/$kver/vmlinuz && -d "${line/$kver/running-kernel}" ]];then + mount --mkdir --bind --options ro /usr/lib/modules/{running-kernel,$kver} + # Mounting read-only since the only modification here should be unmounting + # when rebooting or reinstalling the running kernel + fi +done diff --git a/linux-modules-save b/linux-modules-save new file mode 100644 index 0000000..9ccb370 --- /dev/null +++ b/linux-modules-save @@ -0,0 +1,24 @@ +#!/bin/bash -e + +kver = $(uname -r) +while read -r line; do + # We only care about the running kernel + if [[ "$line" == "usr/lib/modules/$kver/vmlinuz" ]];then + if [[ mountpoint --nofollow --quiet ${line%vmlinuz} ]];then + # Mount point is already present + # This means we already ran that hook during 'remove case' + # + # Remove the mount so we can reinstall the kernel + umount ${line%vmlinuz} + elif [[ -f "$line" && ! -d "/usr/lib/modules/running-kernel/" ]];then + # Kernel install is present and we do not have a copy + # + # This is the removal case, so we save the kernel + mkdir /usr/lib/modules/running-kernel + cp --archive --link /usr/lib/modules/{$kver}/{kernel,modules*} \ + /usr/lib/modules/running-kernel/ + fi + # If we are re-removing the running kernel, (after removing + reinstalling), + # we already have a backup and this hook is a no-op + fi +done From 4c9caab8a77082d39fec08150e896cb2343ccbad Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 11 Jul 2022 17:01:14 +0200 Subject: [PATCH 4/5] Bump pkgver --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 0659962..9fcb1aa 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,7 +1,7 @@ # Maintainer: Artoria Pendragon # Hooks: https://www.reddit.com/r/archlinux/comments/4zrsc3/keep_your_system_fully_functional_after_a_kernel/d6yin0r/ pkgname=kernel-modules-hook -pkgver=0.1.7 +pkgver=0.2.0 pkgrel=1 pkgdesc="Keeps your system fully functional after a kernel upgrade" arch=('any') From 58867e8a6f3b08b3b0229a65c9def07c1adf77bb Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Wed, 22 Feb 2023 09:07:28 +0100 Subject: [PATCH 5/5] Fix wrong parameters in hook files --- .SRCINFO | 4 ++-- 10-linux-modules-post.hook | 2 +- 10-linux-modules-pre.hook | 2 +- PKGBUILD | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.SRCINFO b/.SRCINFO index 58daf13..2ec339a 100644 --- a/.SRCINFO +++ b/.SRCINFO @@ -11,8 +11,8 @@ pkgbase = kernel-modules-hook source = linux-modules-restore source = linux-modules-save sha256sums = 950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29 - sha256sums = 0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f - sha256sums = 2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10 + sha256sums = fc4d53dec520c80fe97dfda65b238c7d678e7ef26aaebffc5b43f924477ea4f4 + sha256sums = 087e5ed70b2fc512d814fbded9e873955b1da5b6bf1e31975174d704ad143156 sha256sums = 7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a sha256sums = 3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424 diff --git a/10-linux-modules-post.hook b/10-linux-modules-post.hook index 3f2f930..11e71e2 100644 --- a/10-linux-modules-post.hook +++ b/10-linux-modules-post.hook @@ -7,4 +7,4 @@ Target = usr/lib/modules/*/vmlinuz Description = Restoring Linux kernel modules... When = PostTransaction Exec = /usr/share/libalpm/scripts/linux-modules-restore -NeedsTarget +NeedsTargets diff --git a/10-linux-modules-pre.hook b/10-linux-modules-pre.hook index f6ff54a..38e4134 100644 --- a/10-linux-modules-pre.hook +++ b/10-linux-modules-pre.hook @@ -8,4 +8,4 @@ Target = usr/lib/modules/*/vmlinuz Description = Saving Linux kernel modules directory (hardlinks)... When = PreTransaction Exec = /usr/share/libalpm/scripts/linux-modules-save -NeedsTarget +NeedsTargets diff --git a/PKGBUILD b/PKGBUILD index 9fcb1aa..0f608e2 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -14,8 +14,8 @@ source=("linux-modules-cleanup.conf" "linux-modules-save" ) sha256sums=('950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29' - '0492722850f90066d33baf7896eb4625fd812890bdb03f025184c8b4bf0ef94f' - '2b86a037a9a394f57279408745bf5b19542f26b0ad862fd514470cd145108c10' + 'fc4d53dec520c80fe97dfda65b238c7d678e7ef26aaebffc5b43f924477ea4f4' + '087e5ed70b2fc512d814fbded9e873955b1da5b6bf1e31975174d704ad143156' '7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a' '3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424')