home · contact · privacy
Fix.
[config] / buster / setup_scripts / setup_pleroma_otp.sh
1 #!/bin/sh
2 set -e
3 # Heavily inspired by <https://docs.pleroma.social/otp_en.html>
4
5 if [ "$#" -ne 2 ]; then
6     echo 'Need domain name, mail_address as arguments.'
7     false
8 fi
9 domain="$1"
10 mail="$2"
11
12 # Install dependencies, set up firewall.
13 config_tree_prefix="${HOME}/config/buster"
14 ./install_for_target.sh web pleroma pleroma_otp
15 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web pleroma
16 nft -f /etc/nftables.conf
17
18 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
19 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
20 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
21 rm /etc/nginx/sites-enabled/default
22
23 # Prepare user.
24 adduser --system --shell  /bin/false --home /opt/pleroma pleroma
25
26 # Download and unzip latest stable release, set up Pleroma dirs.
27 export FLAVOUR='amd64'
28 su pleroma -s $SHELL -lc "
29 curl 'https://git.pleroma.social/api/v4/projects/2/jobs/artifacts/stable/download?job=$FLAVOUR' -o /tmp/pleroma.zip
30 unzip /tmp/pleroma.zip -d /tmp/
31 "
32 su pleroma -s $SHELL -lc "
33 mv /tmp/release/* /opt/pleroma
34 rmdir /tmp/release
35 rm /tmp/pleroma.zip
36 "
37 mkdir -p /var/lib/pleroma/uploads
38 chown -R pleroma /var/lib/pleroma
39 mkdir -p /etc/pleroma
40 chown -R pleroma /etc/pleroma
41
42 # Configure and set up DB.
43 su pleroma -s $SHELL -lc "./bin/pleroma_ctl instance gen \
44 --output /etc/pleroma/config.exs \
45 --output-psql /tmp/setup_db.psql \
46 --domain ${domain} \
47 --instance-name plom-roma \
48 --admin-email ${mail} \
49 --notify-email ${mail} \
50 --dbhost localhost \
51 --dbname pleroma \
52 --dbuser pleroma \
53 --db-configurable N \
54 --rum N \
55 --indexable Y \
56 --uploads-dir /var/lib/pleroma/uploads \
57 --static-dir /var/lib/pleroma/static \
58 --listen-ip 127.0.0.1 \
59 --listen-port 4000 \
60 --dbpass $(pwgen -s 100 1)"
61 su postgres -s $SHELL -lc "psql -f /tmp/setup_db.psql"
62 su pleroma -s $SHELL -lc "./bin/pleroma_ctl migrate"
63
64 # Since the OTP release does not support .secret.exs configuration
65 # files, we hack our own alternative by simply appending custom
66 # configurations to /etc/config.exs.
67 cat "${config_tree_prefix}/other_files/append_pleroma_config" >> /etc/pleroma/config.exs
68
69 # Single-pixel picture hack for removing Pleroma FE images.
70 cp "${config_tree_prefix}/other_files/pixel.png" /var/lib/pleroma/static/
71 chown pleroma:nogroup /var/lib/pleroma/static/pixel.png
72
73 # Info panel and TOS.
74 #mkdir -p /var/lib/pleroma/static/instance
75 #mkdir -p /var/lib/pleroma/static/static
76 #cp "${config_tree_prefix}/other_files/pleroma_panel.html" /var/lib/pleroma/static/instance/panel.html
77 #cp "${config_tree_prefix}/other_files/pleroma_terms-of-service.html" /var/lib/pleroma/static/static/terms-of-service.html
78 #cp "${config_tree_prefix}/other_files/pleroma_robots.txt" /var/lib/pleroma/static/robots.txt
79
80 # Hack to fix <https://git.pleroma.social/pleroma/pleroma/issues/1616>
81 curl https://git.pleroma.social/pleroma/pleroma/-/raw/4271cfb81a8983f5ec6a878cab1fb3fbd164245d/priv/static/static/static-fe.css?inline=false >> /var/lib/pleroma/static/static/static-fe.css
82
83 # Prepare NGINX config for Pleroma.
84 cp /opt/pleroma/installation/pleroma.nginx /etc/nginx/sites-available/pleroma.nginx
85 sed -i "s/example\.tld/${domain}/g" /etc/nginx/sites-available/pleroma.nginx
86 ln -s /etc/nginx/sites-available/pleroma.nginx /etc/nginx/sites-enabled/pleroma.nginx
87
88 # Systemd integration.
89 cp /opt/pleroma/installation/pleroma.service /etc/systemd/system/pleroma.service
90 systemctl start pleroma
91 systemctl enable pleroma
92
93 # Only restart NGINX with Pleroma running.
94 service nginx restart