aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/upgrade.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/upgrade.sh')
-rwxr-xr-xscripts/upgrade.sh108
1 files changed, 0 insertions, 108 deletions
diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh
deleted file mode 100755
index 64c7e1581..000000000
--- a/scripts/upgrade.sh
+++ /dev/null
@@ -1,108 +0,0 @@
1#!/bin/sh
2
3set -eu
4
5PEERTUBE_PATH=${1:-/var/www/peertube}
6
7if [ ! -e "$PEERTUBE_PATH" ]; then
8 echo "Error - path \"$PEERTUBE_PATH\" wasn't found"
9 echo ""
10 echo "If peertube was installed in another path, you can specify it with"
11 echo " ./upgrade.sh <PATH>"
12 exit 1
13fi
14
15if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.yaml" ]; then
16 echo "Error - Couldn't find peertube installation in \"$PEERTUBE_PATH\""
17 echo ""
18 echo "If peertube was installed in another path, you can specify it with"
19 echo " ./upgrade.sh <PATH>"
20 exit 1
21fi
22
23if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ]; then
24 REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p)
25 ONE_GB=$((1024 * 1024))
26
27 if [ "$REMAINING" -lt "$ONE_GB" ]; then
28 echo "Error - not enough free space for upgrading"
29 echo ""
30 echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH"
31 exit 1
32 fi
33fi
34
35# Backup database
36if [ -x "$(command -v pg_dump)" ]; then
37 mkdir -p $PEERTUBE_PATH/backup
38
39 SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak"
40
41 echo "Backing up PostgreSQL database in $SQL_BACKUP_PATH"
42
43 DB_USER=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['username'])")
44 DB_PASS=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['password'])")
45 DB_HOST=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['hostname'])")
46 DB_PORT=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['port'])")
47 DB_SUFFIX=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['suffix'])")
48 DB_NAME=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['name'] || '')")
49
50 PGPASSWORD=$DB_PASS pg_dump -U $DB_USER -p $DB_PORT -h $DB_HOST -F c "${DB_NAME:-peertube${DB_SUFFIX}}" -f "$SQL_BACKUP_PATH"
51else
52 echo "pg_dump not found. Cannot make a SQL backup!"
53fi
54
55# If there is a pre-release, give the user a choice which one to install.
56RELEASE_VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4)
57PRE_RELEASE_VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases | grep tag_name | head -1 | cut -d '"' -f 4)
58
59if [ "$RELEASE_VERSION" != "$PRE_RELEASE_VERSION" ]; then
60 echo -e "Which version do you want to install?\n[1] $RELEASE_VERSION (stable) \n[2] $PRE_RELEASE_VERSION (pre-release)"
61 read choice
62 case $choice in
63 [1]* ) VERSION="$RELEASE_VERSION";;
64 [2]* ) VERSION="$PRE_RELEASE_VERSION";;
65 * ) exit;
66 esac
67else
68 VERSION="$RELEASE_VERSION"
69fi
70
71echo "Installing Peertube version $VERSION"
72wget -q "https://github.com/Chocobozzz/PeerTube/releases/download/${VERSION}/peertube-${VERSION}.zip" -O "$PEERTUBE_PATH/versions/peertube-${VERSION}.zip"
73cd $PEERTUBE_PATH/versions
74unzip -o "peertube-${VERSION}.zip"
75rm -f "peertube-${VERSION}.zip"
76
77RELEASE_PAGE_URL="https://github.com/Chocobozzz/PeerTube/releases/tag/${VERSION}"
78LATEST_VERSION_DIRECTORY="$PEERTUBE_PATH/versions/peertube-${VERSION}"
79cd "$LATEST_VERSION_DIRECTORY"
80
81# Launch yarn to check if we have all required dependencies
82NOCLIENT=1 yarn install --production --pure-lockfile
83
84# Switch to latest code version
85rm -rf $PEERTUBE_PATH/peertube-latest
86ln -s "$LATEST_VERSION_DIRECTORY" $PEERTUBE_PATH/peertube-latest
87cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml
88
89echo ""
90echo "=========================================================="
91echo ""
92
93if [ -x "$(command -v git)" ]; then
94 cd /var/www/peertube
95
96 git merge-file -p config/production.yaml "$LATEST_VERSION_DIRECTORY/config/production.yaml.example" "peertube-latest/config/production.yaml.example" | tee "config/production.yaml.new" > /dev/null
97 echo "/var/www/peertube/config/production.yaml.new generated"
98 echo "You can review it and replace your existing production.yaml configuration"
99else
100 echo "git command not found: unable to generate config/production.yaml.new configuration file based on your existing production.yaml configuration"
101fi
102
103echo ""
104echo "=========================================================="
105echo ""
106echo "Please read the IMPORTANT NOTES on $RELEASE_PAGE_URL"
107echo ""
108echo "Then restart PeerTube!"