Use ASF user account inside docker

This commit is contained in:
Archi
2021-10-17 16:19:07 +02:00
parent f022822e94
commit 618ff781eb
9 changed files with 133 additions and 23 deletions

View File

@@ -63,6 +63,15 @@ for ARG in "$@"; do
fi
done
BINARY_PREFIX=""
if [ -n "${ASF_USER-}" ] && [ "$(id -u)" -eq 0 ] && id -u "$ASF_USER" >/dev/null 2>&1; then
# Fix permissions first to ensure ASF has read/write access to the directory specified by --path and its own
chown -hR "${ASF_USER}:${ASF_USER}" . "$SCRIPT_DIR"
BINARY_PREFIX="su ${ASF_USER} -c"
fi
CONFIG_PATH="$(pwd)/${CONFIG_PATH}"
# Kill underlying ASF process on shell process exit
@@ -71,11 +80,23 @@ trap "trap - TERM && kill -- -$$" INT TERM
while :; do
if [ -f "$CONFIG_PATH" ] && grep -Eq '"Headless":\s+?true' "$CONFIG_PATH"; then
# We're running ASF in headless mode so we don't need STDIN
"$BINARY" $BINARY_ARGS & # Start ASF in the background, trap will work properly due to non-blocking call
wait $! # This will forward dotnet error code, set -e will abort the script if it's non-zero
# Start ASF in the background, trap will work properly due to non-blocking call
if [ -n "$BINARY_PREFIX" ]; then
$BINARY_PREFIX "$BINARY $BINARY_ARGS" &
else
"$BINARY" $BINARY_ARGS &
fi
# This will forward dotnet error code, set -e will abort the script if it's non-zero
wait $!
else
# We're running ASF in non-headless mode, so we need STDIN to be operative
"$BINARY" $BINARY_ARGS # Start ASF in the foreground, trap sadly won't work until process exit
# Start ASF in the foreground, trap won't work until process exit
if [ -n "$BINARY_PREFIX" ]; then
$BINARY_PREFIX "$BINARY $BINARY_ARGS"
else
"$BINARY" $BINARY_ARGS
fi
fi
chmod +x "$SCRIPT_PATH" # If ASF exited by itself, we need to ensure that our script is still set to +x after auto-update