fix hugo install force option

trantor
David Kebler 2020-12-20 17:58:20 -08:00
parent 9e5768aa4d
commit 2321889a52
1 changed files with 36 additions and 36 deletions

View File

@ -22,6 +22,9 @@ EFILE=""
# c - use 'hugoe' as the install command for extended version otherwise 'hugo' will launch extended version # c - use 'hugoe' as the install command for extended version otherwise 'hugo' will launch extended version
# f - force download/overwrite of same version # f - force download/overwrite of same version
declare OPTION
declare OPTARG
declare OPTIND
while getopts 'ecf' OPTION; do while getopts 'ecf' OPTION; do
case "$OPTION" in case "$OPTION" in
@ -74,36 +77,36 @@ if [ -z "$NEW_VERSION" ]; then
exit 1 exit 1
fi fi
if ! [ $NEW_VERSION = $CUR_VERSION ] || [ $FORCE = true ]; then [[ $NEW_VERSION = $CUR_VERSION ]] && [[ $FORCE = false ]] && echo Latest version already installed at $BIN_PATH && return 0
pushd /tmp/ > /dev/null pushd /tmp/ > /dev/null
URL=$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest \ URL=$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/gohugoio/hugo/releases/latest \
| grep "browser_download_url.*hugo.*._Linux-${ARCHES[$ARCH]}\.tar\.gz" \ | grep "browser_download_url.*hugo.*._Linux-${ARCHES[$ARCH]}\.tar\.gz" \
| \ | \
if [ $EXTENDED = true ]; then if [ $EXTENDED = true ]; then
grep "_extended" grep "_extended"
else else
grep -v "_extended" grep -v "_extended"
fi \ fi \
| cut -d ":" -f 2,3 \ | cut -d ":" -f 2,3 \
| tr -d \" \ | tr -d \" \
) )
echo $URL echo $URL
echo "Installing version $NEW_VERSION `[ $EXTENDED == true ] && echo "Extended"` " echo "Installing version $NEW_VERSION `[ $EXTENDED == true ] && echo "Extended"` "
echo "This machine's architecture is $ARCH" echo "This machine's architecture is $ARCH"
echo "Downloading Tarball $URL" echo "Downloading Tarball $URL"
wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL
TARBALL=$(basename $URL) TARBALL=$(basename $URL)
# TARBALL="$(find . -name "*Linux-${ARCHES[$ARCH]}.tar.gz" 2>/dev/null)" # TARBALL="$(find . -name "*Linux-${ARCHES[$ARCH]}.tar.gz" 2>/dev/null)"
echo Expanding Tarball, $TARBALL echo Expanding Tarball, $TARBALL
tar -xzf $TARBALL hugo tar -xzf $TARBALL hugo
chmod +x hugo chmod +x hugo
if [ -w $BIN_DIR ]; then if [ -w $BIN_DIR ]; then
echo "Installing hugo to $BIN_DIR" echo "Installing hugo to $BIN_DIR"
@ -115,25 +118,22 @@ fi
rm $TARBALL rm $TARBALL
popd > /dev/null popd > /dev/null
echo Installing hugo `[ $EXTENDED == true ] && echo "extended"` as hugo$EFILE echo Installing hugo `[ $EXTENDED == true ] && echo "extended"` as hugo$EFILE
BIN_PATH="$(which hugo$EFILE)" BIN_PATH="$(which hugo$EFILE)"
if [ -z "$BIN_PATH" ]; then
if [ -z "$BIN_PATH" ]; then
printf "WARNING: Installed Hugo Binary in $BIN_DIR is not in your environment path\nPATH=$PATH\n" printf "WARNING: Installed Hugo Binary in $BIN_DIR is not in your environment path\nPATH=$PATH\n"
else else
if [ "$BIN_DIR/hugo$EFILE" != "$BIN_PATH" ]; then if [ "$BIN_DIR/hugo$EFILE" != "$BIN_PATH" ]; then
echo "WARNING: Just installed Hugo binary hugo$EFILE to, $BIN_DIR , conflicts with existing Hugo in $BIN_PATH" echo "WARNING: Just installed Hugo binary hugo$EFILE to, $BIN_DIR , conflicts with existing Hugo in $BIN_PATH"
echo "add $BIN_DIR to path and delete $BIN_PATH" echo "add $BIN_DIR to path and delete $BIN_PATH"
else else
echo "--- Installation Confirmation ---" echo "--- Installation Confirmation ---"
printf "New Hugo binary version at $BIN_PATH is\n $($BIN_PATH version)\n" printf "New Hugo binary version at $BIN_PATH is\n $($BIN_PATH version)\n"
fi fi
fi fi
else
echo Latest version already installed at $BIN_PATH
fi
} }