Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
grawlinson committed Apr 12, 2020
0 parents commit 181d74c
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 0 deletions.
451 changes: 451 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# dracut-alpm-hook

This provides [alpm hooks][alpm-hooks5] for [dracut][dracut] to generate a new initramfs on kernel upgrade.

## Usage

Copy hooks (`*.hook`) to `/usr/share/libalpm/hooks` and scripts to `/usr/share/libalpm/scripts`.

## License

[FDL 1.3][fdl]

[alpm-hooks5]:https://www.archlinux.org/pacman/alpm-hooks.5.html
[dracut]:/~https://github.com/dracutdevs/dracut
[fdl]:http://www.gnu.org/licenses/fdl-1.3.html

16 changes: 16 additions & 0 deletions hooks/60-dracut-remove.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Trigger]
Type = File
Operation = Remove
Target = usr/lib/modules/*/pkgbase

[Trigger]
Type = Package
Operation = Remove
Target = dracut
Target = dracut-git

[Action]
Description = Remove linux initcpios...
When = PreTransaction
Exec = /usr/share/libalpm/scripts/dracut-remove
NeedsTargets
12 changes: 12 additions & 0 deletions hooks/90-dracut-install.hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Trigger]
Type = File
Operation = Install
Operation = Upgrade
Target = usr/lib/modules/*/pkgbase
Target = usr/lib/dracut/*

[Action]
Description = Updating linux initcpios...
When = PostTransaction
Exec = /usr/share/libalpm/scripts/dracut-install
NeedsTargets
15 changes: 15 additions & 0 deletions scripts/dracut-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

args=('--force' '--no-hostonly-cmdline')

while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
kver="${line#'usr/lib/modules/'}"
kver="${kver%'/pkgbase'}"

install -Dm0644 "/${line%'/pkgbase'}/vmlinuz" "/boot/vmlinuz-${pkgbase}"
dracut "${args[@]}" "/boot/initramfs-${pkgbase}.img" --kver "$kver"
dracut "${args[@]}" --no-hostonly "/boot/initramfs-${pkgbase}-fallback.img" --kver "$kver"
fi
done
8 changes: 8 additions & 0 deletions scripts/dracut-remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

while read -r line; do
if [[ "$line" == 'usr/lib/modules/'+([^/])'/pkgbase' ]]; then
read -r pkgbase < "/${line}"
rm -f "/boot/vmlinuz-${pkgbase}" "/boot/initramfs-${pkgbase}.img" "/boot/initramfs-${pkgbase}-fallback.img"
fi
done

0 comments on commit 181d74c

Please sign in to comment.