#!/bin/bash toolName="Mayan EDMS" toolVersion="3.3.15" toolRoot="/opt/mayan-edms" toolMediaFolder="/opt/mayan-edms/media" # Needed for different steps postgresDb="" postgresUser="" postgresPass="" step_1_info() { echo "Install libreoffice without gui"; } step_1_alias() { ALIAS="install"; } step_1() { exe apt update exe apt --no-install-recommends install libreoffice -y } step_2_info() { echo "Get $toolName binary dependencies"; } step_2() { exe apt install libimage-exiftool-perl g++ gcc ghostscript gnupg1 graphviz libfuse2 \ libjpeg-dev libmagic1 libpq-dev libpng-dev libtiff-dev \ poppler-utils postgresql python3-dev python3-venv python3-virtualenv python3-pip redis-server sane-utils supervisor tesseract-ocr tesseract-ocr-deu zlib1g-dev -y endReturn -o $? "Binary dependencies installation failed" exe systemctl enable supervisor exe systemctl stop supervisor } step_3_info() { echo "Create virtual environment"; } step_3() { exe adduser --disabled-password --disabled-login --no-create-home --gecos "" mayan exe usermod -a -G users mayan exe python3 -m venv ${toolRoot} endReturn -o $? "Creating virtual environment failed" exe chown -R mayan:mayan ${toolRoot} } step_4_info() { echo "Create postgres database for $toolName"; } step_4_alias() { ALIAS="createdb"; } step_4() { readDatabaseInfos exe cd ~postgres exe sudo -u postgres psql -c "CREATE USER ${postgresUser} WITH password '${postgresPass}';" # -O owner : Specifies the database user who will own the new database. exe sudo -u postgres createdb -O ${postgresUser} ${postgresDb} } step_5_info() { echo "Install $toolName"; } step_5() { # upgrade pip first step upgradepip exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir mayan-edms endReturn -o $? "pip install for $toolName failed" exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir psycopg2==2.8.3 redis==3.2.1 endReturn -o $? } step_6_info() { echo "Supervisord configuration for $toolName"; } step_6_alias() { ALIAS="supervisorconf"; } step_6() { addConf -c "" "$supervisordConfLoc" toolScript "platformtemplate supervisord > ${supervisordConfLoc}" } supervisordConfLoc="/etc/supervisor/conf.d/mayan.conf" step_7_info() { echo "Redis configuration file"; } step_7() { addConf -a "$redisConf" "$redisConfLoc" exe systemctl restart redis } step_8_info() { echo "Initial setup $toolName and start supervisor"; } step_8() { toolScript initialsetup exe sudo -u mayan MAYAN_MEDIA_ROOT=${toolMediaFolder} \ ${toolRoot}/bin/mayan-edms.py collectstatic --noinput exe systemctl start supervisor } redisConfLoc="/etc/redis/redis.conf" redisConf="\ maxmemory-policy allkeys-lru save \"\" databases 2" step_10_info() { echo "Upgrade $toolName to $toolVersion"; } step_10_alias() { ALIAS="upgrade"; } step_10() { exe curl -o "$uninstallRemovalsLoc" https://gitlab.com/mayan-edms/mayan-edms/raw/master/removals.txt exe sudo -u mayan ${toolRoot}/bin/pip uninstall -r "$uninstallRemovalsLoc" endReturn -o $? exe systemctl stop supervisor exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir mayan-edms==$toolVersion endReturn -o $? toolScript performupgrade toolScript preparestatic --noinput # Generating new supervisor file step supervisorconf exe systemctl start supervisor } uninstallRemovalsLoc="/tmp/removals.txt" step_13_info() { echo "$toolName management script"; } step_13_alias() { ALIAS="manage"; } step_13() { shift if [ -z "$1" ] || [ "$1" == "" ] ; then echo -n "Command (empty for help): " if [ $DRY != 0 ]; then echo " dryrun" else read command fi else command="$@" fi toolScript "$command" } step_15_info() { echo "Upgrade python pip"; } step_15_alias() { ALIAS="upgradepip"; } step_15() { exe ${toolRoot}/bin/pip install --upgrade pip } step_20_info() { echo "Backup postgres database to media folder"; } step_20_alias() { ALIAS="backupdb"; } step_20() { local LASTYEAR=$(($(date +%Y)-1)) if [ ! -s ~/.pgpass ] ; then echo " [I] For unattended backup please define ~/.pgpass containing credentials for user mayan" fi echo "Backup custom pg format with standard user / database: mayan / mayan" exep "pg_dump -h 127.0.0.1 -U mayan -Fc mayan | bzip2 -c > ${toolDbBackupFolder}/`date +%Y-%m-%d\"_\"%H-%M-%S`.backup.bz2" exe rm -f ${toolDbBackupFolder}/${LASTYEAR}* } toolDbBackupFolder=${toolMediaFolder}/backupdb step_22_info() { echo "Postgres database restore"; } step_22_alias() { ALIAS="restoredb"; } step_22() { echo " [I] Postgres database restore procedure" echo "1. Create a empty postgres database first (step 4)" echo "2. psql -h -U -d -W -f " echo " e.g. psql -h 127.0.0.1 -U mayan -d mayan -W -f 2018-06-07_18-10-56.sql" echo "or" echo "3. Custom postgres format dump restore:" echo " pg_restore -h localhost -p 5432 -U mayan -d new_db -v \"10.70.0.61.backup\"" echo echo "Available postgresql databases:" exe cd ~postgres && sudo -u postgres psql -c '\l' } # Read postgres database information dbname/user/pass if empty readDatabaseInfos() { if [ "$postgresDb" == "" ] ; then read -p "Enter postgres database name: " postgresDb endCheckEmpty postgresDb "database" fi if [ "$postgresUser" == "" ] ; then read -p "Enter postgres user name: " postgresUser endCheckEmpty postgresUser "user name" fi if [ "$postgresPass" == "" ] ; then read -s -p "Enter postgres password: " postgresPass endCheckEmpty postgresPass "password" fi echo } # Needs readDatabaseInfos() to execute some commands toolScript() { if [ ! -z "$1" ] ; then readDatabaseInfos fi exep "sudo -u mayan \ MAYAN_DATABASES=\"{'default':{'ENGINE':'django.db.backends.postgresql','NAME':'${postgresDb}','PASSWORD':'${postgresPass}','USER':'${postgresUser}','HOST':'127.0.0.1'}}\" \ MAYAN_MEDIA_ROOT=${toolMediaFolder} \ ${toolRoot}/bin/mayan-edms.py $*" } VERSION_SEQREV=8 . /usr/local/bin/sequencer.sh