home · contact · privacy
To status archive setup script, add mirroring from old IP.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 26 Sep 2023 18:15:25 +0000 (20:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 26 Sep 2023 18:15:25 +0000 (20:15 +0200)
bookworm/setup_scripts/mirror_dir.sh [new file with mode: 0755]
bookworm/setup_scripts/prepare_to_meet_server.sh [new file with mode: 0755]
bookworm/setup_scripts/setup_status.plomlompom.com.sh

diff --git a/bookworm/setup_scripts/mirror_dir.sh b/bookworm/setup_scripts/mirror_dir.sh
new file mode 100755 (executable)
index 0000000..0fb7df7
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# Mirror directory tree from remote to local server, keeping the path.
+set -e
+
+expect_n_args 2 "(server, directory)" "$@"
+server=$1
+dir=$2
+path_package=/tmp/delete.tar
+
+eval `ssh-agent`
+ssh-add
+cd
+ssh plom@"${server}" "cd \"${dir}\" && tar cf ${path_package} ."
+scp plom@"${server}":"${path_package}" "${path_package}"
+mkdir -p "${dir}"
+cd "${dir}"
+tar xf "${path_package}"
+cd
+rm "${path_package}"
+ssh plom@"${server}" rm "${path_package}"
diff --git a/bookworm/setup_scripts/prepare_to_meet_server.sh b/bookworm/setup_scripts/prepare_to_meet_server.sh
new file mode 100755 (executable)
index 0000000..d00efdf
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+# Do some of the steps necessary to SSH (key-based) with another server.
+set -e
+
+expect_n_args 1 "(server IP)" "$@"
+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 -N ""
+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
index 30f81d7a01f571b7aba0d28e9418f490ca7e33ca..01356877a1ec0fc20c50fda113c98367985df66e 100755 (executable)
@@ -4,15 +4,19 @@ set -e
 
 expect_setup_finished_file setup_web_has_been_run setup_web.sh
 
-if [ -z "$1" ]; then
-    domain="status.plomlompom.com"
-    mail="plom+status@plomlompom.com"
-elif [ "$#" -lt 2 ]; then
+mirror_ip=""
+mirror_state="not mirroring automatically"
+domain="status.plomlompom.com"
+mail="plom+status@plomlompom.com"
+if [ "$#" -gt 1 ]; then
     domain="$1"
-    mail="plom+testing@plomlompom.com"
-else
-    domain="$1"
-    mail="$2"
+    if [ "$#" -gt 2 ]; then
+        mail="plom+testing@plomlompom.com"
+       if [ "$#" -gt 3]; then
+           mirror_ip="$3"
+            mirror_state="mirroring automatically from ${target_ip}"
+        fi
+    fi
 fi
 echo "Assuming domain ${domain} and letsencrypt support mail address ${mail}, abort and provide as arguments in this order if other desired! (Otherwise just hit Return.)"
 read _
@@ -31,5 +35,20 @@ rm /etc/nginx/sites-enabled/default
 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/status.plomlompom.com.nginx
 ln -s /etc/nginx/sites-available/status.plomlompom.com.nginx /etc/nginx/sites-enabled/status.plomlompom.com.nginx
 
+if [ ! -z "${mirror_ip}" ]; then
+    # Set up connection to old server.
+    cp "${setup_scripts_dir}/prepare_to_meet_server.sh" /home/plom/
+    chown plom:plom /home/plom/prepare_to_meet_server.sh
+    su -lc "./prepare_to_meet_server.sh ${old_server}" plom
+    read -p'Hit Enter when you are done.' ignore
+    rm /home/plom/prepare_to_meet_server.sh
+
+    # Mirror dirs.
+    su -lc "ln -s /home/plom/status.plomlompom.com /var/www-dump/status.plomlompom.com" plom
+    cp "${setup_scripts_dir}/mirror_dir.sh" /home/plom/
+    su -lc "./mirror_dir.sh ${mirror_ip} /var/www/status.plomlompom.com" plom
+    rm /home/plom/mirror_dir.sh
+fi
+
 service nginx restart