2020-12-15 22:33:43 +01:00
#!/bin/bash
2021-10-14 09:24:07 +02:00
# should be run as root and only on Ubuntu 18/20, Debian 10/11 (Buster/Bullseye) versions!
2020-12-15 22:33:43 +01:00
echo "Welcome to the MediacMS installation!" ;
if [ ` id -u` -ne 0 ]
then echo "Please run as root"
exit
fi
while true; do
read -p "
This script will attempt to perform a system update, install required dependencies, install and configure PostgreSQL, NGINX, Redis and a few other utilities.
It is expected to run on a new system **with no running instances of any these services**. Make sure you check the script before you continue . Then enter yes or no
" yn
case $yn in
[ Yy] * ) echo "OK!" ; break; ;
[ Nn] * ) echo "Have a great day" ; exit; ;
* ) echo "Please answer yes or no." ; ;
esac
done
2021-08-01 14:16:13 +02:00
osVersion = $( lsb_release -d)
2021-10-14 09:24:07 +02:00
if [ [ $osVersion = = *"Ubuntu 20" * ] ] || [ [ $osVersion = = *"Ubuntu 18" * ] ] || [ [ $osVersion = = *"buster" * ] ] || [ [ $osVersion = = *"bullseye" * ] ] ; then
2020-12-15 22:33:43 +01:00
echo 'Performing system update and dependency installation, this will take a few minutes'
2021-08-01 14:16:13 +02:00
apt-get update && apt-get -y upgrade && apt-get install python3-venv python3-dev virtualenv redis-server postgresql nginx git gcc vim unzip imagemagick python3-certbot-nginx certbot wget xz-utils -y
2020-12-15 22:33:43 +01:00
else
echo "This script is tested for Ubuntu 18 and 20 versions only, if you want to try MediaCMS on another system you have to perform the manual installation"
2021-08-01 14:16:13 +02:00
exit
2020-12-15 22:33:43 +01:00
fi
2021-08-01 14:16:13 +02:00
# install ffmpeg
echo "Downloading and installing ffmpeg"
wget -q https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
mkdir -p tmp
tar -xf ffmpeg-release-amd64-static.tar.xz --strip-components 1 -C tmp
cp -v tmp/{ ffmpeg,ffprobe,qt-faststart} /usr/local/bin
rm -rf tmp ffmpeg-release-amd64-static.tar.xz
echo "ffmpeg installed to /usr/local/bin"
2020-12-15 22:33:43 +01:00
read -p "Enter portal URL, or press enter for localhost : " FRONTEND_HOST
read -p "Enter portal name, or press enter for 'MediaCMS : " PORTAL_NAME
[ -z " $PORTAL_NAME " ] && PORTAL_NAME = 'MediaCMS'
[ -z " $FRONTEND_HOST " ] && FRONTEND_HOST = 'localhost'
echo 'Creating database to be used in MediaCMS'
su -c "psql -c \"CREATE DATABASE mediacms\"" postgres
su -c "psql -c \"CREATE USER mediacms WITH ENCRYPTED PASSWORD 'mediacms'\"" postgres
su -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE mediacms TO mediacms\"" postgres
echo 'Creating python virtualenv on /home/mediacms.io'
cd /home/mediacms.io
virtualenv . --python= python3
source /home/mediacms.io/bin/activate
cd mediacms
pip install -r requirements.txt
SECRET_KEY = ` python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())' `
# remove http or https prefix
FRONTEND_HOST = ` echo " $FRONTEND_HOST " | sed -r 's/http:\/\///g' `
FRONTEND_HOST = ` echo " $FRONTEND_HOST " | sed -r 's/https:\/\///g' `
2021-01-12 19:21:53 +01:00
sed -i s/localhost/$FRONTEND_HOST /g deploy/local_install/mediacms.io
2020-12-15 22:33:43 +01:00
2021-02-17 21:32:30 +01:00
FRONTEND_HOST_HTTP_PREFIX = 'http://' $FRONTEND_HOST
2020-12-15 22:33:43 +01:00
2021-02-17 21:32:30 +01:00
echo 'FRONTEND_HOST=' \' " $FRONTEND_HOST_HTTP_PREFIX " \' >> cms/local_settings.py
2020-12-15 22:33:43 +01:00
echo 'PORTAL_NAME=' \' " $PORTAL_NAME " \' >> cms/local_settings.py
echo "SSL_FRONTEND_HOST = FRONTEND_HOST.replace('http', 'https')" >> cms/local_settings.py
echo 'SECRET_KEY=' \' " $SECRET_KEY " \' >> cms/local_settings.py
2021-01-12 19:21:53 +01:00
echo "LOCAL_INSTALL = True" >> cms/local_settings.py
2020-12-15 22:33:43 +01:00
mkdir logs
mkdir pids
python manage.py migrate
python manage.py loaddata fixtures/encoding_profiles.json
python manage.py loaddata fixtures/categories.json
python manage.py collectstatic --noinput
ADMIN_PASS = ` python -c "import secrets;chars = 'abcdefghijklmnopqrstuvwxyz0123456789';print(''.join(secrets.choice(chars) for i in range(10)))" `
echo " from users.models import User; User.objects.create_superuser('admin', 'admin@example.com', ' $ADMIN_PASS ') " | python manage.py shell
echo " from django.contrib.sites.models import Site; Site.objects.update(name=' $FRONTEND_HOST ', domain=' $FRONTEND_HOST ') " | python manage.py shell
chown -R www-data. /home/mediacms.io/
2021-01-12 19:21:53 +01:00
cp deploy/local_install/celery_long.service /etc/systemd/system/celery_long.service && systemctl enable celery_long && systemctl start celery_long
cp deploy/local_install/celery_short.service /etc/systemd/system/celery_short.service && systemctl enable celery_short && systemctl start celery_short
cp deploy/local_install/celery_beat.service /etc/systemd/system/celery_beat.service && systemctl enable celery_beat && systemctl start celery_beat
cp deploy/local_install/mediacms.service /etc/systemd/system/mediacms.service && systemctl enable mediacms.service && systemctl start mediacms.service
2020-12-15 22:33:43 +01:00
mkdir -p /etc/letsencrypt/live/mediacms.io/
mkdir -p /etc/letsencrypt/live/$FRONTEND_HOST
2021-06-18 15:56:45 +02:00
mkdir -p /etc/nginx/sites-enabled
mkdir -p /etc/nginx/sites-available
mkdir -p /etc/nginx/dhparams/
rm -rf /etc/nginx/conf.d/default.conf
rm -rf /etc/nginx/sites-enabled/default
2021-01-12 19:21:53 +01:00
cp deploy/local_install/mediacms.io_fullchain.pem /etc/letsencrypt/live/$FRONTEND_HOST /fullchain.pem
cp deploy/local_install/mediacms.io_privkey.pem /etc/letsencrypt/live/$FRONTEND_HOST /privkey.pem
2021-06-18 15:56:45 +02:00
cp deploy/local_install/dhparams.pem /etc/nginx/dhparams/dhparams.pem
cp deploy/local_install/mediacms.io /etc/nginx/sites-available/mediacms.io
ln -s /etc/nginx/sites-available/mediacms.io /etc/nginx/sites-enabled/mediacms.io
2021-01-12 19:21:53 +01:00
cp deploy/local_install/uwsgi_params /etc/nginx/sites-enabled/uwsgi_params
cp deploy/local_install/nginx.conf /etc/nginx/
2020-12-15 22:33:43 +01:00
systemctl stop nginx
systemctl start nginx
# attempt to get a valid certificate for specified domain
if [ " $FRONTEND_HOST " != "localhost" ] ; then
echo 'attempt to get a valid certificate for specified url $FRONTEND_HOST'
certbot --nginx -n --agree-tos --register-unsafely-without-email -d $FRONTEND_HOST
certbot --nginx -n --agree-tos --register-unsafely-without-email -d $FRONTEND_HOST
# unfortunately for some reason it needs to be run two times in order to create the entries
# and directory structure!!!
systemctl restart nginx
else
echo "will not call certbot utility to update ssl certificate for url 'localhost', using default ssl certificate"
fi
2021-06-18 15:56:45 +02:00
# Generate individual DH params
if [ " $FRONTEND_HOST " != "localhost" ] ; then
# Only generate new DH params when using "real" certificates.
openssl dhparam -out /etc/nginx/dhparams/dhparams.pem 4096
systemctl restart nginx
else
echo "will not generate new DH params for url 'localhost', using default DH params"
fi
2020-12-15 22:33:43 +01:00
# Bento4 utility installation, for HLS
cd /home/mediacms.io/mediacms
2021-03-22 19:04:12 +01:00
wget http://zebulon.bok.net/Bento4/binaries/Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip
unzip Bento4-SDK-1-6-0-637.x86_64-unknown-linux.zip
2020-12-15 22:33:43 +01:00
mkdir /home/mediacms.io/mediacms/media_files/hls
# last, set default owner
chown -R www-data. /home/mediacms.io/
echo 'MediaCMS installation completed, open browser on http://' " $FRONTEND_HOST " ' and login with user admin and password ' " $ADMIN_PASS " ''