From c0d81430d942a7dd2cf407c0afbbb0271eb97574 Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Wed, 26 Mar 2025 13:19:19 -0700 Subject: [PATCH] Special case for creating a super user to make it a little cleaner --- docker/compose/docker-compose.mariadb-tika.yml | 2 +- docker/compose/docker-compose.mariadb.yml | 2 +- docker/compose/docker-compose.postgres-tika.yml | 2 +- docker/compose/docker-compose.postgres.yml | 2 +- docker/compose/docker-compose.sqlite-tika.yml | 2 +- docker/compose/docker-compose.sqlite.yml | 2 +- docker/install_management_commands.sh | 5 +++-- docker/rootfs/usr/local/bin/createsuperuser | 14 ++++++++++++++ docs/setup.md | 4 ++-- install-paperless-ngx.sh | 2 +- 10 files changed, 26 insertions(+), 11 deletions(-) create mode 100755 docker/rootfs/usr/local/bin/createsuperuser diff --git a/docker/compose/docker-compose.mariadb-tika.yml b/docker/compose/docker-compose.mariadb-tika.yml index 434c72b0a..845681cc8 100644 --- a/docker/compose/docker-compose.mariadb-tika.yml +++ b/docker/compose/docker-compose.mariadb-tika.yml @@ -26,7 +26,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the diff --git a/docker/compose/docker-compose.mariadb.yml b/docker/compose/docker-compose.mariadb.yml index 9a32368d4..9b8d57f4a 100644 --- a/docker/compose/docker-compose.mariadb.yml +++ b/docker/compose/docker-compose.mariadb.yml @@ -22,7 +22,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the # documentation. diff --git a/docker/compose/docker-compose.postgres-tika.yml b/docker/compose/docker-compose.postgres-tika.yml index 6c0803337..dd81bd5b9 100644 --- a/docker/compose/docker-compose.postgres-tika.yml +++ b/docker/compose/docker-compose.postgres-tika.yml @@ -26,7 +26,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the # documentation. diff --git a/docker/compose/docker-compose.postgres.yml b/docker/compose/docker-compose.postgres.yml index fcf6c322b..8212f8514 100644 --- a/docker/compose/docker-compose.postgres.yml +++ b/docker/compose/docker-compose.postgres.yml @@ -22,7 +22,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the # documentation. diff --git a/docker/compose/docker-compose.sqlite-tika.yml b/docker/compose/docker-compose.sqlite-tika.yml index a096793a3..d2a74b696 100644 --- a/docker/compose/docker-compose.sqlite-tika.yml +++ b/docker/compose/docker-compose.sqlite-tika.yml @@ -26,7 +26,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the # documentation. diff --git a/docker/compose/docker-compose.sqlite.yml b/docker/compose/docker-compose.sqlite.yml index 1a9fd1a03..db63633fe 100644 --- a/docker/compose/docker-compose.sqlite.yml +++ b/docker/compose/docker-compose.sqlite.yml @@ -19,7 +19,7 @@ # - Run 'docker compose pull'. # - Run 'docker compose up -d'. # - Wait until the webserver has completed startup -# - Run 'docker compose exec webserver ./manage.py createsuperuser' to create a user. +# - Run 'docker compose exec webserver createsuperuser' to create a user. # # For more extensive installation and update instructions, refer to the # documentation. diff --git a/docker/install_management_commands.sh b/docker/install_management_commands.sh index c7c65bfbb..17dae68a2 100755 --- a/docker/install_management_commands.sh +++ b/docker/install_management_commands.sh @@ -18,9 +18,10 @@ for command in decrypt_documents \ document_fuzzy_match \ manage_superuser \ convert_mariadb_uuid \ - prune_audit_logs; + prune_audit_logs \ + createsuperuser; do echo "installing $command..." sed "s/management_command/$command/g" management_script.sh >"$PWD/rootfs/usr/local/bin/$command" - chmod +x "$PWD/rootfs/usr/local/bin/$command" + chmod u=rwx,g=rwx,o=rx "$PWD/rootfs/usr/local/bin/$command" done diff --git a/docker/rootfs/usr/local/bin/createsuperuser b/docker/rootfs/usr/local/bin/createsuperuser new file mode 100755 index 000000000..f931952ba --- /dev/null +++ b/docker/rootfs/usr/local/bin/createsuperuser @@ -0,0 +1,14 @@ +#!/command/with-contenv /usr/bin/bash +# shellcheck shell=bash + +set -e + +cd "${PAPERLESS_SRC_DIR}" + +if [[ $(id -u) == 0 ]]; then + s6-setuidgid paperless python3 manage.py createsuperuser "$@" +elif [[ $(id -un) == "paperless" ]]; then + python3 manage.py createsuperuser "$@" +else + echo "Unknown user." +fi diff --git a/docs/setup.md b/docs/setup.md index 6190b79fd..d132d9033 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -143,13 +143,13 @@ account. The script essentially automatically performs the steps described in [D execute the following command: ```shell-session - docker compose exec webserver ./manage.py createsuperuser + docker compose exec webserver createsuperuser ``` or using docker exec from within the container: ```shell-session - ./manage.py createsuperuser + createsuperuser ``` This will guide you through the superuser setup. diff --git a/install-paperless-ngx.sh b/install-paperless-ngx.sh index d901353a3..3977cece9 100755 --- a/install-paperless-ngx.sh +++ b/install-paperless-ngx.sh @@ -402,6 +402,6 @@ if [ "$DATABASE_BACKEND" == "postgres" ] || [ "$DATABASE_BACKEND" == "mariadb" ] docker compose stop fi -docker compose run --rm -e DJANGO_SUPERUSER_PASSWORD="$PASSWORD" webserver ./manage.py createsuperuser --noinput --username "$USERNAME" --email "$EMAIL" +docker compose run --rm -e DJANGO_SUPERUSER_PASSWORD="$PASSWORD" webserver createsuperuser --noinput --username "$USERNAME" --email "$EMAIL" docker compose up --detach