home · contact · privacy
Refactor both scripts into one setup_static_website?
authorChristian Heller <c.heller@plomlompom.de>
Tue, 26 Sep 2023 19:15:23 +0000 (21:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 26 Sep 2023 19:15:23 +0000 (21:15 +0200)
bookworm/setup_scripts/setup_static_website.sh [new file with mode: 0644]
bookworm/setup_scripts/setup_tube.plomlompom.com.sh

diff --git a/bookworm/setup_scripts/setup_static_website.sh b/bookworm/setup_scripts/setup_static_website.sh
new file mode 100644 (file)
index 0000000..4d290a5
--- /dev/null
@@ -0,0 +1,59 @@
+#!/bin/sh
+set -e
+. ./misc.sh
+
+expect_setup_finished_file setup_web_has_been_run setup_web.sh
+
+expect_n_args 1 "(website template, i.e. status.plomlompom, tube.plomlompom.com …)" "$@"
+website_template="$1"
+shift 1
+
+mirror_ip=""
+mirror_state="not mirroring automatically"
+domain="${website_template}"
+mail="plom+webmaster@plomlompom.com"
+if [ "$#" -gt 0 ]; then
+    domain="$1"
+    if [ "$#" -gt 1 ]; then
+        mail="plom+testing@plomlompom.com"
+       if [ "$#" -gt 2 ]; then
+           mirror_ip="$3"
+            mirror_state="mirroring automatically from ${mirror_ip}"
+        fi
+    fi
+fi
+echo "Assuming domain ${domain} and letsencrypt support mail address ${mail} and ${mirror_state}, abort and provide as arguments in this order if other desired! (Otherwise just hit Return.)"
+read _
+
+if [ ! -z "${mirror_ip}" ]; then
+    # Set up connection to old server.
+    cp "${setup_scripts_dir}/misc.sh" /home/plom/
+    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 ${mirror_ip}" plom
+    read -p 'Hit Enter when you are done.' ignore
+    rm /home/plom/prepare_to_meet_server.sh
+
+    # Mirror dirs.
+    cp "${setup_scripts_dir}/mirror_dir.sh" /home/plom/
+    su -lc "./mirror_dir.sh ${mirror_ip} /var/www/${website_template}" plom
+    rm /home/plom/mirror_dir.sh
+    rm /home/plom/misc.sh
+fi
+
+# Install configs, set up firewall.
+./install_for_target.sh "${website_template}" 
+./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" "${website_template}" 
+nft -f /etc/nftables.conf
+
+# Set up letsencrypt certificate. TODO: Is it auto-renewed?
+ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
+certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
+rm /etc/nginx/sites-enabled/default
+
+# Prepare NGINX.
+sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" "/etc/nginx/sites-available/${website_template}.nginx"
+ln -s "/etc/nginx/sites-available/{website_template}.nginx" "/etc/nginx/sites-enabled/${website_template}.nginx"
+
+service nginx restart
+
index a68ee393a838a36740b3c5073680e0a0e5519413..246f8bc0c6a5adb15fc1831d515015cb635da48b 100755 (executable)
@@ -46,7 +46,7 @@ if [ ! -z "${mirror_ip}" ]; then
 
     # Mirror dirs.
     cp "${setup_scripts_dir}/mirror_dir.sh" /home/plom/
 
     # Mirror dirs.
     cp "${setup_scripts_dir}/mirror_dir.sh" /home/plom/
-    su -lc "./mirror_dir.sh ${mirror_ip} /var/www/status.plomlompom.com" plom
+    su -lc "./mirror_dir.sh ${mirror_ip} /var/www/tube.plomlompom.com" plom
     rm /home/plom/mirror_dir.sh
     rm /home/plom/misc.sh
 fi
     rm /home/plom/mirror_dir.sh
     rm /home/plom/misc.sh
 fi