4 if [ "$#" -ne 4 ] && [ "$#" -ne 5 ]; then
5 echo 'Need domain name and mail and key ID and init state and possibly old server IP as argument.'
8 if [ ! "$4" = "copy" ] && [ ! "$4" = "new" ] && [ ! "$4" = "upgrade" ]; then
9 echo "Need init state to be either 'copy' or 'new' or 'upgrade'"
12 if [ ! "$4" = "new" ] && [ "$#" -ne 5 ]; then
13 echo "With init state != 'new' need fifth argument old server IP."
22 # Install configs, set up firewall.
23 config_tree_prefix="${HOME}/config/buster"
24 ./install_for_target.sh web website
25 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web website
26 nft -f /etc/nftables.conf
28 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
29 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
30 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
31 rm /etc/nginx/sites-enabled/default
33 # Set up connection to old server.
34 if [ ! "${init_state}" = "new" ]; then
35 cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/
36 chown plom:plom /home/plom/prepare_to_meet_server.sh
37 su -lc "./prepare_to_meet_server.sh ${old_server}" plom
38 read -p'Hit Enter when you are done.' ignore
39 rm /home/plom/prepare_to_meet_server.sh
43 # To use this dir, "git clone --mirror" repo source paths into it as user plom.
44 # As user plom, touch git-daemon-export-ok files into it to make the repo
45 # publically available.
46 if [ "${init_state}" = "new" ]; then
48 chown plom:plom /var/repos
50 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
52 if [ "${init_state}" = "copy" ]; then
53 su -lc "./mirror_dir.sh ${old_server} /var/repos" plom
55 su -lc "./mirror_dir.sh ${old_server} /var/public_repos" plom
58 rm /home/plom/mirror_dir.sh
61 # Prepare NGINX and GitWeb config.
62 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/gitweb.conf
63 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/website.nginx
64 ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.nginx
66 # Set up website. TODO: use non-/var/www dir for better separation to dump site
69 chown plom:plom /var/www
70 if [ "${init_state}" = "upgrade" ]; then
71 # This assumes the old core.plomlompom.com filesystem hierarchy.
72 su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
73 elif [ "${init_state}" = "new" ]; then
74 su -lc "cd /var/repos && git init --bare website.git" plom
76 cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
77 su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
78 # NOTE: There seems to be a bug that creates a root-owned /var/www/html on
79 # init_state=copy for some reason, at least if website.git is an empty repo.
80 # The following might fix this:
81 mkdir -p /var/www/html
82 chown -R plom:plom /var/www/html
85 keyservers='sks-keyservers.net/ keys.gnupg.net'
89 for keyserver in $(echo "${keyservers}"); do
90 su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
91 if [ $? -eq "0" ]; then
95 echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
97 if [ "${do_break}" -eq "1" ]; then
104 irclogs_dir=/var/www/html/irclogs
105 irclogs_pw_dir=/var/www/irclogs_pw
106 mkdir -p "${irclogs_dir}"
107 chown -R plom:plom "${irclogs_dir}"
108 mkdir -p "${irclogs_pw_dir}"
109 chown -R plom:plom "${irclogs_pw_dir}"
110 if [ "${init_state}" = "new" ]; then
111 # Handle the case that the repo is in the old pre-buster server setup –
112 # even then, the URL should be the same.
113 su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
114 su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
115 cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
117 su -lc "git clone /var/repos/plomlombot-irc.git" plom
118 cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
119 chown plom:plom /home/plom/plomlombot_daemon.sh
120 if [ "${init_state}" = "new" ]; then
121 echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
122 chown plom:plom /home/plom/.plomlombot
124 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
125 su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
126 rm /home/plom/mirror_dir.sh
127 su -lc "scp plom@${old_server}:.plomlombot ~" plom
128 su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
131 systemctl enable plomlombot.service
132 service plomlombot start
135 # - rename /home/plom/public_repos to /home/plom/repos
137 service nginx restart