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