--- /dev/null
+#!/bin/sh
+set -e
+
+# Heavily inspired by
+# <https://docs.joinpeertube.org/#/install-any-os?id=upgrade>
+
+# backup DB
+SQL_BACKUP_PATH="backup/sql-peertube_prod-$(date -Im).bak"
+cd /var/www/peertube/
+su peertube -c 'mkdir -p backup'
+su postgres -c "pg_dump -F c peertube_prod" | su peertube -c "tee ${SQL_BACKUP_PATH}" > /dev/null
+
+# Get new PeerTube version.
+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"
+cd /var/www/peertube/versions
+su peertube -c "wget -q \"https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip\""
+su peertube -c "unzip -o peertube-${VERSION}.zip && rm peertube-${VERSION}.zip"
+
+# Yarn new PeerTube.
+su -l peertube -c "cd /var/www/peertube/versions/peertube-${VERSION} && yarn install --production --pure-lockfile"
+
+# Copy new default.yaml (TODO: find out what it does)
+su peertube -c "cp /var/www/peertube/versions/peertube-${VERSION}/config/default.yaml /var/www/peertube/config/default.yaml"
+
+set +e
+echo
+echo "Check differences between new and old production.yaml[.example]"
+diff /var/www/peertube/versions/peertube-${VERSION}/config/production.yaml.example /var/www/peertube/config/production.yaml
+echo
+set -e
+
+# Link new PeerTube as latest one.
+cd /var/www/peertube
+unlink ./peertube-latest
+su peertube -c "ln -s versions/peertube-${VERSION} ./peertube-latest"
+
+set +e
+echo
+echo "Check differences between new and old NGINX files"
+cd /var/www/peertube/versions
+diff "$(ls --sort=t | head -2 | tail -1)/support/nginx/peertube" "$(ls --sort=t | head -1)/support/nginx/peertube"
+echo
+echo "Check differences between new and old systemd unit files"
+diff "$(ls --sort=t | head -2 | tail -1)/support/systemd/peertube.service" "$(ls --sort=t | head -1)/support/systemd/peertube.service"
+echo
+set -e
+
+service peertube restart