From 78549e9d13647d428932b3cacb736359ce243145 Mon Sep 17 00:00:00 2001 From: h3artbl33d <1+h3artbl33d@noreply.code.exqusite.network> Date: Tue, 4 Aug 2026 22:09:38 +0200 Subject: [PATCH] Add peertube-upgrade.sh Added additional checks for FreeBSD and HardenedBSD --- upgrade.sh | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 upgrade.sh diff --git a/upgrade.sh b/upgrade.sh new file mode 100644 index 0000000..c29dd78 --- /dev/null +++ b/upgrade.sh @@ -0,0 +1,163 @@ +#!/bin/sh + +set -eu + +PEERTUBE_PATH=${1:-/var/www/peertube} + +if [ ! -e "$PEERTUBE_PATH" ]; then + echo "Error - path \"$PEERTUBE_PATH\" wasn't found" + echo "" + echo "If peertube was installed in another path, you can specify it with" + echo " ./upgrade.sh " + exit 1 +fi + +if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.yaml" ]; then + echo "Error - Couldn't find peertube installation in \"$PEERTUBE_PATH\"" + echo "" + echo "If peertube was installed in another path, you can specify it with" + echo " ./upgrade.sh " + exit 1 +fi + +if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ]; then + REMAINING=$(df -k "$PEERTUBE_PATH" | awk '{ print $4}' | sed -n 2p) + THREE_GB=$((3 * 1024 * 1024)) + + if [ "$REMAINING" -lt "$THREE_GB" ]; then + echo "Error - not enough free space for upgrading" + echo "" + echo "Make sure you have at least 3 GB of free space in $PEERTUBE_PATH" + exit 1 + fi +fi + +# Backup database +if [ -x "$(command -v pg_dump)" ]; then + mkdir -p "$PEERTUBE_PATH/backup" + + SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak" + + echo "Backing up PostgreSQL database in $SQL_BACKUP_PATH" + +read DB_HOST DB_SUFFIX DB_NAME DB_USER DB_PASS DB_PORT < /dev/null; then + echo "You are running HardenedBSD. You might want to set the proper PaX options for node." +fi + +rm -f "$PEERTUBE_PATH/peertube-latest" +ln -s "$LATEST_VERSION_DIRECTORY" "$PEERTUBE_PATH/peertube-latest" + +RESOLVED_TARGET=$(cd -P "$PEERTUBE_PATH/peertube-latest" 2>/dev/null && pwd) || RESOLVED_TARGET="" +EXPECTED_TARGET=$(cd -P "$LATEST_VERSION_DIRECTORY" 2>/dev/null && pwd) || { + echo "Error - could not resolve $LATEST_VERSION_DIRECTORY" + exit 1 +} + +if [ -z "$RESOLVED_TARGET" ] || [ "$RESOLVED_TARGET" != "$EXPECTED_TARGET" ]; then + echo "Error - peertube-latest symlink is broken after update" + echo " Expected : $EXPECTED_TARGET" + echo " Resolved : ${RESOLVED_TARGET:-}" + exit 1 +fi + +cp "$PEERTUBE_PATH/peertube-latest/config/default.yaml" "$PEERTUBE_PATH/config/default.yaml" + +echo "" +echo "==========================================================" +echo "" + +if [ -x "$(command -v git)" ]; then + cd "$PEERTUBE_PATH" + + git merge-file -p config/production.yaml "$OLD_VERSION_DIRECTORY/config/production.yaml.example" "peertube-latest/config/production.yaml.example" | tee "config/production.yaml.new" > /dev/null + echo "$PEERTUBE_PATH/config/production.yaml.new generated" + echo "You can review it and replace your existing production.yaml configuration" +else + echo "git command not found: unable to generate config/production.yaml.new configuration file based on your existing production.yaml configuration" +fi + +echo "" +echo "==========================================================" +echo "" +echo "Please read the IMPORTANT NOTES on $RELEASE_PAGE_URL" +echo "" +echo "Then restart PeerTube!" \ No newline at end of file