home · contact · privacy
Add PeerTube upgrade script.
authorChristian Heller <c.heller@plomlompom.de>
Wed, 12 Feb 2020 21:23:41 +0000 (22:23 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Wed, 12 Feb 2020 21:23:41 +0000 (22:23 +0100)
buster/setup_scripts/upgrade_peertube.sh [new file with mode: 0755]

diff --git a/buster/setup_scripts/upgrade_peertube.sh b/buster/setup_scripts/upgrade_peertube.sh
new file mode 100755 (executable)
index 0000000..2f434a7
--- /dev/null
@@ -0,0 +1,48 @@
+#!/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