#!/bin/bash toolName="Mayan EDMS" toolVersion="3.3.3" 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() { exe apt update exe apt --no-install-recommends install libreoffice -y } step_2_info() { echo "Get $toolName binary dependencies"; } step_2() { exe apt install exiftool g++ gcc ghostscript gnupg1 graphviz libfuse2 \ libjpeg-dev libmagic1 libpq-dev libpng-dev libtiff-dev \ poppler-utils postgresql python3-dev python3-virtualenv redis-server \ sane-utils supervisor tesseract-ocr tesseract-ocr-deu zlib1g-dev -y } step_3_info() { echo "Create virtual environment"; } step_3() { exe adduser mayan --disabled-password --disabled-login --no-create-home --gecos -G users"" exe mkdir -p ${toolRoot} exe virtualenv ${toolRoot} -p $(which python3) saveReturn $? endReturn exe chown -R mayan:mayan ${toolRoot} } step_4_info() { echo "Create postgres database for $toolName"; } step_4_alias() { ALIAS="createdb"; } step_4() { readDatabaseInfos 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() { exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir --no-use-pep517 mayan-edms saveReturn $? endReturn exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir --no-use-pep517 psycopg2==2.8.3 redis==3.2.1 saveReturn $? endReturn toolScript initialsetup exe sudo -u mayan MAYAN_MEDIA_ROOT=${toolMediaFolder} \ ${toolRoot}/bin/mayan-edms.py collectstatic --noinput } step_6_info() { echo "Supervisord configuration for $toolName"; } 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 exe systemctl enable supervisor exe systemctl restart supervisor } redisConfLoc="/etc/redis/redis.conf" redisConf="\ maxmemory-policy allkeys-lru save \"\" databases 2" step_10_info() { echo "Update $toolName"; } step_10_alias() { ALIAS="update"; } 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" saveReturn $? endReturn exe systemctl stop supervisor exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir mayan-edms==$toolVersion saveReturn $? endReturn toolScript performupgrade toolScript preparestatic --noinput # Generating new supervisor file step_6 exe systemctl start supervisor } uninstallRemovalsLoc="/tmp/removals.txt" step_13_info() { echo "$toolName management script"; } step_13() { if [ -z "$2" ] || [ "$2" == "" ] ; then echo -n "Command (empty for help): " if [ $DRY != 0 ]; then echo " dryrun" else read command fi else command="$2" 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 "[INFO] 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 "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\"" } # 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=6 . sequencer.sh