Installing dev hugo

Hi - I’m using this zsh function to upgrade hugo:

hugodevinstall (){
  cd $HOME
  echo "==Move current hugo to hugo-prev in case of need to revert=="
  mv $HOME/gocode/bin/hugo $HOME/gocode/bin/hugo-prev
  echo "==Upgrading Hugo Source=="
  go get -u -v
  echo "==Get newly installed hugo version=="
  $HOME/gocode/bin/hugo version
  echo "==Compile new hugo=="
  cd $HOME/gocode/src/
  make hugo
  echo "==Get version string and move hugo into position=="
  _newhugoverstr=$($HOME/gocode/src/ version | awk -F ' ' '{ print $5 }')
  mv $HOME/gocode/src/ $HOME/gocode/bin/hugo-${_newhugoverstr}
  cd $HOME/gocode/bin
  ln -sf $HOME/gocode/bin/hugo-${_newhugoverstr} hugo
  cd $HOME
  echo "==Sanity check - compare versions=="
  echo "Expecting: ${_newhugoverstr}"
  echo "Actual: "
  hugo version

I have GOPATH=/Users/rcogley/gocode, and my go version is 1.8.1. This function script worked when I had not upgraded for a while, but, today I thought I’d run it with the idea that I’d get the latest, but, I think that some things have changed.

This is what it returns when I run it now:

==Move current hugo to hugo-prev in case of need to revert==
overwrite /Users/rcogley/gocode/bin/hugo-prev? (y/n [n]) y
==Upgrading Hugo Source== (download)
# cd /Users/rcogley/gocode/src/; git pull --ff-only
   b332d93e..718c0e14  master       -> origin/master
 + b41518ed...92a51a53 release-docs -> origin/release-docs  (forced update)
 * [new branch]        v0.18.1rb    -> origin/v0.18.1rb
 * [new branch]        v0.20.5rb    -> origin/v0.20.5rb
 * [new branch]        v0.20.6rb    -> origin/v0.20.6rb
 * [new tag]           v0.20.5      -> v0.20.5
 * [new tag]           v0.20.6      -> v0.20.6
error: Your local changes to the following files would be overwritten by merge:
Please commit your changes or stash them before you merge.
Updating b5e32eb6..718c0e14
package exit status 1
  0.27s user 0.97s system 51% cpu 2.406 total
==Get newly installed hugo version==
hugodevinstall:7: no such file or directory: /Users/rcogley/gocode/bin/hugo
==Compile new hugo==
go get
govendor sync
go build -ldflags "-X`git rev-parse --short HEAD 2>/dev/null` -X`date +%FT%T%z`"
  1.25s user 0.66s system 88% cpu 2.165 total
==Get version string and move hugo into position==
overwrite /Users/rcogley/gocode/bin/hugo-v0.21-DEV-B5E32EB6? (y/n [n]) y
==Sanity check - compare versions==
Expecting: v0.21-DEV-B5E32EB6
Hugo Static Site Generator v0.21-DEV-B5E32EB6 darwin/amd64 BuildDate: 2017-04-27T19:10:01+09:00

Well, nothing changes and I just want to understand the best practice for getting the latest, doing an upgrade and so on.

Can someone please advise, if you happen to have a stable script for upgrade?

Thank you in advance. :slightly_smiling:

おはようございます @RickCogley

Have you tried installing Hugo since we move to govendor? I had to work out some quirks (self-imposed) with my path, but this is what I’m currently using to install from source on macOS.

(Same info on as well as the docs concept above.)

I install the dev version of hugo using a little bash script. I had written a blog post about it. Everything in that script would apply to you, except that you can comment out govendor fetch if you do not care about using the latest version of the goorgeous package.

Thanks @rdwatters and @kaushalmodi, much appreciated. I’ll give those a “go”. (I’m easily amused).

The main docs site is not as detailed as the hugodocs site in this respect. I should have looked there.

@kaushalmodi hi, your bash script helped me a lot. Could you please advise what is the purpose of the -ldflags?

go install -v \
   -ldflags "-X ${package}/hugolib.CommitHash=${commithash} \
             -X ${package}/hugolib.BuildDate=${builddate}" \

I assume that that bakes in the commit hash and build date somewhere, but, where can I view those?

hugo version and hugo env show those values.

Thanks @bep :slightly_smiling:

They also populate the internal CommitHash and BuildDate variables which I use I like this in my HTML headers:

    <!-- Hugo info -->
    {{ printf "<!--Hugo Build Date: %s-->" .Hugo.BuildDate | safeHTML }}
    {{ printf "<!--Hugo Commit Hash: %s-->" .Hugo.CommitHash | safeHTML }}

and that shows up like this when I view the page sources of my blog:

  • Use of this in my theme
1 Like

@kaushalmodi, right, thanks!