Skip to content

Commit

Permalink
Clean up post-install script (#160)
Browse files Browse the repository at this point in the history
* Use variables to reduce code duplication.
* Use variables to increase readability.
* Break comment line that exceeded 100 characters.

Co-authored-by: Mattias Axelsson <mattiaax@axis.com>
  • Loading branch information
github-actions[bot] and killenheladagen authored May 6, 2024
1 parent 44ae684 commit 4205535
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions app/postinstallscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4205535

Please sign in to comment.