From 19172909051f0465122c497581a44237d1129a0e Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sun, 26 Jan 2020 22:40:15 +0100
Subject: [PATCH] Pleroma migration scripts.

---
 buster/setup_scripts/backup_pleroma.sh        |  1 +
 buster/setup_scripts/migrate_pleroma.sh       | 20 +++++++++++++++++
 .../setup_scripts/prepare_to_meet_server.sh   | 22 +++++++++++++++++++
 buster/setup_scripts/restore_pleroma.sh       |  1 +
 4 files changed, 44 insertions(+)
 create mode 100755 buster/setup_scripts/migrate_pleroma.sh
 create mode 100755 buster/setup_scripts/prepare_to_meet_server.sh

diff --git a/buster/setup_scripts/backup_pleroma.sh b/buster/setup_scripts/backup_pleroma.sh
index ae1e6bd..ae95b4d 100755
--- a/buster/setup_scripts/backup_pleroma.sh
+++ b/buster/setup_scripts/backup_pleroma.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 set -e
+set -x
 # Heavily inspired by <https://docs.pleroma.social/backup.html>
 
 service pleroma stop
diff --git a/buster/setup_scripts/migrate_pleroma.sh b/buster/setup_scripts/migrate_pleroma.sh
new file mode 100755
index 0000000..bff9872
--- /dev/null
+++ b/buster/setup_scripts/migrate_pleroma.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+set -x
+# Heavily inspired by <https://docs.pleroma.social/backup.html>
+
+if [ "$#" -ne 1 ]; then
+    echo 'Need server IP as argument.'
+    false
+fi
+server_ip="$1"
+
+config_tree_prefix="${HOME}/config/buster"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+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
diff --git a/buster/setup_scripts/prepare_to_meet_server.sh b/buster/setup_scripts/prepare_to_meet_server.sh
new file mode 100755
index 0000000..569bf74
--- /dev/null
+++ b/buster/setup_scripts/prepare_to_meet_server.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# Do some of the steps necessary to SSH (key-based) with another server.
+set -e
+
+if [ "$#" -ne 1 ]; then
+    echo 'Need server IP as argument.'
+    false
+fi
+target="$1"
+
+# We need a public key to copy over, so generate it if not found.
+if [ ! -f ~/.ssh/id_rsa.pub ]; then
+    ssh-keygen
+fi
+
+# Add target to ~/.ssh/known_hosts so we don't get
+# asked for permission at inopportune moments.
+ssh-keyscan -H "$target" >> ~/.ssh/known_hosts
+
+# Tell user what to do.
+echo "APPEND FOLLOWING TO TARGET'S ~/.ssh/authorized_keys:"
+cat ~/.ssh/id_rsa.pub
diff --git a/buster/setup_scripts/restore_pleroma.sh b/buster/setup_scripts/restore_pleroma.sh
index 4f4d05b..844a655 100755
--- a/buster/setup_scripts/restore_pleroma.sh
+++ b/buster/setup_scripts/restore_pleroma.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 set -e
+set -x
 # Heavily inspired by <https://docs.pleroma.social/backup.html>
 
 service pleroma stop
-- 
2.30.2