238 lines
7.2 KiB
Bash
Executable File
238 lines
7.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
toolName="Mayan EDMS"
|
|
toolVersion="4.2.1"
|
|
toolRoot="/opt/mayan-edms"
|
|
toolMediaFolder="/opt/mayan-edms/media"
|
|
|
|
# Needed for different steps
|
|
postgresDb=""
|
|
postgresUser=""
|
|
postgresPass=""
|
|
|
|
# Get script working directory
|
|
# (when called from a different directory)
|
|
WDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >>/dev/null 2>&1 && pwd)"
|
|
APTOPT=
|
|
CONFIG=0
|
|
SCRIPT_FILE=$(basename -- $0)
|
|
SCRIPT_NAME=${SCRIPT_FILE%%.*}
|
|
CONFIG_FILE_NAME="${SCRIPT_NAME}.cfg"
|
|
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
|
|
|
|
step_config() {
|
|
## or to use sequencer api with global config file:
|
|
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
|
|
if [ $? -eq 0 ] ; then
|
|
CONFIG=1
|
|
postgresDb="$MAYAN_DB"
|
|
postgresUser="$MAYAN_DBUSER"
|
|
postgresPass="$MAYAN_DBPASS"
|
|
else
|
|
# End if no configuration file exists
|
|
[ $DRY -eq 0 ] && return -1
|
|
fi
|
|
|
|
## Apt cmdline option to suppress user interaction
|
|
[ $QUIET -ne 0 ] && APTOPT="-y"
|
|
|
|
## Return of non zero value will abort the sequence
|
|
return 0
|
|
}
|
|
|
|
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-get install libimage-exiftool-perl g++ gcc coreutils ghostscript gnupg1 \
|
|
graphviz libfuse2 libjpeg-dev libmagic1 libpq-dev libpng-dev libtiff-dev libldap2-dev libsasl2-dev \
|
|
poppler-utils postgresql python3-dev python3-pip python3-venv python3-virtualenv \
|
|
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==$toolVersion
|
|
endReturn -o $? "pip install for $toolName failed"
|
|
exe sudo -u mayan ${toolRoot}/bin/pip install --no-cache-dir psycopg2==2.8.4 redis==3.4.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 # only < 3.4
|
|
exe systemctl start supervisor
|
|
}
|
|
|
|
redisConfLoc="/etc/redis/redis.conf"
|
|
redisConf="\
|
|
maxmemory-policy allkeys-lru
|
|
save \"\"
|
|
databases 2"
|
|
|
|
step_10_info() {
|
|
echoinfoArgs "[OPTIONS]"
|
|
echo "Upgrade $toolName to $toolVersion"
|
|
echoinfo " [OPTIONS]"
|
|
echoinfo " super : update also supervisor configuration"
|
|
echoinfo " (manual redis password update may be needed)"
|
|
}
|
|
step_10_alias() { ALIAS="upgrade"; }
|
|
step_10() {
|
|
shift # don't need the step number
|
|
step upgradepip
|
|
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 # only < 3.4
|
|
case $1 in
|
|
"super")
|
|
# Generating new supervisor file
|
|
step supervisorconf ;;
|
|
esac
|
|
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 DELYEAR=$(($(date +%Y)-2))
|
|
if [ ! -s ~/.pgpass ] ; then
|
|
echo " [I] For unattended backup please define ~/.pgpass containing credentials for user mayan"
|
|
echo " e.g. localhost:5432:mayan:mayan:pass4mayan"
|
|
echo "Backup custom pg format with standard user / database: mayan / mayan"
|
|
fi
|
|
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}/${DELYEAR}*
|
|
}
|
|
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 <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\""
|
|
echo
|
|
echo "Available postgresql databases:"
|
|
exe cd ~postgres && sudo -u postgres psql -c '\l'
|
|
echo "Available postgresql user:"
|
|
exe cd ~postgres && sudo -u postgres psql -c '\du'
|
|
}
|
|
|
|
# Read postgres database information dbname/user/pass if empty
|
|
readDatabaseInfos() {
|
|
if [ -z "$postgresDb" ] ; then
|
|
read -p "Enter postgres database name: " postgresDb
|
|
endCheckEmpty postgresDb "database"
|
|
fi
|
|
if [ -z "$postgresUser" ] ; then
|
|
read -p "Enter postgres user name: " postgresUser
|
|
endCheckEmpty postgresUser "user name"
|
|
fi
|
|
if [ -z "$postgresPass" ] ; then
|
|
read -s -p "Enter postgres password: " postgresPass
|
|
endCheckEmpty postgresPass "password"
|
|
fi
|
|
echoseq
|
|
}
|
|
|
|
# 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=15
|
|
. /usr/local/bin/sequencer.sh
|