113 lines
4.4 KiB
Bash
113 lines
4.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Add pandora repository
|
|
echo "deb http://ppa.launchpad.net/j/pandora/ubuntu zesty main" > /etc/apt/sources.list.d/pandora.list
|
|
apt-key add - <<EOF
|
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
|
Version: GnuPG v1
|
|
|
|
mI0ESXYhEgEEALl9jDTdmgpApPbjN+7b85dC92HisPUp56ifEkKJOBj0X5HhRqxs
|
|
Wjx/zlP4/XJGrHnxJyrdPxjSwAXz7bNdeggkN4JWdusTkr5GOXvggQnng0X7f/rX
|
|
oJwoEGtYOCODLPs6PC0qjh5yPzJVeiRsKUOZ7YVNnwNwdfS4D8RZvtCrABEBAAG0
|
|
FExhdW5jaHBhZCBQUEEgZm9yIGpeiLYEEwECACAFAkl2IRICGwMGCwkIBwMCBBUC
|
|
CAMEFgIDAQIeAQIXgAAKCRAohRM8AZde82FfA/9OB/64/YLaCpizHZ8f6DK3rGgF
|
|
e6mX3rFK8yOKGGL06316VhDzfzMiZSauUZ0t+lKHR/KZYeSaFwEoUoblTG/s4IIo
|
|
9aBMHWhVXJW6eifKUmTGqEn2/0UxoWQq2C3F6njMkCaP+ALOD5uzaSYGdjqAUAwS
|
|
pAAGSEQ4uz6bYSeM4Q==
|
|
=SM2a
|
|
-----END PGP PUBLIC KEY BLOCK-----
|
|
EOF
|
|
|
|
# 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
|
|
|
|
# Clone git repositories
|
|
git clone --depth 1 https://git.0x2620.org/pandora.git /srv/pandora
|
|
git clone --depth 1 https://git.0x2620.org/oxjs.git /srv/pandora/static/oxjs
|
|
git clone --depth 1 https://git.0x2620.org/oxtimelines.git /srv/pandora/src/oxtimelines
|
|
git clone --depth 1 https://git.0x2620.org/python-ox.git /srv/pandora/src/python-ox
|
|
|
|
# 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
|
|
cd /srv/pandora/src/python-ox && /srv/pandora/bin/python setup.py develop
|
|
/srv/pandora/bin/pip install -r /srv/pandora/requirements.txt
|
|
|
|
# Create PostgreSQL user and database
|
|
export PANDORA_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
|
|
cat <<EOF >/tmp/pandora-createdb.sql
|
|
CREATE ROLE pandora NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${PANDORA_PWD}';
|
|
CREATE DATABASE pandora;
|
|
REVOKE ALL ON DATABASE pandora FROM public;
|
|
ALTER DATABASE pandora OWNER TO pandora;
|
|
\c pandora;
|
|
CREATE EXTENSION pg_trgm;
|
|
EOF
|
|
sudo -u postgres psql -f /tmp/pandora-createdb.sql
|
|
rm -f /tmp/pandora-createdb.sql
|
|
|
|
# Configure RabbitMQ
|
|
export PANDORA_RABBIT_PWD=$(head -c 260 /dev/urandom | tr -cd '[:alnum:]' | head -c 26)
|
|
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
|
|
cp /srv/pandora/pandora/config.pandora.jsonc /srv/pandora/pandora/config.jsonc
|
|
sed 's/127.0.0.1/0.0.0.0/' /srv/pandora/pandora/gunicorn_config.py.in >/srv/pandora/pandora/gunicorn_config.py
|
|
|
|
cat <<EOF >/srv/pandora/pandora/local_settings.py
|
|
DATABASES = {
|
|
'default': {
|
|
'NAME': 'pandora',
|
|
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
|
'USER': 'pandora',
|
|
'PASSWORD': '${PANDORA_PWD}',
|
|
}
|
|
}
|
|
DB_GIN_TRGM = True
|
|
BROKER_URL = '${PANDORA_BROKER_URL}'
|
|
|
|
XACCELREDIRECT = True
|
|
MEDIA_URL = '/pandora/data/'
|
|
STATIC_URL = '/pandora/static/'
|
|
|
|
WEBSOCKET = True
|
|
WEBSOCKET_ADDRESS = "0.0.0.0"
|
|
|
|
DEBUG = False
|
|
TEMPLATE_DEBUG = DEBUG
|
|
JSON_DEBUG = False
|
|
EOF
|
|
|
|
sed -i "s|url(r'^|url(r'^pandora/|g" /srv/pandora/pandora/urls.py
|
|
sed -i 's|href="/|href="/pandora/|g' /srv/pandora/pandora/templates/*.html
|
|
sed -i 's|src="/|src="/pandora/|g' /srv/pandora/pandora/templates/*.html
|
|
sed -i "s|build_absolute_uri('/|build_absolute_uri('/pandora/|g" ./item/views.py ./item/tasks.py ./archive/views.py ./user/views.py ./app/views.py ./text/views.py
|
|
|
|
# Create OS user
|
|
adduser --system --group --home /srv/pandora --shell /bin/false pandora
|
|
chown -R pandora:pandora /srv/pandora
|
|
|
|
# Populate database
|
|
sudo -u pandora /srv/pandora/pandora/manage.py init_db
|
|
|
|
# Install systemd services
|
|
cp /srv/pandora/etc/systemd/system/*.service /etc/systemd/system/
|
|
cp /srv/pandora/etc/tmpfiles.d/pandora.conf /etc/tmpfiles.d/
|
|
systemd-tmpfiles --create /etc/tmpfiles.d/pandora.conf
|
|
systemctl daemon-reload
|
|
|
|
# Start services
|
|
for SERVICE in "pandora pandora-tasks pandora-encoding pandora-cron pandora-websocketd"; do
|
|
systemctl enable ${SERVICE}
|
|
systemctl start ${SERVICE}
|
|
done
|
|
|
|
# TODO: LXC
|
|
# TODO: nginx configuration
|