home · contact · privacy
Fix.
[config] / buster / setup_scripts / setup_dumpsite.sh
1 #!/bin/sh
2 set -e
3 set -x
4
5 if [ "$#" -ne 4 ]; then
6     echo 'Need domain name and mail and old server.'
7     false
8 fi
9 domain="$1"
10 mail="$2"
11 old_server="$3"
12
13 # Install configs, set up firewall.
14 echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
15 echo "postfix postfix/mailname string $(hostname -f)" | debconf-set-selections
16 config_tree_prefix="${HOME}/config/buster"
17 ./install_for_target.sh web dumpsite
18 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web dumpsite
19 nft -f /etc/nftables.conf
20
21 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
22 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
23 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
24 rm /etc/nginx/sites-enabled/default
25
26 # Set up connection to old dump server.
27 cp "${config_tree_prefix}/setup_scripts/prepare_to_meet_server.sh" /home/plom/
28 chown plom:plom /home/plom/prepare_to_meet_server.sh
29 su -lc "./prepare_to_meet_server.sh ${old_server}" plom
30 read -p'Hit Enter when you are done.' ignore
31 rm /home/plom/prepare_to_meet_server.sh
32
33 # Set up dump dirs.
34 mkdir /var/www-dump
35 chown plom:plom /var/www-dump
36 dump_dir=dump
37 geheim_dir=geheim
38 su -lc "ln -s /home/plom/${dump_dir} /var/www-dump/${dump_dir}" plom
39 su -lc "ln -s /home/plom/${geheim_dir} /var/www-dump/${geheim_dir}" plom
40 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
41 su -lc "./mirror_dir.sh ${old_server} /home/plom/${dump_dir}" plom
42 su -lc "./mirror_dir.sh ${old_server} /home/plom/${geheim_dir}" plom
43 su -lc "scp plom@${old_server}:/var/www-dump/password_geheim ~" plom
44 mv /home/plom/password_geheim /var/www-dump/password_geheim
45 rm /home/plom/mirror_dir.sh
46
47 # Set up redo.
48 wget http://news.dieweltistgarnichtso.net/bin/archives/redo-sh.tar.gz
49 tar -moxzf redo-sh.tar.gz -C /usr/local
50
51 # Set up zettel.
52 su -lc "git clone --mirror ${old_server}:zettel.git" plom
53 cp "${config_tree_prefix}/other_files/zettel_hook_post-receive" /home/plom/zettel.git/hooks/post-receive
54 su -lc "git clone ~/zettel.git && cd zettel && redo" plom
55 su -lc "ln -s /home/plom/zettel /var/www-dump/zettel" plom
56 # NOTE: Locally, to update content, clone zettel.git, not zettel.
57
58 # Set up redo blog.
59 su -lc "git clone --mirror ${old_server}:blog.git" plom
60 cp "${config_tree_prefix}/other_files/blog_hook_post-receive" /home/plom/blog.git/hooks/post-receive
61 su -lc "git clone ~/blog.git" plom
62 # TODO: set up like plomlombot repo (with post-recieve hook)?
63 su -lc "git clone https://plomlompom.com/repos/clone/redo-blog" plom
64 su -lc "cd redo-blog && ./add_dir.sh ~/blog" plom
65 su -lc "cd blog && redo" plom
66 su -lc "ln -s /home/plom/blog/public /var/www-dump/blog" plom
67 # NOTE: Locally, to update content, clone blog.git, not blog.
68
69 # Set up url catcher.
70 # TODO: set up like plomlombot repo (with post-recieve hook)?
71 su -lc "git clone https://plomlompom.com/repos/clone/url-catcher" plom
72 su -lc "cd url-catcher && ln -s ../blog/captchas/linkable/ captchas" plom
73 cp "${config_tree_prefix}/other_files/url-catcher_customizations.json" /home/plom/url-catcher/customizations.json
74 systemctl enable url_catcher.service
75 service url_catcher start
76 cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
77 su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/ips" plom
78 su -lc "./mirror_dir.sh ${old_server} /home/plom/url-catcher/lists" plom
79 rm /home/plom/mirror_dir.sh
80
81 # Set up index.html
82 cp "${config_tree_prefix}/other_files/dumpsite_index.html" /var/www-dump/index.html
83
84 # Prepare NGINX.
85 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/dumpsite.nginx
86 ln -s /etc/nginx/sites-available/dumpsite.nginx /etc/nginx/sites-enabled/dumpsite.nginx
87
88 service nginx restart