Last active
July 15, 2023 00:40
-
-
Save jimfrenette/ae7aea908601a711b93bb2564e18d1b4 to your computer and use it in GitHub Desktop.
Hugo version switcher and installer tested with Linux and OS X 64 bit releases from https://github.com/gohugoio/hugo/releases
This file contains 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 | |
# the directory that contains this script | |
base=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) | |
# ----------------------- | |
# Hugo Version Manager | |
# Author: Jim Frenette | |
# May 21, 2019 | |
# EXAMPLE USAGE | |
# ./hvm.sh install 0.54.0 | |
# | |
# the directory that contains this script | |
# should be in your PATH | |
# | |
# Hugo releases | |
# https://github.com/gohugoio/hugo/releases | |
# ----------------------- | |
# ----------------------- | |
# get OS, from | |
# https://stackoverflow.com/questions/3466166/how-to-check-if-running-in-cygwin-mac-or-linux | |
# detect three different OS types (GNU/Linux, Mac OS X, Windows NT | |
# ----------------------- | |
if [ "$(uname)" == "Darwin" ]; then | |
# Mac OS X platform | |
relos="macOS-64" | |
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then | |
# GNU/Linux platform | |
relos="Linux-64" | |
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then | |
# 32 bits Windows NT platform | |
relos="Windows-32" | |
elif [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then | |
# 64 bits Windows NT platform | |
relos="Windows-64" | |
fi | |
# param 1 | |
if [ "$1" != "" ]; then | |
parm1=$1 | |
else | |
echo "Enter a command, e.g., install, ls, use" | |
read -p 'cmd: ' parm1 | |
fi | |
# param 2 | |
if [ "$2" != "" ]; then | |
parm2=$2 | |
else | |
if [ "$2" == "install" ] || [ "$2" == "use" ]; then | |
echo "Enter a version, e.g., 0.54.0" | |
read -p 'ver: ' parm2 | |
fi | |
fi | |
# lcase using tr | |
parm1="$(echo $parm1 | tr '[A-Z]' '[a-z]')" | |
cd "$base" | |
function install { | |
mkdir -p release/v$parm2 | |
if [ -d resources ]; then | |
rm -r resources | |
fi | |
curl -L https://github.com/gohugoio/hugo/releases/download/v${parm2}/hugo_${parm2}_${relos}bit.tar.gz -o release/v$parm2/hugo_${relos}bit.tar.gz | |
cd release/v$parm2 | |
tar -xvf hugo_${relos}bit.tar.gz -C $base | |
cd "$base" | |
hugo version | |
} | |
function list { | |
cd "$base/release" | |
ls | |
} | |
function use { | |
cd "$base" | |
if [ -d release/v$parm2 ]; then | |
cd release/v$parm2 | |
tar -xvf hugo_${relos}bit.tar.gz -C $base | |
cd "$base" | |
hugo version | |
fi | |
} | |
# param 1 are commands like nvm | |
case "$1" in | |
"install") | |
# confirm | |
read -p "install Hugo version $parm2 ? [y/n] " cont | |
case "$cont" in | |
y|Y ) | |
install | |
;; | |
* ) | |
exit 0 | |
;; | |
esac | |
;; | |
"ls") | |
list | |
;; | |
"use") | |
use | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment