From 79cc7cc06b36b0a78c85564ae77d64092fe99c8a Mon Sep 17 00:00:00 2001 From: Gitouche <26656-gitouche@users.noreply.framagit.org> Date: Thu, 1 Jul 2021 19:28:13 +0200 Subject: [PATCH] matrix : ajout mecanique variables (pour gestion du password) --- functions.sh | 20 ++++++++++++++++++++ podman-matrix/05_freshinstall.sh | 4 +++- podman-matrix/10_install.sh | 4 +++- podman-matrix/vars.sh | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/functions.sh b/functions.sh index 85be573..5482d76 100644 --- a/functions.sh +++ b/functions.sh @@ -58,6 +58,26 @@ check_systemd_unit_exists () { systemctl --user cat -- ${1} &> /dev/null } +# check if variable is empty +check_variable_is_empty () { + [[ -z ${!1} ]] +} + +# ensure variable is defined +ensure_variable_is_defined () { + if check_variable_is_empty ${1}; then + echo "Error : variable ${1} must be defined" + exit 1 + fi +} + +# ensure all variables are defined +ensure_variables_are_defined () { + for i in ${1}; do + ensure_variable_is_defined $i + done +} + # ok if systemd unit file {1} exists ensure_systemd_unit_exists () { if ! check_systemd_unit_exists ${1}; then diff --git a/podman-matrix/05_freshinstall.sh b/podman-matrix/05_freshinstall.sh index ac855b5..72cb1d1 100755 --- a/podman-matrix/05_freshinstall.sh +++ b/podman-matrix/05_freshinstall.sh @@ -7,6 +7,8 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root +ensure_variables_are_defined "$envvars" + if [[ -d ~/.local/share/containers/storage/volumes/${confvolume} ]]; then echo "Error : conf volume ${confvolume} already exists. Please remove it first (prune?)." exit 1 @@ -21,7 +23,7 @@ podman volume create matrixdotorg_synapse-pgsql && \ podman run -it --name ${container_name}-generate --mount type=volume,src=matrixdotorg_synapse-data,dst=/data -e SYNAPSE_SERVER_NAME=garbaye.fr -e SYNAPSE_REPORT_STATS=no ${synapse_image}:${synapse_version} generate && \ podman rm ${container_name}-generate && \ podman run -d --name ${container_name}-generate --mount type=volume,src=matrixdotorg_synapse-data,dst=/data ${synapse_image}:${synapse_version} && \ -podman exec -it ${container_name}-generate bash -c "sed -i -e 's|^#public_baseurl: https://example.com/$|public_baseurl: https://qlf-matrix.garbaye.fr|g' /data/homeserver.yaml && sed -z -i -e 's|database:\n name: sqlite3\n args:\n database: /data/homeserver.db|database:\n name: psycopg2\n args:\n user: synapse\n password: mysecretpass\n database: synapse\n host: synapse-db\n port: 5432\n cp_min: 5\n cp_max: 10|g' /data/homeserver.yaml && sed -i -e 's|^#enable_registration: false$|enable_registration: false|g' /data/homeserver.yaml" && \ +podman exec -it ${container_name}-generate bash -c "sed -i -e 's|^#public_baseurl: https://example.com/$|public_baseurl: ${GARBAYE_MATRIX_POSTGRES_PASSWORD}|g' /data/homeserver.yaml && sed -z -i -e 's|database:\n name: sqlite3\n args:\n database: /data/homeserver.db|database:\n name: psycopg2\n args:\n user: synapse\n password: ${GARBAYE_MATRIX_POSTGRES_PASSWORD}\n database: synapse\n host: synapse-db\n port: 5432\n cp_min: 5\n cp_max: 10|g' /data/homeserver.yaml && sed -i -e 's|^#enable_registration: false$|enable_registration: false|g' /data/homeserver.yaml" && \ podman stop ${container_name}-generate && \ podman rm ${container_name}-generate && \ ${ABSDIR}/10_install.sh diff --git a/podman-matrix/10_install.sh b/podman-matrix/10_install.sh index 86b230c..198debd 100755 --- a/podman-matrix/10_install.sh +++ b/podman-matrix/10_install.sh @@ -7,6 +7,8 @@ source ${ABSDIR}/vars.sh ensure_pwd_is_scriptdir ensure_not_root +ensure_variables_are_defined "$envvars" + if [[ ! -d ~/.local/share/containers/storage/volumes/${confvolume} ]]; then echo "Error : conf volume ${confvolume} does not exists. Consider running 05_freshinstall.sh if this is the first install." exit 1 @@ -19,7 +21,7 @@ fi podman pod create --publish 8086:8008 --name ${pod_name} && \ podman run -d --name ${db_container_name} --pod ${pod_name} \ --mount type=volume,src=${dbvolume},dst=/var/lib/postgresql/data/ \ - -e POSTGRES_PASSWORD=mysecretpass \ + -e POSTGRES_PASSWORD=${GARBAYE_MATRIX_POSTGRES_PASSWORD} \ -e POSTGRES_USER=${container_name} \ -e POSTGRES_DB=${container_name} \ -e POSTGRES_INITDB_ARGS="--encoding=UTF8 --locale=C" \ diff --git a/podman-matrix/vars.sh b/podman-matrix/vars.sh index 2eed521..659dbff 100644 --- a/podman-matrix/vars.sh +++ b/podman-matrix/vars.sh @@ -12,4 +12,5 @@ confvolume='matrixdotorg_synapse-data' dbvolume='matrixdotorg_synapse-pgsql' container_name='synapse' db_container_name='synapse-db' -#GARBAYE_JITSI_URL="${GARBAYE_JITSI_ENV_URL:-https://jitsi.garbaye.fr}" +GARBAYE_MATRIX_URL="${GARBAYE_MATRIX_URL:-https://matrix.garbaye.fr}" +envvars='GARBAYE_MATRIX_POSTGRES_PASSWORD GARBAYE_MATRIX_URL'