diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/upgrade.sh | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 9949ebbc4..86135fcc9 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh | |||
@@ -20,27 +20,32 @@ if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.ya | |||
20 | exit 1 | 20 | exit 1 |
21 | fi | 21 | fi |
22 | 22 | ||
23 | if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ] ; then | 23 | if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ]; then |
24 | REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) | 24 | REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) |
25 | ONE_GB=$((1024 * 1024)) | 25 | ONE_GB=$((1024 * 1024)) |
26 | |||
26 | if [ "$REMAINING" -lt "$ONE_GB" ]; then | 27 | if [ "$REMAINING" -lt "$ONE_GB" ]; then |
27 | echo "Error - not enough free space for upgrading" | 28 | echo "Error - not enough free space for upgrading" |
28 | echo "" | 29 | echo "" |
29 | echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" | 30 | echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" |
30 | exit 1 | 31 | exit 1 |
31 | fi | 32 | fi |
32 | fi | 33 | fi |
33 | 34 | ||
34 | # Backup database | 35 | # Backup database |
35 | if [ -x "$(command -v pg_dump)" ] | 36 | if [ -x "$(command -v pg_dump)" ]; then |
36 | then | 37 | mkdir -p $PEERTUBE_PATH/backup |
38 | |||
37 | SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak" | 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 | |||
38 | DB_USER=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['username'])") | 43 | DB_USER=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['username'])") |
39 | DB_PASS=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['password'])") | 44 | DB_PASS=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['password'])") |
40 | DB_HOST=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['hostname'])") | 45 | DB_HOST=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['hostname'])") |
41 | DB_SUFFIX=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['suffix'])") | 46 | DB_SUFFIX=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['suffix'])") |
42 | DB_NAME=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['name'] || '')") | 47 | DB_NAME=$(node -e "console.log(require('js-yaml').load(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['name'] || '')") |
43 | mkdir -p $PEERTUBE_PATH/backup | 48 | |
44 | PGPASSWORD=$DB_PASS pg_dump -U $DB_USER -h $DB_HOST -F c "${DB_NAME:-peertube${DB_SUFFIX}}" -f "$SQL_BACKUP_PATH" | 49 | PGPASSWORD=$DB_PASS pg_dump -U $DB_USER -h $DB_HOST -F c "${DB_NAME:-peertube${DB_SUFFIX}}" -f "$SQL_BACKUP_PATH" |
45 | else | 50 | else |
46 | echo "pg_dump not found. Cannot make a SQL backup!" | 51 | echo "pg_dump not found. Cannot make a SQL backup!" |
@@ -68,20 +73,35 @@ cd $PEERTUBE_PATH/versions | |||
68 | unzip -o "peertube-${VERSION}.zip" | 73 | unzip -o "peertube-${VERSION}.zip" |
69 | rm -f "peertube-${VERSION}.zip" | 74 | rm -f "peertube-${VERSION}.zip" |
70 | 75 | ||
76 | RELEASE_PAGE_URL="https://github.com/Chocobozzz/PeerTube/releases/tag/${VERSION}" | ||
77 | LATEST_VERSION_DIRECTORY="$PEERTUBE_PATH/versions/peertube-${VERSION}" | ||
78 | cd "$LATEST_VERSION_DIRECTORY" | ||
79 | |||
71 | # Launch yarn to check if we have all required dependencies | 80 | # Launch yarn to check if we have all required dependencies |
72 | cd "$PEERTUBE_PATH/versions/peertube-${VERSION}" | ||
73 | NOCLIENT=1 yarn install --production --pure-lockfile | 81 | NOCLIENT=1 yarn install --production --pure-lockfile |
74 | 82 | ||
75 | # Switch to latest code version | 83 | # Switch to latest code version |
76 | rm -rf $PEERTUBE_PATH/peertube-latest | 84 | rm -rf $PEERTUBE_PATH/peertube-latest |
77 | ln -s "$PEERTUBE_PATH/versions/peertube-${VERSION}" $PEERTUBE_PATH/peertube-latest | 85 | ln -s "$LATEST_VERSION_DIRECTORY" $PEERTUBE_PATH/peertube-latest |
78 | cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml | 86 | cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml |
79 | 87 | ||
80 | echo "Differences in configuration files..." | 88 | echo "" |
81 | cd $PEERTUBE_PATH/versions | 89 | echo "==========================================================" |
82 | diff -u "$(ls -t | head -2 | tail -1)/config/production.yaml.example" "$(ls -t | head -1)/config/production.yaml.example" | 90 | echo "" |
91 | |||
92 | if [ -x "$(command -v git)" ]; then | ||
93 | cd /var/www/peertube | ||
94 | |||
95 | 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 | ||
96 | echo "/var/www/peertube/config/production.yaml.new generated" | ||
97 | echo "You can review it and replace your existing production.yaml configuration" | ||
98 | else | ||
99 | echo "git command not found: unable to generate config/production.yaml.new configuration file based on your existing production.yaml configuration" | ||
100 | fi | ||
83 | 101 | ||
84 | echo "" | 102 | echo "" |
85 | echo "===========================================" | 103 | echo "==========================================================" |
86 | echo "== Don’t forget to restart PeerTube! ==" | 104 | echo "" |
87 | echo "===========================================" | 105 | echo "Please read the IMPORTANT NOTES on $RELEASE_PAGE_URL" |
106 | echo "" | ||
107 | echo "Then restart PeerTube!" | ||