Skip to content

Instantly share code, notes, and snippets.

@holehan
Last active January 8, 2024 12:26
Show Gist options
  • Save holehan/4b1cff4ae00e19094f5ba8aafd831b8c to your computer and use it in GitHub Desktop.
Save holehan/4b1cff4ae00e19094f5ba8aafd831b8c to your computer and use it in GitHub Desktop.
Install and update hugo extdended on linux 64bit including man pages and bash completion
#!/bin/bash
# Change to temporary directory
pushd /tmp/
# Get latest hugo version
if test -f "$HOME/.local/bin/hugo"; then
_currentver=$(hugo version | grep -m 1 -Eo '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}')
else
_currentver="Not installed"
fi
_latestver=$(curl --silent -N "https://api.github.com/repos/gohugoio/hugo/tags" | grep -m 1 -Eo '[0-9]{1,}\.[0-9]{1,}\.[0-9]{1,}')
echo "Latest version: $_latestver"
echo "Current version: $_currentver"
if [ "$_latestver" != "$_currentver" ]; then
echo "Downloading hugo v${_latestver}"
curl -L "https://github.com/gohugoio/hugo/releases/download/v${_latestver}/hugo_extended_${_latestver}_Linux-64bit.tar.gz" --progress-bar >hugo_extended_${_latestver}_Linux-64bit.tar.gz
echo "Extracting hugo binary..."
tar xvfz hugo_extended_${_latestver}_Linux-64bit.tar.gz hugo
# Make hugo binary executable
echo "Making hugo executable..."
chmod +x hugo
# Move hugo binary to a location that is already in your PATH
echo "Moving hugo to ~/.local/bin..."
mv hugo $HOME/.local/bin/
# Install man pages
echo "Installing man pages..."
mkdir -p $HOME/.local/share/man/man1
rm $HOME/.local/share/man/man1/hugo* -rf
hugo gen man --dir $HOME/.local/share/man/man1
# Install shell completion files
echo "Installing bash completion..."
mkdir -p $HOME/.local/share/bash-completion/completions/
hugo completion bash > $HOME/.local/share/bash-completion/completions/hugo
echo "Installing fish completion..."
mkdir -p $HOME/.config/fish/completions/
hugo completion fish > $HOME/.config/fish/completions/hugo.fish
# Go back to previous directory
popd
# Display hugo binary location and version
location="$(which hugo)"
echo "Hugo binary location: $location"
version="$(hugo version)"
echo "Hugo binary version: $version"
else
echo "Latest version ${_latestver} is already installed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment