home · contact · privacy
Merge branch 'master' of plomlompom.com:/var/repos/config
[config] / bullseye / setup_scripts / setup_microblogpub.sh
1 #!/bin/sh
2 set -e
3 set -x
4
5 if [ "$#" -ne 2 ]; then
6     echo 'Need domain name and mail.'
7     false
8 fi
9 domain="$1"
10 mail="$2"
11
12 # Install configs, set up firewall.
13 config_tree_prefix="${HOME}/config/bullseye"
14 ./install_for_target.sh web microblogpub
15 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web microblogpub
16 apt update  # since we just updated /etc/apt/sources.list
17 nft -f /etc/nftables.conf
18
19 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
20 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
21 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
22 rm /etc/nginx/sites-enabled/default
23
24 # Install Python >=3.10 from source (Bullseye only has 3.9).
25 python_version=3.11.1
26 python_dirname="Python-${python_version}"
27 su -lc "wget https://www.python.org/ftp/python/${python_version}/${python_dirname}.tgz" plom
28 su -lc "tar -xvf ${python_dirname}.tgz" plom
29 su -lc "cd /home/plom/${python_dirname} && ./configure --enable-optimizations && make"
30 cd /home/plom/${python_dirname}/
31 make altinstall
32 cd
33 rm -rf /home/plom/${python_dirname}
34
35 # Configure/install Poetry and microblog.pub.
36 su -lc "curl -sSL https://install.python-poetry.org | python3.11" - plom
37 su -lc "git clone https://git.sr.ht/~tsileo/microblog.pub testing.microblog.pub" - plom
38 su -lc "poetry config installer.parallel false" - plom
39 su -lc "cd testing.microblog.pub && poetry install" - plom
40 su -lPc "cd testing.microblog.pub && poetry run inv configuration-wizard" - plom
41 su -lPc "cd testing.microblog.pub && poetry run inv migrate-db" - plom
42
43 # Set up microblog.pub daemon service.
44 venv_dir_path=$( su -lPc "cd testing.microblog.pub && poetry env info --path" - plom)
45 venv_dir=$(basename ${venv_dir_path})
46 sed -i "s/REPLACE_venv_dir_ECALPER/${venv_dir}/g" /etc/systemd/system/microblogpub.service
47 systemctl enable microblogpub.service
48 service microblogpub start
49
50 # Prepare and start NGINX config.
51 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/microblogpub.nginx
52 ln -s /etc/nginx/sites-available/microblogpub.nginx /etc/nginx/sites-enabled/microblogpub.nginx
53 service nginx restart
54
55 # Setup regular DB pruning
56 cp "${config_tree_prefix}/other_files/prune_microblog.sh" /home/plom/
57 systemctl enable microblogpub_prune.timer
58 systemctl start microblogpub_prune.timer