Skip to content

Instantly share code, notes, and snippets.

@quangtt-rks
Last active April 21, 2017 08:55
Show Gist options
  • Save quangtt-rks/fcb9e2375c228fb45afeb32333c8203e to your computer and use it in GitHub Desktop.
Save quangtt-rks/fcb9e2375c228fb45afeb32333c8203e to your computer and use it in GitHub Desktop.
Auto upgrade Ghost blog (version 0.x.x). Tired of typing so many commands when upgrading? Write your own script!
#!/bin/sh
# This script works only on my system, edit it before apply to your system!
echo "\n Ghost Upgrader"
waiting_sign=" ⌛"
okay_sign=" ✓"
ng_sign=" ✗"
ghost_dir="/var/www/ghost"
echo "\n$waiting_sign Checking for updates..."
rm ghost-latest.zip >/dev/null 2>&1
rm -rf ghost-latest
cd && curl -LOk https://ghost.org/zip/ghost-latest.zip >/dev/null 2>&1
unzip ~/ghost-latest.zip -d ghost-latest >/dev/null 2>&1
latest_version=$(grep -Po '"version":(\d*?,|.*?[^\\]",)' ~/ghost-latest/package.json)
current_version=$(grep -Po '"version":(\d*?,|.*?[^\\]",)' "$ghost_dir/package.json")
if [ "$latest_version" = "$current_version" ]
then
printf "$okay_sign You already have the latest version.\n"
else
echo "\n Updates found!"
read -p " Do you want to upgrade to newest version? ([Nn] to exit, otherwise to proceed): " wantit
case $wantit in [Nn])
echo "\n Bye!"
exit 0
esac
printf "\n$waiting_sign Backing up [content] folder..."
echo y | rm -rf "$ghost_dir/content-backup"
cp -a "$ghost_dir/content" "$ghost_dir/content-backup"
printf "$okay_sign"
printf "\n$waiting_sign Removing [core] folder..."
echo y | exec sudo rm -rf "$ghost_dir/core"
printf "$okay_sign"
printf "\n$waiting_sign Removing [index.js]..."
echo y | rm "$ghost_dir/index.js" >/dev/null 2>&1
printf "$okay_sign"
printf "\n$waiting_sign Removing *.json files..."
echo y | rm "$ghost_dir/package.json" >/dev/null 2>&1
echo y | rm "$ghost_dir/npm-shrinkwrap.json" >/dev/null 2>&1
printf "$okay_sign"
printf "\n$waiting_sign Removing *.md files..."
echo y | rm "$ghost_dir/README.md" >/dev/null 2>&1
echo y | rm "$ghost_dir/PRIVACY.md" >/dev/null 2>&1
printf "$okay_sign"
printf "\n$waiting_sign Removing [node_modules] folder..."
echo y | rm -rf "$ghost_dir/node_modules"
printf "$okay_sign"
printf "\n$waiting_sign Copying new [core] folder..."
cp -a ~/ghost-latest/core "$ghost_dir"
printf "$okay_sign"
printf "\n$waiting_sign Copying new [index.js]..."
cp ~/ghost-latest/index.js "$ghost_dir"
printf "$okay_sign"
printf "\n$waiting_sign Copying new *.json files..."
cp ~/ghost-latest/*.json "$ghost_dir"
printf "$okay_sign"
printf "\n$waiting_sign Copying new *.md files..."
cp ~/ghost-latest/*.md "$ghost_dir"
printf "$okay_sign"
echo "\n"
read -p "[!] Do you want to overwrite [Casper theme] with the new one? ([y] to confirm, otherwise to skip) " reply
case $reply in [Yy])
printf "\n$waiting_sign Copying new [Casper] theme files..."
cp -R ~/ghost-latest/content/themes/casper "$ghost_dir/content/themes"
printf "$okay_sign"
esac
printf "\n$waiting_sign Clear cpm cache..."
cd "$ghost_dir" && npm cache clean
printf "$okay_sign"
printf "\n$waiting_sign Running [npm install --production]...\n"
cd "$ghost_dir" && npm install --production
printf "\n$waiting_sign Restarting Ghost service..."
exec sudo service ghost restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment