From 009ef80bbffe24818d7b430e35452fc805f5c867 Mon Sep 17 00:00:00 2001 From: sceox Date: Mon, 26 Dec 2022 12:09:55 -0800 Subject: [PATCH] Abort if token or database file not readable and no TTY --- synapse-purge-compress.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/synapse-purge-compress.sh b/synapse-purge-compress.sh index 66de287..ec2ff5f 100755 --- a/synapse-purge-compress.sh +++ b/synapse-purge-compress.sh @@ -103,8 +103,10 @@ main () { if test -r /etc/matrix-synapse/access_token ; then token="$(cat /etc/matrix-synapse/access_token)" +elif ! [ -t 1 ]; then + echo "Error: Access token file is not readable and cannot prompt for token." >&2 + exit 1 else - # TODO: if standard output is not a tty, exit with failure read -p "synapse admin API access_token: " token fi @@ -113,8 +115,10 @@ if test -r $db_conf_file; then db_name="$(grep '^\s*database: ' $db_conf_file | awk '{print $2}')" db_user="$(grep '^\s*user: ' $db_conf_file | awk '{print $2}')" db_password="$(grep '^\s*password: ' $db_conf_file | awk '{print $2}')" +elif ! [ -t 1 ]; then + echo "Error: Database config file is not readable and cannot prompt for database config." >&2 + exit 1 else - # TODO: if standard output is not a tty, exit with failure read -p "synapse database name: " db_name read -p "synapse database user: " db_user read -p "synapse database password: " db_password