X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;ds=inline;f=buster%2Fsetup_scripts%2Fsetup_website.sh;h=d1dc91d7b756907ebedf1aecbade35eed0812839;hb=6dc9cfee290e3ec99ea4d52fb4c3bbe0ff6b8697;hp=fef4b6772282d0cc25cf2c2d3606518032809c12;hpb=40b1aac9fad6b73589484750bc70968a260f945e;p=config
diff --git a/buster/setup_scripts/setup_website.sh b/buster/setup_scripts/setup_website.sh
index fef4b67..d1dc91d 100755
--- a/buster/setup_scripts/setup_website.sh
+++ b/buster/setup_scripts/setup_website.sh
@@ -1,16 +1,25 @@
#!/bin/sh
set -e
-set -x
-# Heavily inspired by
-if [ "$#" -ne 4 ]; then
- echo 'Need domain name and mail and old server IP and key ID as argument.'
+if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
+ echo 'Need domain name and mail and key ID and init state and possibly old server IP as argument.'
+ false
+fi
+if [ ! "$4" = "copy" ] && [ ! "$4" = "new" ] && [ ! "$4" = "upgrade" ]; then
+ echo "Need init state to be either 'copy' or 'new' or 'upgrade'"
+ false
+fi
+if [ ! "$4" = "new" ] && [ "$#" -ne 5 ]; then
+ echo "With init state != 'new' need fifth argument old server IP."
false
fi
domain="$1"
mail="$2"
-old_server="$3"
-gpg_key="$4"
+gpg_key="$3"
+init_state="$4"
+old_server="$5"
+
+# NOTE: init_state=upgrade is for migration from older stretch server setup
# Install configs, set up firewall.
config_tree_prefix="${HOME}/config/buster"
@@ -23,27 +32,49 @@ 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
+# Set up connection to old server.
+if [ ! "${init_state}" = "new" ]; then
+ cp "${config_tree_prefix}/setup_scripts/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
+fi
+
# Set up repos dir.
-mkdir /var/repos
-chown plom:plom /var/repos
# 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
+ mkdir /var/repos
+ chown plom:plom /var/repos
+else
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ chmod a+w /var
+ if [ "${init_state}" = "copy" ]; then
+ su -lc "./mirror_dir.sh ${old_server} /var/repos" plom
+ else
+ su -lc "./mirror_dir.sh ${old_server} /var/public_repos" plom
+ fi
+ chmod a-w /var
+ rm /home/plom/mirror_dir.sh
+fi
# Prepare NGINX and GitWeb config.
sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/gitweb.conf
sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/website.nginx
ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.nginx
-# Set up website.
+# Set up website. TODO: use non-/var/www dir for better separation to dump site
rm -rf /var/www
mkdir /var/www
chown plom:plom /var/www
-cp "${config_tree_prefix}/setup_scripts/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
-su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
+if [ "${init_state}" = "upgrade" ]; then
+ # This assumes the old core.plomlompom.com filesystem hierarchy.
+ su -lc "cd /var/repos && git clone --mirror plom@core.plomlompom.com:repos/website" plom
+elif [ "${init_state}" = "new" ]; then
+ su -lc "cd /var/repos && git init --bare website.git" plom
+fi
cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
@@ -73,26 +104,34 @@ mkdir -p "${irclogs_dir}"
chown -R plom:plom "${irclogs_dir}"
mkdir -p "${irclogs_pw_dir}"
chown -R plom:plom "${irclogs_pw_dir}"
-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
+if [ "${init_state}" = "new" ]; then
+ # Handle the case that the repo is in the old pre-buster server setup â
+ # even then, the URL should be the same.
+ 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
-echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
-chown plom:plom /home/plom/.plomlombot
+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
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
+ rm /home/plom/mirror_dir.sh
+ su -lc "scp plom@${old_server}:.plomlombot ~" plom
+ su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
+fi
systemctl enable plomlombot.service
service plomlombot start
-# Migrate borg repo.
-cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
-su -lc "./mirror_dir.sh ${old_server} /home/plom/borg" plom
-
-# Clean up
-rm /home/plom/{prepare_to_meet_server,mirror_dir}.sh
+# In the above step, we might have created a root-owned /var/www/html â
+# fix this here.
+chown -R plom:plom /var/www/html
# TODO:
-# - commit git-daemon-export-ok directly into the public repos; rename
-# /home/plom/public_repos to /home/plom/repos
+# - rename /home/plom/public_repos to /home/plom/repos
service nginx restart