aboutsummaryrefslogtreecommitdiff
path: root/src/hugo
diff options
context:
space:
mode:
authorJosh Spicer <josh@joshspicer.com>2022-05-12 23:10:51 +0300
committerGitHub <noreply@github.com>2022-05-12 23:10:51 +0300
commit3a277ad757dbc51a43a5dd452d030c67a49d49f1 (patch)
tree7d4f27493f946d8792b2ff5b6383258cb9f03ce0 /src/hugo
parent2707a37ca0d4a45c7487f856bf95f8c5e10bce94 (diff)
restructure and update cli (#11)
* restructure and update cli * typo
Diffstat (limited to 'src/hugo')
-rw-r--r--src/hugo/feature.json16
-rw-r--r--src/hugo/install.sh113
2 files changed, 129 insertions, 0 deletions
diff --git a/src/hugo/feature.json b/src/hugo/feature.json
new file mode 100644
index 0000000..0b91ac1
--- /dev/null
+++ b/src/hugo/feature.json
@@ -0,0 +1,16 @@
+{
+ "id": "hugo",
+ "name": "Hugo",
+ "options": {
+ "version": {
+ "type": "string",
+ "proposals": ["latest"],
+ "default": "latest",
+ "description": "Select or enter a version."
+ }
+ },
+ "install": {
+ "app": "",
+ "file": "install.sh"
+ }
+}
diff --git a/src/hugo/install.sh b/src/hugo/install.sh
new file mode 100644
index 0000000..3913c7a
--- /dev/null
+++ b/src/hugo/install.sh
@@ -0,0 +1,113 @@
+#!/usr/bin/env bash
+#-------------------------------------------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
+#-------------------------------------------------------------------------------------------------------------
+#
+# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/hugo.md
+# Maintainer: The VS Code and Codespaces Teams
+#
+# Syntax: ./hugo-debian.sh [Hugo version] [HUGO_DIR] [Non-root user] [Add rc files flag]
+
+VERSION=${1:-"latest"}
+export HUGO_DIR=${2:-"/usr/local/hugo"}
+USERNAME=${3:-"automatic"}
+UPDATE_RC=${4:-"true"}
+
+set -e
+
+if [ "$(id -u)" -ne 0 ]; then
+ echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
+ exit 1
+fi
+
+# Ensure that login shells get the correct path if the user updated the PATH using ENV.
+rm -f /etc/profile.d/00-restore-env.sh
+echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
+chmod +x /etc/profile.d/00-restore-env.sh
+
+# Determine the appropriate non-root user
+if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
+ USERNAME=""
+ POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
+ for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
+ if id -u ${CURRENT_USER} > /dev/null 2>&1; then
+ USERNAME=${CURRENT_USER}
+ break
+ fi
+ done
+ if [ "${USERNAME}" = "" ]; then
+ USERNAME=root
+ fi
+elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
+ USERNAME=root
+fi
+
+architecture="$(uname -m)"
+if [ "${architecture}" != "amd64" ] && [ "${architecture}" != "x86_64" ] && [ "${architecture}" != "arm64" ] && [ "${architecture}" != "aarch64" ]; then
+ echo "(!) Architecture $architecture unsupported"
+ exit 1
+fi
+
+updaterc() {
+ if [ "${UPDATE_RC}" = "true" ]; then
+ echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
+ if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
+ echo -e "$1" >> /etc/bash.bashrc
+ fi
+ if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
+ echo -e "$1" >> /etc/zsh/zshrc
+ fi
+ fi
+}
+
+# Function to run apt-get if needed
+apt_get_update_if_needed()
+{
+ if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
+ echo "Running apt-get update..."
+ apt-get update
+ else
+ echo "Skipping apt-get update."
+ fi
+}
+
+# Checks if packages are installed and installs them if not
+check_packages() {
+ if ! dpkg -s "$@" > /dev/null 2>&1; then
+ apt_get_update_if_needed
+ apt-get -y install --no-install-recommends "$@"
+ fi
+}
+
+# Install dependencies
+check_packages curl ca-certificates tar
+
+# Fetch latest version of Hugo if needed
+if [ "${VERSION}" = "latest" ] || [ "${VERSION}" = "lts" ]; then
+ export VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | grep "tag_name" | awk '{print substr($2, 3, length($2)-4)}')
+fi
+
+# Install Hugo if it's missing
+if ! hugo version &> /dev/null ; then
+ echo "Installing Hugo..."
+ installation_dir="$HUGO_DIR/bin"
+ mkdir -p "$installation_dir"
+
+ # Install ARM or x86 version of hugo based on current machine architecture
+ if [ "$(uname -m)" == "aarch64" ]; then
+ arch="ARM64"
+ else
+ arch="64bit"
+ fi
+
+ hugo_filename="hugo_${VERSION}_Linux-${arch}.tar.gz"
+
+ curl -fsSLO --compressed "https://github.com/gohugoio/hugo/releases/download/v${VERSION}/${hugo_filename}"
+ tar -xzf "$hugo_filename" -C "$installation_dir"
+ rm "$hugo_filename"
+
+ updaterc "export HUGO_DIR=${installation_dir}"
+fi
+
+echo "Done!"