mediagoblin-setup/installer.sh

118 lines
3.9 KiB
Bash
Raw Normal View History

2025-01-10 22:19:31 +00:00
#!/bin/bash
#
# Setting up CMXSL's instance of MediaGoblin
# Source https://docs.mediagoblin.org/en/stable/siteadmin/deploying.html
#
# CMXSL members © - 2024, https://cmxsl.org/
# GPLv3 or later.
#
# NOTE
# - for Debian-basded distros (Trisquel GNU/Linux)
# - in deps, python3-venv depends python3-pip-whl (broken)
# - username and db name are the same: mediagoblin
# (by the moment) RUN IT AT THE ROOT IN HOME!!
echo "Installing MediaGoblin"
# --- Install deps
sudo apt-get update
sudo apt-get install automake git nodejs npm python3-dev \
python3-venv python3-gst-1.0 python3-lxml python3-pil \
nginx-light rabbitmq-server \
postgresql python3-psycopg2
# --- Configure PostgreSQL
sudo --login --user=postgres createuser --no-createdb mediagoblin
sudo --login --user=postgres createdb --encoding=UTF8 --owner=mediagoblin mediagoblin
# --- Drop privileges
# create mediagoblin user
sudo useradd --system --create-home --home-dir /var/lib/mediagoblin \
--group www-data --comment 'GNU MediaGoblin system account' mediagoblin
# create mediagoblin group (to be sure)
sudo groupadd --force mediagoblin
sudo usermod --append --groups mediagoblin mediagoblin
# --- Create MediaGoblin dir
# iocal git repository will be located at: /srv/media.cmxsl.org/mediagoblin/
sudo mkdir --parents /srv/media.cmxsl.org
sudo chown --no-dereference --recursive mediagoblin:www-data /srv/media.cmxsl.org
# --- Install MediaGoblin
# switch to mediagoblin user
sudo su mediagoblin --shell=/bin/bash
cd /srv/media.cmxsl.org
# installing from source
git clone --depth=1 https://git.sr.ht/~mediagoblin/mediagoblin \
--branch stable --recursive
cd mediagoblin
./autogen.sh
./configure
make
# set proper permissions
mkdir --mode=2750 user_dev
# --- Configure
sed -i -e 's/notice@mediagoblin.example.org/admin@cmxsl.org/g' /srv/media.cmxsl.org/mediagoblin/mediagoblin.ini
sed -i '/sql_engine = postgresql:\/\/\/mediagoblin/s/^#//g' /srv/media.cmxsl.org/mediagoblin/mediagoblin.ini
# populate the db with the MediaGoblin data structures
./bin/gmg dbupdate
# create an admin account
./bin/gmg adduser --username chaneque --email admin@cmxsl.org
./bin/gmg makeadmin chaneque
# test the server
# echo "Testing the server. In your browser http://localhost:6543 CTRL-c to exit."
# echo "..."
# ./lazyserver.sh --server-name=broadcast
exit
echo "Deploying MediaGoblin"
# --- Deploy MediaGoblin
sudo ln --symbolic /srv/media.cmxsl.org/nginx.conf /etc/nginx/sites-enabled/mediagoblin.conf
sudo rm --force /etc/nginx/sites-enabled/default
sudo systemctl enable nginx
sudo cp ~/mediagoblin-setup/nginx.conf /srv/media.cmxsl.org/
# quick test
sudo nginx -t
sudo systemctl restart nginx
# test the server
# echo "Testing NGINX. In your browser http://localhost:6543 CTRL-c to exit."
# echo "..."
# sudo su mediagoblin --shell=/bin/bash
# cd /srv/media.cmxsl.org/mediagoblin/
# ./lazyserver.sh --server-name=main
# set permissions in the new directories
sudo chown --no-dereference --recursive mediagoblin:www-data /srv/media.cmxsl.org
sudo find /srv/media.cmxsl.org -type d -exec chmod 755 {} \;
sudo find /srv/media.cmxsl.org -type f -exec chmod 644 {} \;
sudo find /srv/media.cmxsl.org/mediagoblin/user_dev/crypto -type d -exec chmod 750 {} \;
sudo find /srv/media.cmxsl.org/mediagoblin/user_dev/crypto -type f -exec chmod 640 {} \;
sudo find /srv/media.cmxsl.org/mediagoblin/bin -type f -exec chmod 750 {} \;
exit
# --- Run MediaGoblin as a system services
sudo mkdir --parents /var/log/mediagoblin
sudo chown --no-dereference --recursive mediagoblin:mediagoblin /var/log/mediagoblin
sudo cp ~/mediagoblin-setup/*.service /etc/systemd/system/
# enable the project processes to start at boot
sudo systemctl enable mediagoblin-paster.service
sudo systemctl enable mediagoblin-celeryd.service
# start these processes for the current session
sudo systemctl start mediagoblin-paster.service
sudo systemctl start mediagoblin-celeryd.service
echo "MediaGoblin installed!!!"