Create Pandora admin account via Django management script

This commit is contained in:
Disassembler 2017-09-17 22:09:56 +02:00
parent 5614f66a1a
commit a47d649f71
2 changed files with 28 additions and 4 deletions

View File

@ -8,8 +8,7 @@ apt-key add ${SOURCE_DIR}/pandora/pandora.gpg
# Install packages
apt-get -y update
apt-get -y --no-install-recommends install gpac poppler-utils rabbitmq-server python3-setuptools python3-pip virtualenv python3-virtualenv python3-pil python3-numpy python3-psycopg2 python3-pyinotify python3-simplejson python3-lxml python3-html5lib python3-ox oxframe ffmpeg mkvtoolnix youtube-dl
# python3-dev imagemagick
apt-get -y --no-install-recommends install gpac ffmpeg mkvtoolnix oxframe poppler-utils python3-html5lib python3-lxml python3-numpy python3-ox python3-pil python3-pip python3-psycopg2 python3-pyinotify python3-setuptools python3-simplejson python3-virtualenv rabbitmq-server virtualenv youtube-dl
# Clone git repositories
git clone --depth 1 https://git.0x2620.org/pandora.git /srv/pandora
@ -38,10 +37,10 @@ rm -f /tmp/pandora-createdb.sql
# Configure RabbitMQ
export PANDORA_RABBIT_PWD=$(head -c 18 /dev/urandom | base64)
export PANDORA_BROKER_URL="amqp://pandora:${PANDORA_RABBIT_PWD}@localhost:5672//pandora"
rabbitmqctl add_user pandora ${PANDORA_RABBIT_PWD}
rabbitmqctl add_vhost /pandora
rabbitmqctl set_permissions -p /pandora pandora ".*" ".*" ".*"
export PANDORA_BROKER_URL="amqp://pandora:${PANDORA_RABBIT_PWD}@localhost:5672//pandora"
# Configure Pandora
mkdir /srv/pandora/data
@ -56,6 +55,14 @@ chown -R pandora:pandora /srv/pandora
# Populate database
sudo -u pandora /srv/pandora/pandora/manage.py init_db
# Create admin account
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
# Create nginx site definition
cp ${SOURCE_DIR}/pandora/etc/nginx/sites-available/pandora /etc/nginx/sites-available/pandora
ln -s /etc/nginx/sites-available/pandora /etc/nginx/sites-enabled/pandora
@ -66,4 +73,4 @@ ln -s /etc/nginx/sites-available/pandora /etc/nginx/sites-enabled/pandora
systemctl restart nginx
# Add portal application definition
${SOURCE_DIR}/basic/portal-app-manager.py pandora "https://{host}:8001/"
${SOURCE_DIR}/basic/portal-app-manager.py pandora "https://{host}:8001/" "${PANDORA_ADMIN_USER}" "${PANDORA_ADMIN_PWD}"

View File

@ -0,0 +1,17 @@
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)