matrix : ajout mecanique variables (pour gestion du password)

This commit is contained in:
Gitouche 2021-07-01 19:28:13 +02:00
parent b677b7a17c
commit 79cc7cc06b
4 changed files with 28 additions and 3 deletions

View file

@ -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

View file

@ -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

View file

@ -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" \

View file

@ -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'