home · contact · privacy
Improve handling of old/new dumpsite init.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 15 Apr 2020 20:09:35 +0000 (22:09 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 15 Apr 2020 20:09:35 +0000 (22:09 +0200)
buster/setup_scripts/setup_dumpsite.sh
buster/setup_scripts/setup_website.sh

index 71cc6f5bd7c32e2febccd3f6458036ed5a704da0..4a7200372a9a2a3edc402865ae39073feac65cd5 100755 (executable)
@@ -2,13 +2,18 @@
 set -e
 set -x
 
-if [ "$#" -ne 3 ]; then
-    echo 'Need domain name and mail and old server.'
+if [ "$#" -ne 4 ]; then
+    echo 'Need domain name and mail and old server and init state (old, new?).'
+    false
+fi
+if [ ! "$4" = "old" ] && [ ! "$4" = "new" ]; then
+    echo "Need init state to be either 'old' or 'new'"
     false
 fi
 domain="$1"
 mail="$2"
 old_server="$3"
+init_state="$4"
 
 # Install configs, set up firewall.
 echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
@@ -37,17 +42,19 @@ dump_dir=dump
 geheim_dir=geheim
 su -lc "ln -s /home/plom/${dump_dir} /var/www-dump/${dump_dir}" plom
 su -lc "ln -s /home/plom/${geheim_dir} /var/www-dump/${geheim_dir}" plom
-# Use upper outcommented instead of lower code if setting up new empty server.
-#su -lc "mkdir ${dump_dir} ${geheim_dir}" plom
-#password_geheim=$(pwgen -1)
-#echo "foo:{PLAIN}${password_geheim}" > /var/www-dump/password_geheim
-#echo "geheim password is: ${password_geheim}"
-cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
-su -lc "./mirror_dir.sh ${old_server} /home/plom/${dump_dir}" plom
-su -lc "./mirror_dir.sh ${old_server} /home/plom/${geheim_dir}" plom
-su -lc "scp plom@${old_server}:/var/www-dump/password_geheim ~" plom
-mv /home/plom/password_geheim /var/www-dump/password_geheim
-rm /home/plom/mirror_dir.sh
+if [ "${init_state}" = "new" ]; then
+  su -lc "mkdir ${dump_dir} ${geheim_dir}" plom
+  password_geheim=$(pwgen -1)
+  echo "foo:{PLAIN}${password_geheim}" > /var/www-dump/password_geheim
+  echo "geheim password is: ${password_geheim}"
+else
+  cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+  su -lc "./mirror_dir.sh ${old_server} /home/plom/${dump_dir}" plom
+  su -lc "./mirror_dir.sh ${old_server} /home/plom/${geheim_dir}" plom
+  su -lc "scp plom@${old_server}:/var/www-dump/password_geheim ~" plom
+  mv /home/plom/password_geheim /var/www-dump/password_geheim
+  rm /home/plom/mirror_dir.sh
+fi
 
 # Set up redo.
 wget http://news.dieweltistgarnichtso.net/bin/archives/redo-sh.tar.gz
@@ -78,11 +85,12 @@ su -lc "cd url-catcher && ln -s ../blog/captchas/linkable/ captchas" plom
 cp "${config_tree_prefix}/other_files/url-catcher_customizations.json" /home/plom/url-catcher/customizations.json
 systemctl enable url_catcher.service
 service url_catcher start
-# Outcomment if setting up new / not migrating.
-cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
-su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/ips" plom
-su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/lists" plom
-rm /home/plom/mirror_dir.sh
+if [ ! "${init_state}" = "new" ]; then
+  cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+  su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/ips" plom
+  su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/lists" plom
+  rm /home/plom/mirror_dir.sh
+fi
 
 # Set up index.html
 cp "${config_tree_prefix}/other_files/dumpsite_index.html" /var/www-dump/index.html
index 08739032c91debb9f010ccd5c83325d4e985c556..38b49a20595a4715ec21c06c2b688504d7026d1c 100755 (executable)
@@ -37,7 +37,7 @@ rm /home/plom/prepare_to_meet_server.sh
 # To use this dir, "git clone --mirror" repo source paths into it as user plom.
 # As user plom, touch git-daemon-export-ok files into it to make the repo
 # publically available.
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
   mkdir /var/repos
   chown plom:plom /var/repos
 else
@@ -57,7 +57,7 @@ ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.
 rm -rf /var/www
 mkdir /var/www
 chown plom:plom /var/www
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
   su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
   cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
 fi
@@ -89,16 +89,15 @@ mkdir -p "${irclogs_dir}"
 chown -R plom:plom "${irclogs_dir}"
 mkdir -p "${irclogs_pw_dir}"
 chown -R plom:plom "${irclogs_pw_dir}"
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
   su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
   su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
   cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
 fi
-
 su -lc "git clone /var/repos/plomlombot-irc.git" plom
 cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
 chown plom:plom /home/plom/plomlombot_daemon.sh
-if [ "$init_state" = "new" ]; then
+if [ "${init_state}" = "new" ]; then
   echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
   chown plom:plom /home/plom/.plomlombot
 else