Skip to content

Instantly share code, notes, and snippets.

@jeremejazz
Created May 26, 2019 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremejazz/75fb11ab0c6c9cd5e3481a5c753b5eab to your computer and use it in GitHub Desktop.
Save jeremejazz/75fb11ab0c6c9cd5e3481a5c753b5eab to your computer and use it in GitHub Desktop.
Hugo Theme Update Script. Uses git subtree
#!/usr/bin/env bash
# This script will download the latest theme release from the Github repository.
# requires jq
REPO="" # github "user/repo"
GITHUB_USERNAME=""
metas=$(echo $REPO | tr "/" "\n")
THEME_NAME=$(echo $metas | awk '{print $2}')
LATEST=$(curl -u $GITHUB_USERNAME https://api.github.com/repos/$REPO/tags | jq -r ".[0].name")
CURRENT=$(cat THEME_VERSION)
if [ $LATEST = $CURRENT ]; then
echo "Theme is up to date"
exit
fi
echo -n "Current version: $CURRENT Download Latest ($LATEST)? (y/n): "
read answer
echo ""
if [ "$answer" != "${answer#[Yy]}" ] ;then
rm -rf themes/$THEME_NAME
git subtree add --prefix themes/$THEME_NAME --squash https://github.com/$REPO.git $LATEST
#save new version to file
echo $LATEST > THEME_VERSION
echo "Theme downloaded"
else
echo "Download aborted"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment