ptrcnull.me/content/posts/alpine-commit-hooks.md

39 lines
1.2 KiB
Markdown
Raw Normal View History

2021-07-13 10:31:02 +00:00
---
title: "How to use Alpine Linux commit hooks"
date: 2021-04-18T13:56:06+02:00
draft: false
---
tl;dr:
2021-07-13 10:31:02 +00:00
- Create directory `/etc/apk/commit_hooks.d`
2021-07-13 10:31:02 +00:00
- Put your executable files in there
- First argument passed to your script is the stage (`pre-commit`/`post-commit`)
### Example hook
```shell
#!/bin/sh
2021-07-13 10:31:02 +00:00
if ! mount | grep -q '/boot/efi'; then
mount /boot/efi
fi
if [[ "$1" == "post-commit" ]]; then
cp /boot/initramfs-lts /boot/efi/alpine/initramfs-lts
cp /boot/vmlinuz-lts /boot/efi/alpine/vmlinuz-lts
2021-07-13 10:31:02 +00:00
fi
```
### Why?
I use [Gummiboot](https://en.wikipedia.org/wiki/Gummiboot_(software)) as my bootloader,
which can boot Linux kernel images directly from the EFI partition.
Alpine packages don't care about EFI though, they just put the stuff in `/boot`
[directly](https://pkgs.alpinelinux.org/contents?file=&path=%2Fboot&name=linux-lts&branch=edge&repo=main&arch=x86_64).
(I mean, the official wiki just says "manually copy them to `/boot/efi/`", which works but I tend to forget about it)
I didn't want to mount EFI as `/boot`, so I decided that creating a commit hook would be
the easiest way of hotfixing that issue (not ideal, as it runs with _every_ apk commit,
but feasible for my use).