Simple script to update self hosted Ghost.org blogging platform

NOTE: Since the release of ghost 1.0 this guide is deprecated!

This is a quick script to automate the update process of the self hosted Ghost.Org platform.
This script is based on the guide found here.

The “APP_INIT” part of the script is based on chovy’s script found here, I have saved it as nodejs.sh as referenced in the script below.

Instructions:

  1. Save the script
  2. Edit the USER,APP_DIR,APP_INIT,UNPACK_DIR variables to match your installation
  3. Make the script executable (chmod +x update_ghost.sh)
  4. Run it

The script:

#!/bin/bash
## Script to automatically update ghost.org
## Written by Drakfot

### Variables
USER=“USER_RUNNING_GHOST”
APP_DIR=“PATH_TO_GHOST_DIR”
APP_INIT="/etc/init.d/nodejs.sh"
UNPACK_DIR="/tmp/ghost_unpacked"
DOWNLOAD_URL="https://ghost.org/zip/ghost-latest.zip"

### Stop the node process prior to updating the files
$APP_INIT stop

### Download latest ghost and extract to /tmp
## Remove previous file, if exists
if [ -f /tmp/ghost-latest.zip ]; then
	echo "Removing previous file."
	/bin/rm /tmp/ghost-latest.zip
fi

## Download and extract ghost
/usr/bin/wget -P /tmp/ -c $DOWNLOAD_URL
/usr/bin/unzip /tmp/ghost-latest.zip -d /tmp/ghost_unpacked

## Backup important files before updating
/bin/tar -cf $APP_DIR/files_backup.tar $APP_DIR/content $APP_DIR/config.js

## Delete ghost core directory
/bin/rm -rf $APP_DIR/core

## Move over the new files to the ghost dir
/bin/cp -fr $UNPACK_DIR/* $APP_DIR/
/bin/rm -rf $UNPACK_DIR
/bin/tar -xf $APP_DIR/files_backup.tar

## Change owner on files
/bin/chown -R $USER:$USER $APP_DIR

## clear out node_modules and npm cache before updating dependencies
cd $APP_DIR
/bin/rm -rf $APP_DIR/node_modules
/usr/local/bin/npm cache clean
/usr/local/bin/npm install --production

## Start ghost again.
$APP_INIT start

### License ###
#Simple script to automate the update process of the self-hosted version of the Ghost.Org blogging platform.
#Copyright (C) 2016  J. Sten. 
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software Foundation,
#Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
#
#https://gnu.org/licenses/gpl.html
Mastodon