From eafecb0ed8c373dc4f33b6190375fdc3d5c4d841 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 15 Dec 2018 19:15:04 +0100
Subject: [PATCH] Change directory structure and between-script path
 references.

---
 all_new_2018/{ => setup_scripts}/hardlink_etc.sh            | 5 +++--
 .../{ => setup_scripts}/init_user_and_keybased_login.sh     | 5 +++--
 all_new_2018/{ => setup_scripts}/install_for_target.sh      | 5 +++--
 all_new_2018/{ => setup_scripts}/letsencrypt.sh             | 2 ++
 all_new_2018/{ => setup_scripts}/letsencrypt_get.sh         | 0
 all_new_2018/{ => setup_scripts}/mirror_dir.sh              | 1 +
 all_new_2018/{ => setup_scripts}/prepare_to_meet_server.sh  | 0
 all_new_2018/{ => setup_scripts}/purge_nonrequireds.sh      | 5 +++--
 all_new_2018/{ => setup_scripts}/set_hostname_and_fqdn.sh   | 0
 all_new_2018/{ => setup_scripts}/setup_mail.sh              | 4 ++++
 all_new_2018/{ => setup_scripts}/setup_play.sh              | 6 +++++-
 all_new_2018/{ => setup_scripts}/setup_plomlombot.sh        | 2 +-
 all_new_2018/{ => setup_scripts}/setup_sendonly.sh          | 4 ++++
 all_new_2018/{ => setup_scripts}/setup_server.sh            | 4 ++++
 all_new_2018/{ => setup_scripts}/setup_web.sh               | 5 +++++
 15 files changed, 38 insertions(+), 10 deletions(-)
 rename all_new_2018/{ => setup_scripts}/hardlink_etc.sh (88%)
 rename all_new_2018/{ => setup_scripts}/init_user_and_keybased_login.sh (90%)
 rename all_new_2018/{ => setup_scripts}/install_for_target.sh (76%)
 rename all_new_2018/{ => setup_scripts}/letsencrypt.sh (88%)
 rename all_new_2018/{ => setup_scripts}/letsencrypt_get.sh (100%)
 rename all_new_2018/{ => setup_scripts}/mirror_dir.sh (85%)
 rename all_new_2018/{ => setup_scripts}/prepare_to_meet_server.sh (100%)
 rename all_new_2018/{ => setup_scripts}/purge_nonrequireds.sh (87%)
 rename all_new_2018/{ => setup_scripts}/set_hostname_and_fqdn.sh (100%)
 rename all_new_2018/{ => setup_scripts}/setup_mail.sh (95%)
 rename all_new_2018/{ => setup_scripts}/setup_play.sh (90%)
 rename all_new_2018/{ => setup_scripts}/setup_plomlombot.sh (96%)
 rename all_new_2018/{ => setup_scripts}/setup_sendonly.sh (73%)
 rename all_new_2018/{ => setup_scripts}/setup_server.sh (91%)
 rename all_new_2018/{ => setup_scripts}/setup_web.sh (71%)

diff --git a/all_new_2018/hardlink_etc.sh b/all_new_2018/setup_scripts/hardlink_etc.sh
similarity index 88%
rename from all_new_2018/hardlink_etc.sh
rename to all_new_2018/setup_scripts/hardlink_etc.sh
index a6f3b68..d6f2987 100755
--- a/all_new_2018/hardlink_etc.sh
+++ b/all_new_2018/setup_scripts/hardlink_etc.sh
@@ -9,10 +9,11 @@
 # CAUTION: This removes original files at the affected paths.
 set -e
 
-config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files/"
+config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files"
+linkable_files_dir="${config_tree_prefix}/linkable_etc_files"
 
 for target in "$@"; do
-    cd "${config_tree_prefix}${target}"
+    cd "${linkable_files_dir}/${target}"
     for path in $(find . -type f); do
         linking=$(echo "${path}" | cut -c2-)
         linked=$(realpath "${path}")
diff --git a/all_new_2018/init_user_and_keybased_login.sh b/all_new_2018/setup_scripts/init_user_and_keybased_login.sh
similarity index 90%
rename from all_new_2018/init_user_and_keybased_login.sh
rename to all_new_2018/setup_scripts/init_user_and_keybased_login.sh
index fc9dd96..6a46c20 100755
--- a/all_new_2018/init_user_and_keybased_login.sh
+++ b/all_new_2018/setup_scripts/init_user_and_keybased_login.sh
@@ -13,9 +13,10 @@ set -e
 
 # Location auf a sshd_config with "PermitRootLogin no" and
 # "PasswordAuthentication no".
+config_tree_prefix="${HOME}/config/all_new_2018"
+linkable_files_dir="${config_tree_prefix}/linkable_etc_files/server"
 system_path_sshd_config='/etc/ssh/sshd_config'
