2023-11-27 14:44:39 +00:00
|
|
|
#!/bin/bash -e
|
2023-11-27 14:01:02 +00:00
|
|
|
|
2023-11-27 14:44:39 +00:00
|
|
|
# Check if UID and GID are passed as environment variables, if not, extract from the space folder owner
|
|
|
|
if [ -z "$PUID" ]; then
|
2023-11-27 14:01:02 +00:00
|
|
|
# Get the UID of the folder owner
|
2023-11-27 14:44:39 +00:00
|
|
|
PUID=$(stat -c "%u" "$SB_FOLDER")
|
|
|
|
echo "Will run SilverBullet with UID $PUID, inferred from the owner of $SB_FOLDER (set PUID environment variable to override)"
|
2023-11-27 14:01:02 +00:00
|
|
|
fi
|
2023-11-27 14:44:39 +00:00
|
|
|
if [ -z "$PGID" ]; then
|
2023-11-27 14:01:02 +00:00
|
|
|
# Get the GID of the folder owner
|
2023-11-27 14:44:39 +00:00
|
|
|
PGID=$(stat -c "%g" "$SB_FOLDER")
|
2023-11-27 14:01:02 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-27 14:44:39 +00:00
|
|
|
if [ "$PUID" -eq "0" ]; then
|
|
|
|
echo "Will run SilverBullet as root"
|
2023-11-27 14:01:02 +00:00
|
|
|
deno run -A --unstable /silverbullet.js $@
|
|
|
|
else
|
2023-11-27 14:44:39 +00:00
|
|
|
# Create silverbullet user and group ad-hoc mapped to PUID and PGID
|
|
|
|
groupadd -g $PGID silverbullet
|
|
|
|
useradd -M -u $PUID -g $PGID silverbullet
|
|
|
|
# And make sure /deno-dir (Deno cache) is accessible
|
|
|
|
chown -R $PUID:$PGID /deno-dir
|
|
|
|
# And run via su as the newly mapped 'silverbullet' user
|
|
|
|
args="$@"
|
|
|
|
su silverbullet -s /bin/bash -c "deno run -A --unstable /silverbullet.js $args"
|
2023-11-27 14:01:02 +00:00
|
|
|
fi
|
2023-11-27 14:44:39 +00:00
|
|
|
|