From 4205535bd8500ebfd6eab8e621322b25213db6f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 17:35:36 +0200 Subject: [PATCH] Clean up post-install script (#160) * Use variables to reduce code duplication. * Use variables to increase readability. * Break comment line that exceeded 100 characters. Co-authored-by: Mattias Axelsson --- app/postinstallscript.sh | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/app/postinstallscript.sh b/app/postinstallscript.sh index c29c645..e01ea5d 100644 --- a/app/postinstallscript.sh +++ b/app/postinstallscript.sh @@ -5,16 +5,21 @@ if [ ! -e /usr/bin/containerd ]; then exit 77 # EX_NOPERM fi +UID_DOT_GID="$(stat -c %u.%g localdata)" +IS_ROOT=$([ "$(id -u)" -eq 0 ] && echo true || echo false) + # Create empty daemon.json -if [ ! -e localdata/daemon.json ]; then +DAEMON_JSON=localdata/daemon.json +if [ ! -e "$DAEMON_JSON" ]; then umask 077 - echo "{}" >localdata/daemon.json - [ "$(id -u)" -ne 0 ] || chown "$(stat -c %u.%g localdata)" localdata/daemon.json + echo "{}" >"$DAEMON_JSON" + ! $IS_ROOT || chown "$UID_DOT_GID" "$DAEMON_JSON" fi -# ACAP framework does not handle ownership on SD card, which causes problem when the app user ID changes. -# If run as root, this script will repair the ownership. -SD_CARD_AREA=/var/spool/storage/SD_DISK/areas/"$(basename "$(pwd)")" -if [ "$(id -u)" -eq 0 ] && [ -d "$SD_CARD_AREA" ]; then - chown -R "$(stat -c %u.%g localdata)" "$SD_CARD_AREA" +# ACAP framework does not handle ownership on SD card, which causes problem when +# the app user ID changes. If run as root, this script will repair the ownership. +APP_NAME="$(basename "$(pwd)")" +SD_CARD_AREA=/var/spool/storage/SD_DISK/areas/"$APP_NAME" +if $IS_ROOT && [ -d "$SD_CARD_AREA" ]; then + chown -R "$UID_DOT_GID" "$SD_CARD_AREA" fi