Last active
September 7, 2018 06:42
-
-
Save kaushalmodi/9fd32d25b64511b1242a3b1b47a4fa84 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| # Time-stamp: <2017-10-23 12:14:47 kmodi> | |
| # Hugo build script.. for hugo version build after switching to Go dep. | |
| # (v0.31-DEV+) | |
| # Usage: ./hugo_mybuild.sh # Installs using origin/master | |
| # ./hugo_mybuild.sh --rev v0.30.2 | |
| #${GOPATH}/src/github.com/gohugoio/hugo/README.md | |
| # http://matthewkwilliams.com/index.php/2014/09/28/go-executables-are-statically-linked-except-when-they-are-not/ | |
| set -euo pipefail # http://redsymbol.net/articles/unofficial-bash-strict-mode | |
| IFS=$'\n\t' | |
| here=$(pwd) | |
| hugo_rev="origin/master" | |
| while [ $# -gt 0 ] | |
| do | |
| case "$1" in | |
| "-r"|"--rev" ) shift | |
| hugo_rev="$1";; | |
| * ) echo >&2 "Error: Invalid option: $*" | |
| esac | |
| shift # expose next argument | |
| done | |
| # If ${hugo_rev} is origin/master, ${hugo_rev_basename} = master | |
| # If ${hugo_rev} is v0.30.2, ${hugo_rev_basename} = v0.30.2 | |
| hugo_rev_basename=$(basename "${hugo_rev}") | |
| dep_src="github.com/golang/dep/cmd/dep" | |
| hugo_src="github.com/gohugoio/hugo" | |
| chroma_src="github.com/alecthomas/chroma" | |
| export CGO_ENABLED=0 | |
| export GO_EXTLINK_ENABLED=0 | |
| # Install hugo for the first time so that the ${GOPATH}/src/${hugo_src} | |
| # directory gets populated. | |
| if [[ ! -d "${GOPATH}/src/${hugo_src}" ]] || ( ! hash hugo 2>/dev/null ) | |
| then | |
| go get -u -v ${hugo_src} | |
| fi | |
| # cd to the hugo source directory to update to the needed version. | |
| cd "${GOPATH}/src/${hugo_src}" || exit | |
| git fetch --all # fetch new branch names if any | |
| git reset --hard "${hugo_rev}" | |
| git checkout "${hugo_rev_basename}" | |
| git reset --hard "${hugo_rev}" | |
| echo "" | |
| # Synchronize all the dependent packages | |
| if ! hash dep 2>/dev/null | |
| then | |
| go get -u -v "${dep_src}" | |
| fi | |
| dep ensure | |
| hugo_commithash=$(git rev-parse --short HEAD 2>/dev/null) | |
| builddate=$(date +%FT%T%z) | |
| # Update dependent packages from their master branches if building hugo from its | |
| # master branch. | |
| if [[ "${hugo_rev_basename}" == "master" ]] | |
| then | |
| # https://discourse.gohugo.io/t/building-hugo-with-the-latest-version-of-chroma/8543/2?u=kaushalmodi | |
| go get -u -v ${chroma_src}/... | |
| rm -rf "${GOPATH}/src/${hugo_src}/vendor/${chroma_src}" | |
| chroma_commithash=$(cd "${GOPATH}/src/${chroma_src}" && git rev-parse --short HEAD 2>/dev/null) | |
| hugo_commithash="${hugo_commithash}:chroma-${chroma_commithash}" | |
| fi | |
| cmd="go build -v \ | |
| -ldflags \"-X ${hugo_src}/hugolib.CommitHash=${hugo_commithash} \ | |
| -X ${hugo_src}/hugolib.BuildDate=${builddate}\" \ | |
| ${hugo_src}" | |
| echo "${cmd}" | |
| eval "${cmd}" | |
| hugo_install_dir="${STOW_PKGS_ROOT}/hugo/${hugo_rev_basename}" | |
| mkdir -p "${hugo_install_dir}/bin" | |
| cp -f ./hugo "${hugo_install_dir}/bin/." # We are still in ${GOPATH}/src/${hugo_src} | |
| # Version check | |
| "${hugo_install_dir}"/bin/hugo version | |
| cd "${here}" || exit | |
| echo "" | |
| echo "Now update the '~/scripts/bash/stow_it.sh' script and rerun that script if needed." | |
| echo " That would be needed if you are installing 'hugo' for the first time, or changing the version." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for making this available. My install script stopped working after the extended versions became available, so I will try your techniques as a starting point, @kaushalmodi.