summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-04-30 18:11:12 +0200
committerSamantaz Fox <coding@samantaz.fr>2022-05-21 19:06:45 +0200
commitfe53b5503cc175ad7cef74d9ad1d8096031c44ac (patch)
treeecf857d9145ccf94924af445163d9c829044bb3e /scripts
parentd66ef8fe22ccf095205c0586700728d33d81fbd3 (diff)
downloadinvidious-fe53b5503cc175ad7cef74d9ad1d8096031c44ac.tar.gz
invidious-fe53b5503cc175ad7cef74d9ad1d8096031c44ac.tar.bz2
invidious-fe53b5503cc175ad7cef74d9ad1d8096031c44ac.zip
Add a script to start postgres and create user/DB
Diffstat (limited to 'scripts')
-rw-r--r--scripts/deploy-database.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/deploy-database.sh b/scripts/deploy-database.sh
new file mode 100644
index 00000000..9f0bffcb
--- /dev/null
+++ b/scripts/deploy-database.sh
@@ -0,0 +1,41 @@
+#!/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