-config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files/server/"
-local_path_sshd_config="${config_tree_prefix}""${system_path_sshd_config}"
+local_path_sshd_config="${linkable_files_dir}/${system_path_sshd_config}"
 
 # Ensure we have a server name as argument.
 if [ $# -eq 0 ]; then
diff --git a/all_new_2018/install_for_target.sh b/all_new_2018/setup_scripts/install_for_target.sh
similarity index 76%
rename from all_new_2018/install_for_target.sh
rename to all_new_2018/setup_scripts/install_for_target.sh
index 9d765aa..53914d6 100755
--- a/all_new_2018/install_for_target.sh
+++ b/all_new_2018/setup_scripts/install_for_target.sh
@@ -5,10 +5,11 @@
 # Ignores anything in an apt-mark/ file after the last newline.
 set -e
 
-config_tree_prefix="${HOME}/config/all_new_2018/apt-mark/"
+config_tree_prefix="${HOME}/config/all_new_2018"
+aptmark_dir="${config_tree_prefix}/apt-mark"
 
 for target in "$@"; do
-    path="${config_tree_prefix}${target}"
+    path="${aptmark_dir}/${target}"
     cat "${path}" | while read line; do
         echo "$line"
         if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
diff --git a/all_new_2018/letsencrypt.sh b/all_new_2018/setup_scripts/letsencrypt.sh
similarity index 88%
rename from all_new_2018/letsencrypt.sh
rename to all_new_2018/setup_scripts/letsencrypt.sh
index 5fdf703..29ed3b6 100755
--- a/all_new_2018/letsencrypt.sh
+++ b/all_new_2018/setup_scripts/letsencrypt.sh
@@ -1,4 +1,6 @@
 #!/bin/sh
+# Certify current server with LetsEncrypt.
+# Uses hostname -f for the domain we want to certify.
 set -e
 
 # Ensure we have a mail address as argument.
diff --git a/all_new_2018/letsencrypt_get.sh b/all_new_2018/setup_scripts/letsencrypt_get.sh
similarity index 100%
rename from all_new_2018/letsencrypt_get.sh
rename to all_new_2018/setup_scripts/letsencrypt_get.sh
diff --git a/all_new_2018/mirror_dir.sh b/all_new_2018/setup_scripts/mirror_dir.sh
similarity index 85%
rename from all_new_2018/mirror_dir.sh
rename to all_new_2018/setup_scripts/mirror_dir.sh
index cb943c9..0fc03aa 100755
--- a/all_new_2018/mirror_dir.sh
+++ b/all_new_2018/setup_scripts/mirror_dir.sh
@@ -1,4 +1,5 @@
 #!/bin/sh
+# Mirror directory tree from remote to local server, keeping the path.
 set -e
 
 if [ $# -lt 2 ]; then
diff --git a/all_new_2018/prepare_to_meet_server.sh b/all_new_2018/setup_scripts/prepare_to_meet_server.sh
similarity index 100%
rename from all_new_2018/prepare_to_meet_server.sh
rename to all_new_2018/setup_scripts/prepare_to_meet_server.sh
diff --git a/all_new_2018/purge_nonrequireds.sh b/all_new_2018/setup_scripts/purge_nonrequireds.sh
similarity index 87%
rename from all_new_2018/purge_nonrequireds.sh
rename to all_new_2018/setup_scripts/purge_nonrequireds.sh
index 5b63ddf..e444a55 100755
--- a/all_new_2018/purge_nonrequireds.sh
+++ b/all_new_2018/setup_scripts/purge_nonrequireds.sh
@@ -4,11 +4,12 @@
 # or not listed in the argument-selected files of apt-mark/.
 set -e
 
-config_tree_prefix="${HOME}/config/all_new_2018/apt-mark/"
+config_tree_prefix="${HOME}/config/all_new_2018"
+aptmark_dir="${config_tree_prefix}/apt-mark"
 
 dpkg-query -Wf '${Package} ${Priority}\n' | grep ' required' | sed 's/ required//' > /tmp/list_white_unsorted
 for target in "$@"; do
-    path="${config_tree_prefix}${target}"
+    path="${aptmark_dir}/${target}"
     cat "${path}" | while read line; do
         if [ ! $(echo "${line}" | cut -c1) = "#" ]; then
             echo "${line}" >> /tmp/list_white_unsorted
diff --git a/all_new_2018/set_hostname_and_fqdn.sh b/all_new_2018/setup_scripts/set_hostname_and_fqdn.sh
similarity index 100%
rename from all_new_2018/set_hostname_and_fqdn.sh
rename to all_new_2018/setup_scripts/set_hostname_and_fqdn.sh
diff --git a/all_new_2018/setup_mail.sh b/all_new_2018/setup_scripts/setup_mail.sh
similarity index 95%
rename from all_new_2018/setup_mail.sh
rename to all_new_2018/setup_scripts/setup_mail.sh
index 60eda31..c8d4254 100755
--- a/all_new_2018/setup_mail.sh
+++ b/all_new_2018/setup_scripts/setup_mail.sh
@@ -10,6 +10,10 @@ mail_domain="$1"
 dkim_selector="$2"
 domainwide="$3"
 
+config_tree_prefix="${HOME}/config/all_new_2018"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+cd "${setup_scripts_dir}"
+
 # Set up DKIM key if necessary.
 mkdir -p /etc/dkimkeys/
 add_dkim_record=0
diff --git a/all_new_2018/setup_play.sh b/all_new_2018/setup_scripts/setup_play.sh
similarity index 90%
rename from all_new_2018/setup_play.sh
rename to all_new_2018/setup_scripts/setup_play.sh
index 233219d..020c13d 100755
--- a/all_new_2018/setup_play.sh
+++ b/all_new_2018/setup_scripts/setup_play.sh
@@ -8,8 +8,12 @@ if [ $# -lt 1 ]; then
 fi
 gpg_key="$1"
 
-./hardlink_etc.sh play
+config_tree_prefix="${HOME}/config/all_new_2018"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+cd "${setup_scripts_dir}"
+
 config_tree_prefix="${HOME}/config/all_new_2018/"
+./hardlink_etc.sh play
 apt -y install weechat screen vim
 cp "${config_tree_prefix}user_files/encrypter.sh" /home/plom/
 chown plom:plom /home/plom/encrypter.sh
diff --git a/all_new_2018/setup_plomlombot.sh b/all_new_2018/setup_scripts/setup_plomlombot.sh
similarity index 96%
rename from all_new_2018/setup_plomlombot.sh
rename to all_new_2018/setup_scripts/setup_plomlombot.sh
index 3c9efa3..5a45b6f 100755
--- a/all_new_2018/setup_plomlombot.sh
+++ b/all_new_2018/setup_scripts/setup_plomlombot.sh
@@ -8,7 +8,7 @@ if [ $# -lt 1 ]; then
 fi
 gpg_key="$1"
 
-config_tree_prefix="${HOME}/config/all_new_2018/"
+config_tree_prefix="${HOME}/config/all_new_2018"
 irclogs_dir=/var/www/html/irclogs
 irclogs_pw_dir=/var/www/irclogs_pw
 cp "${config_tree_prefix}"/user_files/plomlombot_daemon.sh /home/plom/
diff --git a/all_new_2018/setup_sendonly.sh b/all_new_2018/setup_scripts/setup_sendonly.sh
similarity index 73%
rename from all_new_2018/setup_sendonly.sh
rename to all_new_2018/setup_scripts/setup_sendonly.sh
index 641c16b..e761eeb 100755
--- a/all_new_2018/setup_sendonly.sh
+++ b/all_new_2018/setup_scripts/setup_sendonly.sh
@@ -3,6 +3,10 @@
 # to the world.
 set -e
 
+config_tree_prefix="${HOME}/config/all_new_2018"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+cd "${setup_scripts_dir}"
+
 ./hardlink_etc.sh sendonly
 echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
 echo "postfix postfix/mailname string $(hostname -f)" | debconf-set-selections
diff --git a/all_new_2018/setup_server.sh b/all_new_2018/setup_scripts/setup_server.sh
similarity index 91%
rename from all_new_2018/setup_server.sh
rename to all_new_2018/setup_scripts/setup_server.sh
index ea3437a..b47a495 100755
--- a/all_new_2018/setup_server.sh
+++ b/all_new_2018/setup_scripts/setup_server.sh
@@ -11,6 +11,10 @@ fi
 hostname="$1"
 fqdn="$2"
 
+config_tree_prefix="${HOME}/config/all_new_2018"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+cd "${setup_scripts_dir}"
+
 # Adapt /etc/ to our needs by hardlinking into ./linkable_etc_files. This
 # will set basic configurations affecting following steps, such as setup
 # of APT and the locale selection, so needs to be right at the beginning.
diff --git a/all_new_2018/setup_web.sh b/all_new_2018/setup_scripts/setup_web.sh
similarity index 71%
rename from all_new_2018/setup_web.sh
rename to all_new_2018/setup_scripts/setup_web.sh
index 661aa74..7adb62f 100755
--- a/all_new_2018/setup_web.sh
+++ b/all_new_2018/setup_scripts/setup_web.sh
@@ -1,6 +1,11 @@
 #!/bin/sh
+# Set up plomlompom.com web server.
 set -e
 
+config_tree_prefix="${HOME}/config/all_new_2018"
+setup_scripts_dir="${config_tree_prefix}/setup_scripts"
+cd "${setup_scripts_dir}"
+
 ./hardlink_etc.sh web
 sed -i "s/REPLACE_fqdn_ECALPER/$(hostname -f)/g" /etc/nginx/nginx.conf
 sed -i "s/REPLACE_fqdn_ECALPER/$(hostname -f)/g" /etc/gitweb.conf
-- 
2.30.2