From d9d1989b62bed7eeed987d6def0ac8ccd6032c5e Mon Sep 17 00:00:00 2001 From: Luc Didry Date: Thu, 11 Oct 2018 10:34:44 +0200 Subject: Use DB informations from config/production.yaml in upgrade script Avoid hardcoded values in upgrade script. Avoid asking for DB password. Uses python (usually installed on your system, even with minimal installations) and some of its standard lib modules. --- scripts/upgrade.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'scripts/upgrade.sh') diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index b29615fb1..c70b3b42a 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -23,8 +23,13 @@ fi # Backup database SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak" +DB_USER=$(node -e "console.log(require('js-yaml').safeLoad(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['username'])") +DB_PASS=$(node -e "console.log(require('js-yaml').safeLoad(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['password'])") +DB_HOST=$(node -e "console.log(require('js-yaml').safeLoad(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['hostname'])") +DB_SUFFIX=$(node -e "console.log(require('js-yaml').safeLoad(fs.readFileSync('$PEERTUBE_PATH/config/production.yaml', 'utf8'))['database']['suffix'])") mkdir -p $PEERTUBE_PATH/backup -pg_dump -U peertube -W -h localhost -F c peertube_prod -f "$SQL_BACKUP_PATH" + +PGPASSWORD=$DB_PASS pg_dump -U $DB_USER -h $DB_HOST -F c "peertube${DB_SUFFIX}" -f "$SQL_BACKUP_PATH" # If there is a pre-release, give the user a choice which one to install. RELEASE_VERSION=$(curl -s https://api.github.com/repos/chocobozzz/peertube/releases/latest | grep tag_name | cut -d '"' -f 4) -- cgit v1.2.3 From 75939291703cf18010495f6b85d6d65e01184235 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Thu, 22 Nov 2018 15:40:49 +0100 Subject: Check free storage before upgrading --- scripts/upgrade.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'scripts/upgrade.sh') diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index c70b3b42a..0a9ce1dab 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -20,6 +20,14 @@ if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.ya exit 1 fi +REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) +ONE_GB=$((1024 * 1024)) +if [ "$REMAINING" -lt "$ONE_GB" ]; then + echo "Error - not enough free space for upgrading" + echo "" + echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" + exit 1 +fi # Backup database SQL_BACKUP_PATH="$PEERTUBE_PATH/backup/sql-peertube_prod-$(date +"%Y%m%d-%H%M").bak" -- cgit v1.2.3 From 5c94c38d18a02864b6f384bcd829a0d3f2d86c4a Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sat, 1 Dec 2018 14:00:07 +0100 Subject: Check if awk and sed are executable --- scripts/upgrade.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'scripts/upgrade.sh') diff --git a/scripts/upgrade.sh b/scripts/upgrade.sh index 0a9ce1dab..4f7c58edd 100755 --- a/scripts/upgrade.sh +++ b/scripts/upgrade.sh @@ -20,13 +20,15 @@ if [ ! -e "$PEERTUBE_PATH/versions" -o ! -e "$PEERTUBE_PATH/config/production.ya exit 1 fi -REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) -ONE_GB=$((1024 * 1024)) -if [ "$REMAINING" -lt "$ONE_GB" ]; then - echo "Error - not enough free space for upgrading" - echo "" - echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" - exit 1 +if [ -x "$(command -v awk)" ] && [ -x "$(command -v sed)" ] ; then + REMAINING=$(df -k $PEERTUBE_PATH | awk '{ print $4}' | sed -n 2p) + ONE_GB=$((1024 * 1024)) + if [ "$REMAINING" -lt "$ONE_GB" ]; then + echo "Error - not enough free space for upgrading" + echo "" + echo "Make sure you have at least 1 GB of free space in $PEERTUBE_PATH" + exit 1 + fi fi # Backup database -- cgit v1.2.3