Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use hardlinks, bind mount and systemd-tmpfiles to simplify the logic #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions .SRCINFO
Original file line number Diff line number Diff line change
Expand Up @@ -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 = fc4d53dec520c80fe97dfda65b238c7d678e7ef26aaebffc5b43f924477ea4f4
sha256sums = 087e5ed70b2fc512d814fbded9e873955b1da5b6bf1e31975174d704ad143156
sha256sums = 7cf080b0d0d5a07ccb414ffb793525e554ca95447201f22b917f0be04ff48d2a
sha256sums = 3168ea6c2740dbde4229d718e44f6262f2d10aef529fb446cdb4f1778b8b6424

pkgname = kernel-modules-hook

21 changes: 1 addition & 20 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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*
8 changes: 3 additions & 5 deletions 10-linux-modules-post.hook
Original file line number Diff line number Diff line change
@@ -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
NeedsTargets
8 changes: 4 additions & 4 deletions 10-linux-modules-pre.hook
Original file line number Diff line number Diff line change
@@ -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
NeedsTargets
31 changes: 14 additions & 17 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# Maintainer: Artoria Pendragon <[email protected]>
# 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')
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")
sha256sums=('4169b44c297ddb7aad2220c6eba7c7942e3396f92528c59617955ab5560cb4cf'
'5d947290ef8c94b33c79c531e5615f4c9bea38e7649092d34af3bf0af5b1ca24'
'900502d030e925fca6188b9448fbaf6562d6e23cd5c50938cdf00522825f76c2'
'f7ea2947c3fbe1510b3ea5cc5793b8197f0718dcb12daea3da9b27b3cf1c4116'
'7e12e5df4bae12cb21581ba157ced20e1986a0508dd10d0e8a4ab9a4cf94e85c')
"10-linux-modules-post.hook"
"10-linux-modules-pre.hook"
"linux-modules-restore"
"linux-modules-save"
)
sha256sums=('950f851eba08dac4d0b93ff62b3fb16ddacd4f8ebb98a2435f80bf05f2ea5a29'
'fc4d53dec520c80fe97dfda65b238c7d678e7ef26aaebffc5b43f924477ea4f4'
'087e5ed70b2fc512d814fbded9e873955b1da5b6bf1e31975174d704ad143156'
'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-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/"
install -Dm755 linux-modules-{save,restore} -t "${pkgdir}/usr/share/libalpm/scripts/"
}
16 changes: 0 additions & 16 deletions kernel-modules-hook.install

This file was deleted.

3 changes: 2 additions & 1 deletion linux-modules-cleanup.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
R! /usr/lib/modules/.old/* - - - 4w
R! /usr/lib/modules/running-kernel
r /usr/lib/modules/*
9 changes: 0 additions & 9 deletions linux-modules-cleanup.service

This file was deleted.

11 changes: 11 additions & 0 deletions linux-modules-restore
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions linux-modules-save
Original file line number Diff line number Diff line change
@@ -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