Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge mkinitcpio libalpm scripts into one
Fixes #10
Co-authored-by: nl6720 <nl6720@gmail.com>
Signed-off-by: Hugo Osvaldo Barrera <hugo@barrera.io>
- Loading branch information
1 parent
4a2367a
commit aac3876
Showing
6 changed files
with
98 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
args=() | ||
package=0 | ||
|
||
process_preset() { | ||
if [[ -n "$pkgbase" && -e "$preset" ]]; then | ||
if ! cmp "$preset" > /dev/null 2>&1 <(sed "s|%PKGBASE%|${pkgbase}|g" /usr/share/mkinitcpio/hook.preset); then | ||
if [[ ! -e "$preset.pacsave" ]]; then | ||
# save the preset as pacsave | ||
mv -- "$preset" "$preset.pacsave" && return 0 | ||
fi | ||
else | ||
# remove the preset | ||
rm -- "$preset" && return 0 | ||
fi | ||
fi | ||
} | ||
|
||
install_kernel() { | ||
preset="/etc/mkinitcpio.d/${1}.preset" | ||
if [[ ! -e "$preset" ]]; then | ||
if [[ -e "$preset.pacsave" ]]; then | ||
# move the pacsave to the template | ||
mv -- "${preset}.pacsave" "$preset" | ||
else | ||
# create the preset from the template | ||
sed "s|%PKGBASE%|${1}|g" /usr/share/mkinitcpio/hook.preset \ | ||
| install -Dm644 /dev/stdin "$preset" | ||
fi | ||
fi | ||
|
||
# always install the kernel | ||
install -Dm644 "$line" "/boot/vmlinuz-${1}" | ||
|
||
# compound args for each kernel | ||
args+=(-p "$1") | ||
} | ||
|
||
remove_kernel() { | ||
# remove the actual kernel and images for the package being removed | ||
kernel="/boot/vmlinuz-${1}" | ||
preset="/etc/mkinitcpio.d/${1}.preset" | ||
initramfs="/boot/initramfs-${1}.img" | ||
fallback_initramfs="/boot/initramfs-${1}-fallback.img" | ||
# remove the installed kernel | ||
rm -f -- "$kernel" | ||
|
||
process_preset "$1" "$preset" | ||
|
||
# remove images | ||
rm -f -- "$initramfs" "$fallback_initramfs" | ||
} | ||
|
||
while read -r line; do | ||
if [[ "$line" != */vmlinuz ]]; then | ||
# triggers when it's a change to usr/lib/initcpio/* | ||
package=1 | ||
continue | ||
fi | ||
|
||
if ! read -r pkgbase > /dev/null 2>&1 < "${line%/vmlinuz}/pkgbase"; then | ||
# if the kernel has no pkgbase, we skip it | ||
continue | ||
fi | ||
|
||
case "$1" in | ||
install) install_kernel "$pkgbase";; | ||
remove) remove_kernel "$pkgbase";; | ||
esac | ||
done | ||
|
||
if (( package )) && compgen -G /etc/mkinitcpio.d/"*.preset" > /dev/null; then | ||
case "$1" in | ||
install) | ||
# change to use all presets | ||
args=(-P) | ||
;; | ||
remove) | ||
shopt -s nullglob | ||
for preset in /etc/mkinitcpio.d/*.preset; do | ||
pkgbase=${preset##*/} | ||
pkgbase=${pkgbase%.preset} | ||
process_preset "$pkgbase" "$preset" | ||
done | ||
shopt -u nullglob | ||
;; | ||
esac | ||
fi | ||
|
||
if [[ "$1" == "install" ]] && (( ${#args[@]} )); then | ||
mkinitcpio "${args[@]}" | ||
fi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.