set-db.sh (1259B)
1 #!/bin/bash 2 # set-db.sh 3 # Usage: ./set-db.sh <POSTGRES_URL> 4 POSTGRES_URL="$1" 5 6 # The database URI belongs in the secret snippet that the packaged 7 # taler-merchant.conf pulls in with 8 # @inline-secret@ merchantdb-postgres ../secrets/merchant-db.secret.conf 9 # as [merchantdb-postgres] CONFIG. "DATABASE_URL" is not an option the 10 # merchant reads, and appending it to taler-merchant.conf landed it under 11 # whatever section happened to come last, so it never had any effect. 12 SECRET_PATH="/etc/taler-merchant/secrets/merchant-db.secret.conf" 13 14 if [ -z "$POSTGRES_URL" ]; then 15 echo "Missing PostgreSQL URL argument." 16 exit 1 17 fi 18 19 if [ ! -f "$SECRET_PATH" ]; then 20 echo "Expected $SECRET_PATH to be shipped by the taler-merchant package." >&2 21 exit 1 22 fi 23 24 # Rewrite in place via tee so the file keeps its owner and permissions. 25 printf '%s\n' "[merchantdb-postgres]" "CONFIG=$POSTGRES_URL" \ 26 | sudo tee "$SECRET_PATH" > /dev/null 27 28 echo "Updated [merchantdb-postgres] CONFIG in $SECRET_PATH" 29 30 # The external database still needs the schema before the backend can use it. 31 if ! sudo taler-merchant-dbconfig; then 32 echo "taler-merchant-dbconfig failed for the external database." >&2 33 exit 1 34 fi 35 36 sudo systemctl restart taler-merchant.target 37 38 exit 0