aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-05-16 08:59:05 +0200
committerChocobozzz <me@florianbigard.com>2023-05-16 08:59:05 +0200
commitb30ad9888f54e6b55f3b6ca6e73534227d4d401e (patch)
tree1d0525a4c7cdf90784b24cedb520204b7cc7ed66
parentaa5473314973a1c941546c1ec09108e94a61b3c9 (diff)
downloadPeerTube-b30ad9888f54e6b55f3b6ca6e73534227d4d401e.tar.gz
PeerTube-b30ad9888f54e6b55f3b6ca6e73534227d4d401e.tar.zst
PeerTube-b30ad9888f54e6b55f3b6ca6e73534227d4d401e.zip
Add config file merging in upgrade script
-rwxr-xr-xscripts/upgrade.sh52
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
21fi 21fi
22 22
23if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ] ; then 23if [ -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
32fi 33fi
33 34
34# Backup database 35# Backup database
35if [ -x "$(command -v pg_dump)" ] 36if [ -x "$(command -v pg_dump)" ]; then
36then 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"
45else 50else
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
68unzip -o "peertube-${VERSION}.zip" 73unzip -o "peertube-${VERSION}.zip"
69rm -f "peertube-${VERSION}.zip" 74rm -f "peertube-${VERSION}.zip"
70 75
76RELEASE_PAGE_URL="https://github.com/Chocobozzz/PeerTube/releases/tag/${VERSION}"
77LATEST_VERSION_DIRECTORY="$PEERTUBE_PATH/versions/peertube-${VERSION}"
78cd "$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
72cd "$PEERTUBE_PATH/versions/peertube-${VERSION}"
73NOCLIENT=1 yarn install --production --pure-lockfile 81NOCLIENT=1 yarn install --production --pure-lockfile
74 82
75# Switch to latest code version 83# Switch to latest code version
76rm -rf $PEERTUBE_PATH/peertube-latest 84rm -rf $PEERTUBE_PATH/peertube-latest
77ln -s "$PEERTUBE_PATH/versions/peertube-${VERSION}" $PEERTUBE_PATH/peertube-latest 85ln -s "$LATEST_VERSION_DIRECTORY" $PEERTUBE_PATH/peertube-latest
78cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml 86cp $PEERTUBE_PATH/peertube-latest/config/default.yaml $PEERTUBE_PATH/config/default.yaml
79 87
80echo "Differences in configuration files..." 88echo ""
81cd $PEERTUBE_PATH/versions 89echo "=========================================================="
82diff -u "$(ls -t | head -2 | tail -1)/config/production.yaml.example" "$(ls -t | head -1)/config/production.yaml.example" 90echo ""
91
92if [ -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"
98else
99 echo "git command not found: unable to generate config/production.yaml.new configuration file based on your existing production.yaml configuration"
100fi
83 101
84echo "" 102echo ""
85echo "===========================================" 103echo "=========================================================="
86echo "== Don’t forget to restart PeerTube! ==" 104echo ""
87echo "===========================================" 105echo "Please read the IMPORTANT NOTES on $RELEASE_PAGE_URL"
106echo ""
107echo "Then restart PeerTube!"