Skip to content

Instantly share code, notes, and snippets.

@toddbirchard
Last active September 24, 2021 16:57
Show Gist options
  • Save toddbirchard/a5980c3ee251ffe54ff1bf26dd8d10cb to your computer and use it in GitHub Desktop.
Save toddbirchard/a5980c3ee251ffe54ff1bf26dd8d10cb to your computer and use it in GitHub Desktop.
Update Ghost & Add Storage Adapter
#!/bin/bash
PROJECT=$(pwd)
CURRENT_GHOST_VERSION=$(ghost version)
NEW_GHOST_VERSION=$(ghost check-update)
# Ensure latest NPM & Ghost CLI versions
echo "Getting latest version of NPM & Ghost-ClI"
sudo npm install -g npm@latest
sudo npm install -g ghost-cli@latest
if [ ! -z "$NEW_GHOST_VERSION" ]
then
# Update Ghost version to latest
echo "Upgrading $CURRENT_GHOST_VERSION -> $NEW_GHOST_VERSION"
ghost stop
sudo chown -R ghost:ghost ./content
ghost update --no-prompt
# Create storage adapter in `/core` ghost logic (`/current` frequently does not work.)
if [ ! -d "$PROJECT/current/core/server/adapters/storage/gcs/" ]
then
echo "Installing `ghost-v3-google-cloud-storage` in /core/server"
sudo mkdir -p $PROJECT/current/core/server/adapters/storage/
sudo mkdir -p $PROJECT/current/core/server/adapters/storage/gcs/
sudo chown ghost:ghost /var/www/hackers/current/core/server/adapters/storage/gcs/
cd $PROJECT && npm i ghost-v3-google-cloud-storage
cp $PROJECT/node_modules/ghost-v3-google-cloud-storage/* $PROJECT/content/adapters/storage/gcs/
fi
# Create storage adapter in agnostic `/content` directory
if [ ! -d "$PROJECT/content/adapters/storage/gcs/" ]
then
echo "Installing `ghost-v3-google-cloud-storage` in /content"
sudo mkdir -p $PROJECT/content/adapters/
sudo mkdir -p $PROJECT/content/adapters/storage/
sudo mkdir -p $PROJECT/content/adapters/storage/gcs/
sudo chown ghost:ghost $PROJECT/content/adapters/storage/gcs/
cd $PROJECT && npm i ghost-v3-google-cloud-storage
cp $PROJECT/node_modules/ghost-v3-google-cloud-storage/* $PROJECT/content/adapters/storage/gcs/
fi
# Restart Ghost instance
echo "Restarting Ghost"
cd $PROJECT/
ghost restart --verbose
else
echo "NEW_GHOST_VERSION = $CURRENT_GHOST_VERSION"
echo "Ghost $CURRENT_GHOST_VERSION is already up to date."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment