home · contact · privacy
c92be5cc40f9cb405859bfcf0d2dd2e7bae9f184
[config] / buster / setup_scripts / setup_peertube.sh
1 #!/bin/sh
2 set -e
3
4 # Heavily inspired by
5 # <https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/production.md>
6 # and
7 # <https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/dependencies.md>
8
9 if [ "$#" -ne 2 ]; then
10     echo 'Need domain name, mail_address as arguments.'
11     false
12 fi
13 domain="$1"
14 mail="$2"
15
16 # Install dependencies, set up firewall.
17 config_tree_prefix="${HOME}/config/buster"
18 ./install_for_target.sh peertube
19 ./copy_dirtree.sh "${config_tree_prefix}/etc_files" "" web
20 nft -f /etc/nftables.conf
21
22 # Set up letsencrypt certificate. TODO: Is it auto-renewed?
23 ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
24 certbot --nginx --agree-tos --redirect --no-eff-email -m "${mail}" -d "${domain}"
25 rm /etc/nginx/sites-enabled/default
26
27 # Get NodeJS. See
28 # <https://github.com/nodesource/distributions/blob/master/README.md>
29 curl -sL https://deb.nodesource.com/setup_10.x | bash -
30 apt-get install -y nodejs
31
32 # Get Yarn. See
33 # <https://classic.yarnpkg.com/en/docs/install#debian-stable>
34 curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
35 echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
36 apt update && apt install yarn
37
38 systemctl start redis postgresql
39
40 # Prepare user and DB.
41 useradd -m -d /var/www/peertube -s /bin/bash -p peertube peertube
42 db_pw=$(pwgen -s 100 1)
43 su postgres -lc "psql -c \"CREATE USER peertube WITH PASSWORD '${db_pw}';\""
44 su -l postgres -c 'createdb -O peertube -E UTF8 -T template0 peertube_prod'
45 su -l postgres -c 'psql -c "CREATE EXTENSION pg_trgm;" peertube_prod'
46 su -l postgres -c 'psql -c "CREATE EXTENSION unaccent;" peertube_prod'
47
48 # Install and configure PeerTube from latest version.
49 VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) && echo "Latest Peertube version is $VERSION"
50 cd /var/www/peertube && su -l peertube -c "mkdir config storage versions && cd versions"
51 su -l peertube -c "wget -q 'https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip'"
52 su -l peertube -c "unzip peertube-${VERSION}.zip && rm peertube-${VERSION}.zip"
53 su -l peertube -c "ln -s peertube-${VERSION} ./peertube-latest"
54 su -l peertube -c "cd peertube-latest && yarn install --production --pure-lockfile"
55
56 # Configure PeerTube.
57 cp "${config_tree_prefix}/other_files/peertube_production.yaml" /var/www/peertube/config/production.yaml
58 chown peertube:peertube /var/www/peertube/config/production.yaml
59 sed -i "s/admin\@example\.com/${mail}/g" config/production.yaml
60 sed -i "s/example\.com/${domain}/g" config/production.yaml
61 sed -i "s/password: 'peertube'/password: '${db_pw}'/g" config/production.yaml
62
63 # Configure NGINX.
64 cp /var/www/peertube/peertube-latest/support/nginx/peertube /etc/nginx/sites-available/peertube
65 sed -i "s/peertube.example.com/${domain}/g" /etc/nginx/sites-available/peertube
66 ln -s /etc/nginx/sites-available/peertube /etc/nginx/sites-enabled/peertube
67
68 # Configure systemd and start PeerTube through it.
69 cp /var/www/peertube/peertube-latest/support/systemd/peertube.service /etc/systemd/system/
70 systemctl daemon-reload
71 systemctl enable peertube
72 systemctl start peertube
73
74 # Restart NGINX.
75 service nginx restart