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" ]; then
9 echo "Need init state to be either 'copy' or 'new'."
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/bullseye"
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}" = "new" ]; then
71 su -lc "cd /var/repos && git init --bare website.git" plom
73 cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
74 su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
77 keyservers='keyserver.ubuntu.com pgp.surf.nl pgp.rediris.es'
81 for keyserver in $(echo "${keyservers}"); do
82 su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
83 if [ $? -eq "0" ]; then
87 echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
89 if [ "${do_break}" -eq "1" ]; then
96 irclogs_dir=/var/www/html/irclogs
97 irclogs_pw_dir=/var/www/irclogs_pw
98 mkdir -p "${irclogs_dir}"
99 chown -R plom:plom "${irclogs_dir}"
100 mkdir -p "${irclogs_pw_dir}"
101 chown -R plom:plom "${irclogs_pw_dir}"
102 if [ "${init_state}" = "new" ]; then
103 # TODO investigate whether we can get rid of anything here
104 # Handle the case that the repo is in the old pre-buster server setup –
105 # even then, the URL should be the same.
106 su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
107 su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
108 cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
110 su -lc "git clone /var/repos/plomlombot-irc.git" plom
111 cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
112 chown plom:plom /home/plom/plomlombot_daemon.sh
113 if [ "${init_state}" = "new" ]; then
114 echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
115 chown plom:plom /home/plom/.plomlombot
117 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
118 su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
119 rm /home/plom/mirror_dir.sh
120 su -lc "scp plom@${old_server}:.plomlombot ~" plom
121 # TODO su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
123 # TODO systemctl enable plomlombot.service
124 # TODO service plomlombot start
127 su -lc "git clone /var/repos/guiltcards" plom
128 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
129 su -lc "./mirror_dir.sh ${old_server} /home/plom/guiltcards/decks" plom
130 rm /home/plom/mirror_dir.sh
132 # In the above step, we might have created a root-owned /var/www/html –
134 chown -R plom:plom /var/www/html
137 # - rename /home/plom/public_repos to /home/plom/repos
139 service nginx restart