Last active
April 9, 2023 12:31
-
-
Save fschoenfeldt/aa09dead024d4123a5c73272ee725456 to your computer and use it in GitHub Desktop.
Update Ghost CMS – script on / for uberspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set -v | |
# created by peleke.de | |
# modified by @fschoenfeldt - 27.11.2019 & 09.04.2023 | |
GHOSTDIR=~/blog | |
PACKAGE_VERSION_OLD=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $GHOSTDIR/current/package.json) | |
CURRENT_GHOST=$(curl -s https://api.github.com/repos/TryGhost/Ghost/releases | grep tag_name | head -n 1 | cut -d '"' -f 4) | |
CURRENT_GHOST_DOWNLOAD=$(curl -s https://api.github.com/repos/TryGhost/Ghost/releases/latest | grep zipball_url | cut -d '"' -f 4) | |
CURRENT_GHOST_FILE=$(echo $CURRENT_GHOST_DOWNLOAD | sed 's:.*/::').zip | |
echo "installed version: $PACKAGE_VERSION_OLD" | |
echo "available version: $CURRENT_GHOST" | |
cd $GHOSTDIR | |
if [[ $CURRENT_GHOST != $PACKAGE_VERSION_OLD ]] | |
then | |
read -r -p "Do you want to update Ghost $PACKAGE_VERSION_OLD to version $CURRENT_GHOST? [Y/n] " response | |
if [[ $response =~ ^([yY]|"")$ ]] | |
then | |
echo "downloading and unpacking ghost $CURRENT_GHOST ..." | |
cd $GHOSTDIR/versions/ | |
curl -Lk $CURRENT_GHOST_DOWNLOAD -o $CURRENT_GHOST_FILE | |
unzip $GHOSTDIR/versions/$CURRENT_GHOST_FILE -d $CURRENT_GHOST | |
rm $GHOSTDIR/versions/$CURRENT_GHOST_FILE | |
echo "Updating ghost ..." | |
cd $GHOSTDIR/versions/$CURRENT_GHOST | |
# release zip contains a subdir called `TryGhost-Ghost-<HASH>` | |
# we want all the necessary files in the current directory though | |
mv */* . | |
yarn install --production --prefix ghost/core | |
echo "Migrating ghost database ..." | |
cd $GHOSTDIR | |
NODE_ENV=production knex-migrator migrate --mgpath $GHOSTDIR/versions/$CURRENT_GHOST/ghost/core | |
ln -sfn $GHOSTDIR/versions/$CURRENT_GHOST/ghost/core $GHOSTDIR/current | |
PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' $GHOSTDIR/current/package.json) | |
echo "Ghost $PACKAGE_VERSION_OLD has been updated to version $PACKAGE_VERSION" | |
echo "Restarting Ghost. This may take a few seconds ..." | |
supervisorctl restart blog | |
supervisorctl status | |
echo "If something seems wrong, please check the logs: 'supervisorctl tail ghost'" | |
echo "To revert to version $PACKAGE_VERSION_OLD run the following command: 'ln -sfn $GHOSTDIR/versions/v$PACKAGE_VERSION_OLD $GHOSTDIR/current' and restart ghost using 'supervisorctl restart ghost'." | |
fi | |
else | |
echo "-> Ghost is already up-to-date, no update needed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment