Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to upgrade your Ghost blog installation to the latest version
#!/bin/bash
# Make sure only root can run our script
if [[ ${EUID} -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
OLD_PWD=$(pwd)
cd /var/www/
# Get current Ghost version
OLD_VERSION=$(node -pe "JSON.parse(require('fs').readFileSync('/dev/stdin').toString()).version" < ghost/package.json)
echo "Upgrading Ghost"
echo -n "Fetching ... "
curl -LOk https://ghost.org/zip/ghost-latest.zip > upgrade.log 2>&1 || exit
echo "Unzipping ..."
unzip ghost-latest.zip -d ghost-latest >> upgrade.log 2>&1 || exit
# Get new Ghost version
NEW_VERSION=$(node -pe "JSON.parse(require('fs').readFileSync('/dev/stdin').toString()).version" < ghost-latest/package.json)
echo "Upgrading from ${OLD_VERSION} to ${NEW_VERSION}. Please wait ..."
sudo -u ghost pm2 stop ghost
mv -v ghost/core ghost-${OLD_VERSION}-core || exit
cp -v ghost-latest/{*.js,*.json,*.md,LICENSE} ghost/ || exit
cp -R -v ghost-latest/core ghost/ || exit
cp -R -v ghost-latest/content/themes/casper ghost/content/themes || exit
cd ghost
npm install --production
# chown -R ghost:www-data ./*
cd ${OLD_PWD}
sudo -u ghost pm2 start ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.