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
|
2023-11-29 12:47:18 +00:00
|
|
|
if [ -z "$PUID" ] && [ "$UID" == "0" ] ; 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-29 12:47:18 +00:00
|
|
|
if [ "$PUID" == "0" ] || [ "$UID" != "0" ]; then
|
|
|
|
# Will run SilverBullet as default user
|
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
|
2023-11-30 14:19:08 +00:00
|
|
|
getent group silverbullet &> /dev/null || groupadd -g $PGID silverbullet
|
2023-11-30 14:12:16 +00:00
|
|
|
id -u silverbullet &> /dev/null || useradd -M -u $PUID -g $PGID silverbullet
|
2023-11-27 14:44:39 +00:00
|
|
|
# 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
|
|
|
|