5 # <https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/production.md>
7 # <https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/dependencies.md>
9 if [ "$#" -ne 2 ]; then
10 echo 'Need domain name, mail_address as arguments.'
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
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
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
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
38 systemctl start redis postgresql
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'
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"
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
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
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