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 # NOTE: init_state=upgrade is for migration from older stretch server setup
24 # Install configs, set up firewall.
25 config_tree_prefix="${HOME}/config/buster"
26 ./install_for_target.sh web website
27 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web website
28 nft -f /etc/nftables.conf
30 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
31 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
32 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
33 rm /etc/nginx/sites-enabled/default
35 # Set up connection to old server.
36 if [ ! "${init_state}" = "new" ]; then
37 cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/
38 chown plom:plom /home/plom/prepare_to_meet_server.sh
39 su -lc "./prepare_to_meet_server.sh ${old_server}" plom
40 read -p'Hit Enter when you are done.' ignore
41 rm /home/plom/prepare_to_meet_server.sh
45 # To use this dir, "git clone --mirror" repo source paths into it as user plom.
46 # As user plom, touch git-daemon-export-ok files into it to make the repo
47 # publically available.
48 if [ "${init_state}" = "new" ]; then
50 chown plom:plom /var/repos
52 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
54 if [ "${init_state}" = "copy" ]; then
55 su -lc "./mirror_dir.sh ${old_server} /var/repos" plom
57 su -lc "./mirror_dir.sh ${old_server} /var/public_repos" plom
60 rm /home/plom/mirror_dir.sh
63 # Prepare NGINX and GitWeb config.
64 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/gitweb.conf
65 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/website.nginx
66 ln -s /etc/nginx/sites-available/website.nginx /etc/nginx/sites-enabled/website.nginx
68 # Set up website. TODO: use non-/var/www dir for better separation to dump site
71 chown plom:plom /var/www
72 if [ "${init_state}" = "upgrade" ]; then
73 # This assumes the old core.plomlompom.com filesystem hierarchy.
74 su -lc "cd /var/repos && git clone --mirror plom@core.plomlompom.com:repos/website" plom
75 elif [ "${init_state}" = "new" ]; then
76 su -lc "cd /var/repos && git init --bare website.git" plom
78 cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
79 su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
82 keyservers='sks-keyservers.net/ keys.gnupg.net'
86 for keyserver in $(echo "${keyservers}"); do
87 su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
88 if [ $? -eq "0" ]; then
92 echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
94 if [ "${do_break}" -eq "1" ]; then
101 irclogs_dir=/var/www/html/irclogs
102 irclogs_pw_dir=/var/www/irclogs_pw
103 mkdir -p "${irclogs_dir}"
104 chown -R plom:plom "${irclogs_dir}"
105 mkdir -p "${irclogs_pw_dir}"
106 chown -R plom:plom "${irclogs_pw_dir}"
107 if [ "${init_state}" = "new" ]; then
108 # Handle the case that the repo is in the old pre-buster server setup –
109 # even then, the URL should be the same.
110 su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
111 su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
112 cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
114 su -lc "git clone /var/repos/plomlombot-irc.git" plom
115 cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
116 chown plom:plom /home/plom/plomlombot_daemon.sh
117 if [ "${init_state}" = "new" ]; then
118 echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
119 chown plom:plom /home/plom/.plomlombot
121 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
122 su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
123 rm /home/plom/mirror_dir.sh
124 su -lc "scp plom@${old_server}:.plomlombot ~" plom
125 su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
127 systemctl enable plomlombot.service
128 service plomlombot start
130 # In the above step, we might have created a root-owned /var/www/html –
132 chown -R plom:plom /var/www/html
135 # - rename /home/plom/public_repos to /home/plom/repos
137 service nginx restart