diff options
| author | Caian Benedicto <caianbene@gmail.com> | 2024-12-13 18:29:28 -0300 |
|---|---|---|
| committer | Caian Benedicto <caianbene@gmail.com> | 2024-12-13 20:26:52 -0300 |
| commit | d7f5cdc2f971af524c496aaeb25226eb9f8236df (patch) | |
| tree | 1e69d1088ee67407b1058f490cc188cd1dd4e287 /scripts/deploy-database.sh | |
| parent | 78773d732672d8985795fb040a39dd7e946c7b7c (diff) | |
| parent | 98926047586154269bb269d01e3e52e60e044035 (diff) | |
| download | invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.tar.gz invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.tar.bz2 invidious-d7f5cdc2f971af524c496aaeb25226eb9f8236df.zip | |
Merge branch 'master' into unix-sockets
Diffstat (limited to 'scripts/deploy-database.sh')
| -rwxr-xr-x | scripts/deploy-database.sh | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/scripts/deploy-database.sh b/scripts/deploy-database.sh new file mode 100755 index 00000000..fa24b8f0 --- /dev/null +++ b/scripts/deploy-database.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Parameters +# + +interactive=true + +if [ "$1" = "--no-interactive" ]; then + interactive=false +fi + +# +# Enable and start Postgres +# + +sudo systemctl start postgresql.service +sudo systemctl enable postgresql.service + +# +# Create databse and user +# + +if [ "$interactive" = "true" ]; then + sudo -u postgres -- createuser -P kemal + sudo -u postgres -- createdb -O kemal invidious +else + # Generate a DB password + if [ -z "$POSTGRES_PASS" ]; then + echo "Generating database password" + POSTGRES_PASS=$(tr -dc 'A-Za-z0-9.;!?{[()]}\\/' < /dev/urandom | head -c16) + fi + + # hostname:port:database:username:password + echo "Writing .pgpass" + echo "127.0.0.1:*:invidious:kemal:${POSTGRES_PASS}" > "$HOME/.pgpass" + + sudo -u postgres -- psql -c "CREATE USER kemal WITH PASSWORD '$POSTGRES_PASS';" + sudo -u postgres -- psql -c "CREATE DATABASE invidious WITH OWNER kemal;" + sudo -u postgres -- psql -c "GRANT ALL ON DATABASE invidious TO kemal;" +fi + + +# +# Instructions for modification of pg_hba.conf +# + +if [ "$interactive" = "true" ]; then + echo + echo "-------------" + echo " NOTICE " + echo "-------------" + echo + echo "Make sure that your postgreSQL's pg_hba.conf file contains the follwong" + echo "lines before previous 'host' configurations:" + echo + echo "host invidious kemal 127.0.0.1/32 md5" + echo "host invidious kemal ::1/128 md5" + echo +fi |
