Skip to content

Instantly share code, notes, and snippets.

Forked from anonymous/
Last active January 6, 2016 23:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tdack/21e85367663a44dd527c to your computer and use it in GitHub Desktop.
Bash script to upgrade your Ghost blog installation to the latest version
# 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
if [[ $# -eq 0 ]]; then
echo "Usage:"
echo " $0 <systemd|sysv>"
echo -e "\n systemd : use systemd/systemctl to stop/start services"
echo " sysv : use /etc/init.d syvs init system to stop/start services"
case "$1" in
INIT_START="sudo systemctl start ghost.service"
INIT_STOP ="sudo systemctl stop ghost.service"
INIT_START="sudo service ghost start"
INIT_STOP ="sudo service ghost stop"
# Get current Ghost version
OLD_VERSION=$(node -pe "JSON.parse(require('fs').readFileSync('/dev/stdin').toString()).version" < ghost/package.json)
echo "Upgrading Ghost"
rm -fr ghost-latest
echo -n "Fetching ... "
curl -LOk > upgrade.log 2>&1 || exit
echo "Unzipping ..."
unzip -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 ..."
# Stop Ghost
# Backup the current version core files
mv -v ghost/core ghost-${OLD_VERSION}-core || exit
# Update with new files
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
# Update nodejs modules as required
npm install --production
# Fix permissions
chown -R ghost:www-data ./*
# Restart Ghost
cd ${OLD_PWD}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment