Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up post-install script #160

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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