Files
shell_sequencer/seqs/mayan-edms.sh
Martin Winkler a7646beeb0 Bump mayan version to 3.2.9
Include supervisor configuration update and manual editing in update step
2019-11-04 11:45:24 +01:00

186 lines
5.5 KiB
Bash
Executable File

#!/bin/bash
toolName="Mayan EDMS"
toolVersion="3.2.9"
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 g++ gcc ghostscript gnupg1 graphviz libfuse2 \
libjpeg-dev libmagic1 libpq-dev libpng-dev libtiff-dev \
poppler-utils postgresql python-dev python-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}
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.7.3.2 redis==2.10.6
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}"
echo "Wrap you password in \", if it contains a \"=\" character, in the file ${supervisordConfLoc}"
}
supervisordConfLoc="/etc/supervisor/conf.d/mayan.conf"
step_7_info() { echo "$toolName 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 1"
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 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
echo -n "Edit supervisor configuration... (ENTER to continue)"
if [ $DRY != 0 ]; then
echo " dryrun"
else
read
fi
exe vi "$supervisordConfLoc"
exe systemctl restart supervisor
}
uninstallRemovalsLoc="/tmp/removals.txt"
step_13_info() { echo "$toolName management script"; }
step_13() {
echo -n "Command (empty for help): "
if [ $DRY != 0 ]; then
echo " dryrun"
else
read 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 "[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 <host> -U <database user> -d <database name> -W -f <sql dump file>"
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_DATABASE_ENGINE=django.db.backends.postgresql MAYAN_DATABASE_NAME=${postgresDb} \
MAYAN_DATABASE_PASSWORD=\"${postgresPass}\" MAYAN_DATABASE_USER=${postgresUser} \
MAYAN_DATABASE_HOST=127.0.0.1 MAYAN_MEDIA_ROOT=${toolMediaFolder} \
${toolRoot}/bin/mayan-edms.py $*"
}
VERSION_SEQREV=4
. sequencer.sh