matrix - Check for rustc as dependency

modernize implementation
This commit is contained in:
2022-12-08 11:24:20 +01:00
parent ee340cfc8c
commit 4affa8ff8a

View File

@@ -1,14 +1,14 @@
#!/bin/bash
toolName=synapse
readonly toolName=synapse
toolDeps="build-essential python3-dev libffi-dev python3-pip python3-setuptools postgresql libssl-dev virtualenv libjpeg-dev libxslt1-dev libpq5 libpq-dev"
toolDeps+=" jq" # used as helper for api access
toolDepsRaspi="libopenjp2-7 libtiff5"
toolUser="synapse"
toolGroup="synapse"
toolServiceName="matrix-synapse"
synapseHashTool="env/bin/hash_password"
toolUrlLocal="http://localhost:8008"
readonly toolDeps+=" jq" # used as helper for api access
readonly toolDepsRaspi="libopenjp2-7 libtiff5"
readonly toolUser="synapse"
readonly toolGroup="synapse"
readonly toolServiceName="matrix-synapse"
readonly synapseHashTool="env/bin/hash_password"
readonly toolUrlLocal="http://localhost:8008"
# Filled by configuration
toolConfig=
toolUrl=
@@ -18,12 +18,8 @@ postgresDb=""
postgresUser=""
postgresPass=""
# Get script working directory
# (when called from a different directory)
WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )"
CONFIG=0
CONFIG_FILE_NAME="matrix.cfg"
CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example"
sq_aptOpt=
sq_config=0
seq_config() {
if [ "$(which lsb_release)" == "" ] ; then
@@ -39,39 +35,36 @@ seq_config() {
osName="Raspbian"
fi
echo " [I] Detected OS: $osName $distName"
info "Detected OS: $osName $distName"
initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE"
if [ $? -eq 0 ] ; then
CONFIG=1
if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
sq_config=1
toolConfig="${MATRIX_HOME}/homeserver.yaml"
toolUrl="https://$MATRIX_DOMAIN"
localHome="$MATRIX_HOME"
echo " $toolName home: $MATRIX_HOME"
echo " $toolName domain: $MATRIX_DOMAIN"
info -a "$toolName home: $MATRIX_HOME"
info -a "$toolName domain: $MATRIX_DOMAIN"
else
# End if no configuration file exists
dry || return 1
fi
## Apt cmdline option to suppress user interaction
interactive || sq_aptOpt="-y"
return 0
}
step_1_info() { echo "Installing $toolName dependencies"; }
step_1_alias() { echo "install"; }
step_1() {
local aptOption=
exe apt update
endReturn -o $? "Updating apt repositories failed"
if quiet ; then
aptOption="-y"
else
aptOption=""
fi
if [ "$osName" != "Raspbian" ] ; then
toolDepsRaspi=""
fi
exe apt install $toolDeps $toolDepsRaspi $aptOption
exe apt install $toolDeps $toolDepsRaspi ${sq_aptOpt}
}
step_2_info() { echo "Create postgres database for $toolName"; }
@@ -104,7 +97,7 @@ step_4() {
exe pip install --upgrade setuptools
# bcrypt and cryptography last version before requiring rust to compile
# hiredis and txredisapi needed by redis
exe pip install bcrypt==3.2.2 cryptography==37.0.4 matrix-synapse[postgres] lxml psycopg2 hiredis txredisapi
exe pip install matrix-synapse[postgres] lxml psycopg2 hiredis txredisapi
}
step_5_info() { echo "Create default configuration and folder structure"; }
@@ -168,7 +161,11 @@ step_10_info() {
}
step_10_alias() { echo "upgrade"; }
step_10() {
echo " [I] Upgrading $toolName"
if [[ -z "$(command -v rustc)" ]] ; then
info "Rust compiler not found an might be needed."
confirm "Continue without Rust?" || return 1
fi
info "Upgrading $toolName"
disableErrorCheck
exe source "${MATRIX_HOME}/env/bin/activate"
exe pip install --upgrade pip
@@ -178,9 +175,9 @@ step_10() {
enableErrorCheck
endReturn "Error upgrading $toolName"
echo " [I] Restarting $toolName"
info "Restarting $toolName"
step restart
echo " [I] New Version:"
info "New Version:"
exe sleep 2
step version
}
@@ -467,11 +464,11 @@ step_52_alias() { echo "backupdb"; }
step_52() {
local DELYEAR=$(($(date +%Y)-2))
if [ ! -s ~/.pgpass ] ; then
echo " [I] For unattended backup please define ~/.pgpass containing credentials"
echo " e.g. localhost:5432:database:user:pass"
echo "Backup custom pg format with standard user / database: synapse / synapse"
info "For unattended backup please define ~/.pgpass containing credentials"
info -a " e.g. localhost:5432:database:user:pass"
info -a "Backup custom pg format with standard user / database: synapse / synapse"
fi
exep "pg_dump -h 127.0.0.1 -U synapse -Fc synapse | bzip2 -c > ${toolDbBackupFolder}/`date +%Y-%m-%d\"_\"%H-%M-%S`.backup.bz2"
exep "pg_dump -h 127.0.0.1 -U synapse -Fc synapse | bzip2 -c > ${toolDbBackupFolder}/$(date +%Y-%m-%d\"_\"%H-%M-%S).backup.bz2"
exe rm -f ${toolDbBackupFolder}/${DELYEAR}*
}
toolDbBackupFolder=/root/backupdb
@@ -480,43 +477,49 @@ toolDbBackupFolder=/root/backupdb
step_54_info() { echo "Postgres database restore"; }
step_54_alias() { echo "restoredb"; }
step_54() {
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 synapse -d synapse -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 synapse -d new_db -v \"10.70.0.61.backup\""
echo
echo "Available postgresql databases:"
info "Postgres database restore procedure"
cat <<RESTORE_END
1. Create a empty postgres database first (step 4)
2. psql -h <host> -U <database user> -d <database name> -W -f <sql dump file>
e.g. psql -h 127.0.0.1 -U synapse -d synapse -W -f 2018-06-07_18-10-56.sql
or
3. Custom postgres format dump restore:
pg_restore -h localhost -p 5432 -U synapse -d new_db -v "10.70.0.61.backup"
RESTORE_END
info "Available postgresql databases:"
exe cd ~postgres
exe su postgres -c "psql -c '\l'"
echo "Available postgresql user:"
info -a "Available postgresql user:"
exe su postgres -c "psql -c '\du'"
}
step_56_info() { echo "$toolName migration notes"; }
step_56_alias() { echo "migrate"; }
step_56() {
echo " [I] Backup database"
echo " ./postgres.sh backupdb synapse"
echo
echo " [I] Backup virtual env folders except \"env\""
echo " cd ${MATRIX_HOME}"
echo " tar czf ../\`date +%Y-%m-%d\"_\"%H-%M-%S\`.synapse_bu.tar.gz --exclude=\"./env\" ."
echo
echo " [I] Transfer both backup files to target server"
echo
echo " [I] Install $toolName on the target server up to step \"virtualenv\""
echo " (Stop after first run and edit $seq_configFile)"
echo " ./matrix.sh install"
echo " cd ${MATRIX_HOME}"
echo " tar xf ...synapse_bu.tar.gz"
echo " Follow the instructions of:"
echo " ./matrix.sh restoredb"
echo " ./matrix.sh systemd"
echo
echo " [I] $toolName should be running. Now modify the reverse proxy configuration"
color green
cat <<MIGRATE_END
# Backup database
./postgres.sh backupdb synapse
# Backup virtual env folders except "env"
cd ${MATRIX_HOME}
tar czf ../\$(date +%Y-%m-%d"_"%H-%M-%S).synapse_bu.tar.gz --exclude="./env" .
# Transfer both backup files to target server
# Install $toolName on the target server up to step "virtualenv"
(Stop after first run and edit $seq_configFile)
./matrix.sh install
cd ${MATRIX_HOME}
tar xf ...synapse_bu.tar.gz
Follow the instructions of:
./matrix.sh restoredb
./matrix.sh systemd
# $toolName should be running. Now modify the reverse proxy configuration
MIGRATE_END
}
# Read postgres database information dbname/user/pass if empty
@@ -553,5 +556,7 @@ adminTokenCheck() {
return 0
}
# shellcheck disable=SC2034 # Appears unused
readonly sqr_minVersion=16
# shellcheck disable=SC1091 # Don't follow this source
. /usr/local/bin/sequencer.sh