This uses some lightweight tools with systemd-inhibit to block sleep and shutdown when apk is running. This is being installed in a new subpkg that is pulled in only when apk-tools is installed, so that this is not installed on duranium. Signed-off-by: Clayton Craft <craftyguy@postmarketos.org> Part-of: <https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/8672>
15 lines
512 B
Bash
15 lines
512 B
Bash
#!/bin/sh
|
|
|
|
while true; do
|
|
# wait for something to open apk's lock file
|
|
inotifywait -q -e open /usr/lib/apk/db/lock
|
|
|
|
# Take an inhibitor lock and make it conditional on flock, which is trying
|
|
# to lock apk's lock file. flock will block until it can take a lock (i.e.
|
|
# if apk is doing operations), so the inhibitor lock is held until apk is
|
|
# done.
|
|
systemd-inhibit --what=sleep --who=apk \
|
|
--why="Package transaction in progress" \
|
|
flock /usr/lib/apk/db/lock true
|
|
done
|