From: Med Date: Sat, 9 Sep 2023 15:44:54 +0000 (-0400) Subject: Update entrypoint.sh X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=39c740eaf340750feed0d1ad601749641e1904bf;p=flatnotes.git Update entrypoint.sh Added a check to verify is the .sh is starting with a user set by docker, if it is, it skip the permission setup and gosu. If not, it does it's old behaviors. Also re-introduced the PORT environment variable. Not everyone will run that program on docker, and conflict may arise with others program, putting aside the fact that 8080 is commonly used, begin able to change the PORT without the needed of recompiling everything is useful. --- diff --git a/entrypoint.sh b/entrypoint.sh index c637125..a395419 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,39 +1,49 @@ #!/bin/bash -set -e - -USERNAME=flatnotes - -echo Setting up user and group... -addgroup \ - --gid ${PGID} \ - ${USERNAME} \ - || echo "Group '${PGID}' already exists." - -adduser \ - --disabled-password \ - --gecos "" \ - --uid ${PUID} \ - --gid ${PGID} \ - ${USERNAME} \ - || echo "User '${PUID}' already exists." - -echo Setting file permissions... -chown -R ${PUID}:${PGID} ${FLATNOTES_PATH} - echo "WARNING: Breaking changes introduced in version 3.x:" -echo " - The port flatnotes uses inside the Docker container has been changed to 8080 (previously 80)." -echo " - To accompany the above change, support for the PORT environment variable has been removed." echo " - The note directory inside the Docker container has moved from /app/data to simply /data." -echo Starting flatnotes... -cd ${APP_PATH} -exec gosu ${PUID}:${PGID} \ - python -m \ - uvicorn \ - main:app \ - --app-dir flatnotes \ - --host 0.0.0.0 \ - --port 8080 \ - --proxy-headers \ - --forwarded-allow-ips "*" +if [ `id -u` -eq 0 ] && [ `id -g` -eq 0 ]; then + set -e + + USERNAME=flatnotes + + echo Setting up user and group... + addgroup \ + --gid ${PGID} \ + ${USERNAME} \ + || echo "Group '${PGID}' already exists." + + adduser \ + --disabled-password \ + --gecos "" \ + --uid ${PUID} \ + --gid ${PGID} \ + ${USERNAME} \ + || echo "User '${PUID}' already exists." + + echo Setting file permissions... + chown -R ${PUID}:${PGID} ${FLATNOTES_PATH} + + echo Starting flatnotes... + cd ${APP_PATH} + exec gosu ${PUID}:${PGID} \ + python -m \ + uvicorn \ + main:app \ + --app-dir flatnotes \ + --host 0.0.0.0 \ + --port ${PORT} \ + --proxy-headers \ + --forwarded-allow-ips "*" +else + echo "A user was set by docker, skipping permissions setup." + exec python -m \ + uvicorn \ + main:app \ + --app-dir flatnotes \ + --host 0.0.0.0 \ + --port ${PORT} \ + --proxy-headers \ + --forwarded-allow-ips "*" +fi