Update entrypoint.sh
authorMed <redacted>
Sat, 9 Sep 2023 15:44:54 +0000 (11:44 -0400)
committerGitHub <redacted>
Sat, 9 Sep 2023 15:44:54 +0000 (11:44 -0400)
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.

entrypoint.sh

index c637125b5f298c77808de17e277cc6bb31e7b99e..a3954191b033bfb6b8c802f88dc4aff72b41c2fb 100644 (file)
@@ -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
git clone https://git.99rst.org/PROJECT