forked from Sophia/thelinuxlist
65 lines
2.3 KiB
Bash
65 lines
2.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Trap INT signal to ensure clean exits
|
|
trap 'exit 130' INT
|
|
|
|
# Confirmation prompt
|
|
while true; do
|
|
read -r -p "Would you like to install Hugo? [Y/n] " input
|
|
|
|
case $input in
|
|
[yY][eE][sS]|[yY])
|
|
break
|
|
;;
|
|
[nN][oO]|[nN])
|
|
echo "Hugo installation aborted."
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "That wasn't an option..."
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Check for dependencies and install if needed
|
|
if ! command -v curl &>/dev/null; then
|
|
echo "Installing curl..."
|
|
sudo apt update && sudo apt install -y curl || { echo "Failed to install curl. Exiting."; exit 1; }
|
|
fi
|
|
|
|
# Remove unused dependencies (optional)
|
|
echo "Removing unused dependencies..."
|
|
sudo apt autoremove -y
|
|
|
|
# Download Hugo
|
|
echo "Downloading Hugo..."
|
|
mkdir -p /tmp/hugo && cd /tmp/hugo || { echo "Failed to create directory. Exiting."; exit 1; }
|
|
VER=$(curl --silent "https://api.github.com/repos/gohugoio/hugo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's|[v,]||g' ) || { echo "Failed to fetch Hugo version. Exiting."; exit 1; }
|
|
|
|
if [ -n "$(uname -a | grep x86_64)" ]; then
|
|
HUGO_URL="https://github.com/gohugoio/hugo/releases/download/v$VER/hugo_extended_${VER}_Linux-64bit.tar.gz"
|
|
elif [ -n "$(uname -a | grep armv6l)" ]; then
|
|
HUGO_URL="https://github.com/gohugoio/hugo/releases/download/v$VER/hugo_extended_${VER}_Linux-ARM64.tar.gz"
|
|
elif [ -n "$(uname -a | grep armv7l)" ]; then
|
|
HUGO_URL="https://github.com/gohugoio/hugo/releases/download/v$VER/hugo_${VER}_Linux-ARM.tar.gz"
|
|
echo "Hugo Extended is not supported on armv7l, installing standard Hugo..."
|
|
sudo apt update && sudo apt install -y snapd || { echo "Failed to install snapd. Exiting."; exit 1; }
|
|
sudo snap install dart-sass || { echo "Failed to install dart-sass via snap. Exiting."; exit 1; }
|
|
else
|
|
echo "Unsupported architecture. Exiting."
|
|
exit 1
|
|
fi
|
|
|
|
# Download and install Hugo
|
|
echo "Downloading and installing Hugo..."
|
|
wget -O hugo.tar.gz "$HUGO_URL" || { echo "Failed to download Hugo. Exiting."; exit 1; }
|
|
tar -xzf hugo.tar.gz || { echo "Failed to extract Hugo. Exiting."; exit 1; }
|
|
sudo mv hugo /usr/local/bin || { echo "Failed to move Hugo binary. Exiting."; exit 1; }
|
|
echo "Hugo successfully installed!"
|
|
|
|
# Clean up
|
|
rm -rf /tmp/hugo
|
|
cd ~
|
|
|
|
exit 0
|