4 if [ "$#" -ne 5 ]; then
5 echo 'Need domain name and mail and old server IP and key ID and init state (old, new?) as argument.'
8 if [ ! "$5" = "old" ] && [ ! "$5" = "new" ]; then
9 echo "Need init state to be either 'old' or 'new'"
18 # Install configs, set up firewall.
19 config_tree_prefix="${HOME}/config/buster"
20 ./install_for_target.sh web website
21 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web website
22 nft -f /etc/nftables.conf
24 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
25 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
26 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
27 rm /etc/nginx/sites-enabled/default
29 # Set up connection to old server.
30 cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/
31 chown plom:plom /home/plom/prepare_to_meet_server.sh
32 su -lc "./prepare_to_meet_server.sh ${old_server}" plom
33 read -p'Hit Enter when you are done.' ignore
34 rm /home/plom/prepare_to_meet_server.sh
37 # To use this dir, "git clone --mirror" repo source paths into it as user plom.
38 # As user plom, touch git-daemon-export-ok files into it to make the repo
39 # publically available.
40 if [ "${init_state}" = "new" ]; then
42 chown plom:plom /var/repos
44 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
46 su -lc "./mirror_dir.sh ${old_server} /var/repos" plom
48 rm /home/plom/mirror_dir.sh
51 # Prepare NGINX and GitWeb config.
52 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/gitweb.conf
53 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/website.nginx
54 ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.nginx
56 # Set up website. TODO: use non-/var/www dir for better separation to dump site
59 chown plom:plom /var/www
60 if [ "${init_state}" = "new" ]; then
61 su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
62 cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
64 su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
67 keyservers='sks-keyservers.net/ keys.gnupg.net'
71 for keyserver in $(echo "${keyservers}"); do
72 su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
73 if [ $? -eq "0" ]; then
77 echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
79 if [ "${do_break}" -eq "1" ]; then
86 irclogs_dir=/var/www/html/irclogs
87 irclogs_pw_dir=/var/www/irclogs_pw
88 mkdir -p "${irclogs_dir}"
89 chown -R plom:plom "${irclogs_dir}"
90 mkdir -p "${irclogs_pw_dir}"
91 chown -R plom:plom "${irclogs_pw_dir}"
92 if [ "${init_state}" = "new" ]; then
93 su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
94 su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
95 cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
97 su -lc "git clone /var/repos/plomlombot-irc.git" plom
98 cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
99 chown plom:plom /home/plom/plomlombot_daemon.sh
100 if [ "${init_state}" = "new" ]; then
101 echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
102 chown plom:plom /home/plom/.plomlombot
104 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
105 su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
106 rm /home/plom/mirror_dir.sh
107 su -lc "scp plom@${old_server}:.plomlombot ~" plom
108 su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
111 systemctl enable plomlombot.service
112 service plomlombot start
115 # - commit git-daemon-export-ok directly into the public repos; rename
116 # /home/plom/public_repos to /home/plom/repos
118 service nginx restart