Skip to content

Instantly share code, notes, and snippets.

@boh717
Last active July 27, 2020 08:58
Show Gist options
  • Save boh717/c8a3ee1f89b0fdc7ee15c06285205881 to your computer and use it in GitHub Desktop.
Save boh717/c8a3ee1f89b0fdc7ee15c06285205881 to your computer and use it in GitHub Desktop.
Script to update self-hosted Ghost blog to its latest version
#!/bin/bash
KillNode() {
NODE_PID=`ps aux | grep [n]ode | awk '{print $2}'`
kill $NODE_PID 2>/dev/null
}
if [ -z $1 ]; then
echo "I need ghost version number as parameter."
echo "Exiting..."
exit
else
GHOST_VERSION=$1
fi
GHOST_DIR=/var/www/ghost
DOWNLOAD_DIR=/var/www
echo "Stopping ghost service"
service ghost stop
echo "Downloading ghost..."
cd ${DOWNLOAD_DIR}
wget https://github.com/TryGhost/Ghost/releases/download/${GHOST_VERSION}/Ghost-${GHOST_VERSION}.zip
echo "Done."
echo "Installing new version..."
unzip -qq Ghost-${GHOST_VERSION}.zip -d ghost-temp
cd ghost/
rm -rf core/
cd ${DOWNLOAD_DIR}/ghost-temp
cp -R core ${GHOST_DIR}
cp index.js ${GHOST_DIR}
cp *.json ${GHOST_DIR}
cd ${GHOST_DIR}
chown -R ghost:ghost *
npm install --production
echo "Done installing."
echo "Trying to start ghost manually..."
echo "Once it's started, check if blog is alive, then press CTRL+C to stop it."
trap KillNode SIGINT
npm start --production
echo "Starting ghost service..."
service ghost start
echo "Cleaning temp files..."
cd ${DOWNLOAD_DIR}
rm Ghost-${GHOST_VERSION}.zip
rm -R ghost-temp
echo "All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment