From 06e7f865feb169f359e28382200fe7d6c5d42673 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sun, 26 Jan 2020 23:41:28 +0100
Subject: [PATCH] Fix Pleroma migration scripts.

---
 buster/setup_scripts/migrate_pleroma.sh | 7 ++++++-
 buster/setup_scripts/restore_pleroma.sh | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/buster/setup_scripts/migrate_pleroma.sh b/buster/setup_scripts/migrate_pleroma.sh
index bff9872..5eefc39 100755
--- a/buster/setup_scripts/migrate_pleroma.sh
+++ b/buster/setup_scripts/migrate_pleroma.sh
@@ -11,10 +11,15 @@ server_ip="$1"
 
 config_tree_prefix="${HOME}/config/buster"
 setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+
+# So we're only asked once …
+eval $(ssh-agent)
+ssh-add
+
 cd "${setup_scripts_dir}"
 ./prepare_to_meet_server.sh "${server_ip}"
 read -p'Hit Enter when you are done.' ignore
 ssh plom@"${server_ip}" 'su -lc "cd config && git pull"'
 ssh plom@"${server_ip}" 'su -lc "cd config/buster/setup_scripts && ./backup_pleroma.sh"'
 scp plom@"${server_ip}":~/pleroma_backup.tar /home/plom/pleroma_backup.tar
-./backup_pleroma.sh
+./restore_pleroma.sh
diff --git a/buster/setup_scripts/restore_pleroma.sh b/buster/setup_scripts/restore_pleroma.sh
index 844a655..325aa23 100755
--- a/buster/setup_scripts/restore_pleroma.sh
+++ b/buster/setup_scripts/restore_pleroma.sh
@@ -10,4 +10,9 @@ tar xf pleroma_backup.tar
 cp -a pleroma_backup/uploads/* /var/lib/pleroma/uploads/
 cp -a pleroma_backup/etc_files/* /etc/pleroma/
 su postgres -lc 'pg_restore --clean -d pleroma -v -1 /tmp/pleroma_backup/pleroma.pgdump'
+
+# TODO: Horrible hack, improve.
+db_pw=$(cat /etc/pleroma/config.exs | grep password | sed 's/[ ]*password\: *//g' | sed 's/,//g' | sed 's/"//g')
+su postgres -lc "psql -c \"ALTER USER pleroma WITH PASSWORD '${db_pw}';\""
+
 service pleroma start
-- 
2.30.2