From 929f1afd69f910d00be1dd7331b6da7ca5f587b4 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Wed, 29 Nov 2017 22:21:06 +0100 Subject: [PATCH] Install Pandora in a less ugly way - Don't customize manage.py - Use pip -e instead of manual call - Fix deprecation warning --- pandora.sh | 9 +++++---- pandora/srv/pandora/pandora/local_settings.py | 1 - .../user/management/commands/createadmin.py | 17 ----------------- pandora/tmp/pandora-adminpwd.sql | 3 +++ 4 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 pandora/srv/pandora/pandora/user/management/commands/createadmin.py create mode 100644 pandora/tmp/pandora-adminpwd.sql diff --git a/pandora.sh b/pandora.sh index 7225709..3754e85 100755 --- a/pandora.sh +++ b/pandora.sh @@ -24,7 +24,7 @@ cp ${SOURCE_DIR}/pandora/srv/pandora/static/oxjs/source/UI/json/locale.cs.json / # Create Python virtualenv virtualenv --system-site-packages -p /usr/bin/python3 /srv/pandora -cd /srv/pandora/src/oxtimelines && /srv/pandora/bin/python setup.py develop +/srv/pandora/bin/pip install -e /srv/pandora/src/oxtimelines /srv/pandora/bin/pip install -r /srv/pandora/requirements.txt # Create PostgreSQL user and database @@ -62,9 +62,10 @@ sudo -u pandora /srv/pandora/pandora/manage.py init_db export PANDORA_ADMIN_USER=admin export PANDORA_ADMIN_EMAIL=admin@example.com export PANDORA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) -cp ${SOURCE_DIR}/pandora/srv/pandora/pandora/user/management/commands/createadmin.py /srv/pandora/pandora/user/management/commands/createadmin.py -sudo -u pandora /srv/pandora/pandora/manage.py createadmin --username "${PANDORA_ADMIN_USER}" --email "${PANDORA_ADMIN_EMAIL}" --password "${PANDORA_ADMIN_PWD}" -rm -f /srv/pandora/pandora/user/management/commands/createadmin.py +export PANDORA_ADMIN_HASH=$(cd /srv/pandora && DJANGO_SETTINGS_MODULE=pandora.settings /srv/pandora/bin/python -c "from django.contrib.auth.hashers import make_password; print(make_password('${PANDORA_ADMIN_PWD}'))") +envsubst <${SOURCE_DIR}/pandora/tmp/pandora-adminpwd.sql >/tmp/pandora-adminpwd.sql +sudo -u postgres psql -f /tmp/pandora-adminpwd.sql pandora +rm -f /tmp/pandora-adminpwd.sql # Create nginx site definition cp ${SOURCE_DIR}/pandora/etc/nginx/sites-available/pandora /etc/nginx/sites-available/pandora diff --git a/pandora/srv/pandora/pandora/local_settings.py b/pandora/srv/pandora/pandora/local_settings.py index 8f42162..fb4f92e 100644 --- a/pandora/srv/pandora/pandora/local_settings.py +++ b/pandora/srv/pandora/pandora/local_settings.py @@ -13,5 +13,4 @@ XACCELREDIRECT = True GOOGLE_API_KEY = 'AIzaSyBvIF3D550tlpL6o1xRrDurGo-81VhHlOw' DEBUG = True -TEMPLATE_DEBUG = DEBUG JSON_DEBUG = DEBUG diff --git a/pandora/srv/pandora/pandora/user/management/commands/createadmin.py b/pandora/srv/pandora/pandora/user/management/commands/createadmin.py deleted file mode 100644 index 5535775..0000000 --- a/pandora/srv/pandora/pandora/user/management/commands/createadmin.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.contrib.auth import get_user_model -from django.core.management.base import BaseCommand -from django.db import DEFAULT_DB_ALIAS - -class Command(BaseCommand): - def add_arguments(self, parser): - parser.add_argument('--username', help='Specifies the login for the superuser.') - parser.add_argument('--email', help='Specifies the email for the superuser.') - parser.add_argument('--password', help='Specifies the password for the superuser.') - - def handle(self, *args, **options): - user_data = { - 'username': options['username'], - 'email': options['email'], - 'password': options['password'] - } - get_user_model()._default_manager.db_manager(DEFAULT_DB_ALIAS).create_superuser(**user_data) diff --git a/pandora/tmp/pandora-adminpwd.sql b/pandora/tmp/pandora-adminpwd.sql new file mode 100644 index 0000000..830d3e0 --- /dev/null +++ b/pandora/tmp/pandora-adminpwd.sql @@ -0,0 +1,3 @@ +INSERT INTO auth_user (id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined) VALUES (nextval('auth_user_id_seq'), '${PANDORA_ADMIN_HASH}', NULL, true, '${PANDORA_ADMIN_USER}', '', '', '${PANDORA_ADMIN_EMAIL}', true, true, now()); +INSERT INTO user_userprofile (id, reset_code, level, files_updated, newsletter, ui, preferences, notes, user_id) VALUES +(nextval('user_userprofile_id_seq'), NULL, 3, now(), true, '{}', '{}', '', 1);