From 38b91375ebeb9dc3790d45e15589dbdc469428fd Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 2 Nov 2022 11:54:18 +0100 Subject: [PATCH] Create default user https://github.com/alexbelgium/hassio-addons/issues/528 --- .../rootfs/etc/cont-init.d/99-run.sh | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/paperless_ngx/rootfs/etc/cont-init.d/99-run.sh b/paperless_ngx/rootfs/etc/cont-init.d/99-run.sh index 1846c4d18..02fb35864 100644 --- a/paperless_ngx/rootfs/etc/cont-init.d/99-run.sh +++ b/paperless_ngx/rootfs/etc/cont-init.d/99-run.sh @@ -1,11 +1,37 @@ #!/usr/bin/with-contenv bashio # shellcheck shell=bash -# Staring redis +################# +# Staring redis # +################# exec redis-server & bashio::log.info "Starting redis" -# Avoid overcommit memory +########################### +# Avoid overcommit memory # +########################### bashio::log.info "Avoid overcommit memory" sysctl vm.overcommit_memory=1 +############################### +# Create user if not existing # +############################### +# Origin : https://github.com/linuxserver/docker-paperless-ngx/blob/main/root/etc/cont-init.d/99-migrations +bashio::log.info "Creating default user" +cat << EOF | python3 /app/paperless/src/manage.py shell +from django.contrib.auth import get_user_model + +# see ref. below +UserModel = get_user_model() + +if len(UserModel.objects.all()) == 1: + print("Creating new user") + user = UserModel.objects.create_user('admin', password='admin') + user.is_superuser = True + user.is_staff = True + user.save() +EOF + +######### +# Start # +######### bashio::log.info "Initial username and password are admin. Please change in the administration panel of the webUI after login."