+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 <PATH>"
+ 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 <PATH>"
+ exit 1
+fi
+
+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