52 lines
1.4 KiB
Bash
52 lines
1.4 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
echo "[go] starting go devcontainer install"
|
|
|
|
# --------------------------------------------------
|
|
# Config
|
|
# --------------------------------------------------
|
|
RUNTIME_ROOT="/opt/zlh/runtime/go"
|
|
ARTIFACT_ROOT="/opt/zlh/devcontainer/go"
|
|
|
|
VERSION="${RUNTIME_VERSION:-1.25}"
|
|
|
|
SRC_DIR="${ARTIFACT_ROOT}/${VERSION}"
|
|
DEST_DIR="${RUNTIME_ROOT}/${VERSION}"
|
|
SYMLINK="${RUNTIME_ROOT}/current"
|
|
|
|
# --------------------------------------------------
|
|
# Guards
|
|
# --------------------------------------------------
|
|
if [ ! -d "${SRC_DIR}" ]; then
|
|
echo "[go][ERROR] artifact directory not found: ${SRC_DIR}"
|
|
exit 1
|
|
fi
|
|
|
|
if [ -x "${DEST_DIR}/bin/go" ]; then
|
|
echo "[go] go ${VERSION} already installed"
|
|
else
|
|
ARCHIVE="$(ls ${SRC_DIR}/go*.linux-amd64.tar.gz 2>/dev/null | head -n1)"
|
|
if [ -z "${ARCHIVE}" ]; then
|
|
echo "[go][ERROR] no Go archive found in ${SRC_DIR}"
|
|
exit 1
|
|
fi
|
|
|
|
echo "[go] installing go ${VERSION}"
|
|
mkdir -p "${DEST_DIR}"
|
|
|
|
tar -xzf "${ARCHIVE}" -C "${DEST_DIR}" --strip-components=1
|
|
fi
|
|
|
|
# --------------------------------------------------
|
|
# Symlink current
|
|
# --------------------------------------------------
|
|
ln -sfn "${DEST_DIR}" "${SYMLINK}"
|
|
|
|
# --------------------------------------------------
|
|
# Verify
|
|
# --------------------------------------------------
|
|
"${SYMLINK}/bin/go" version
|
|
|
|
echo "[go] go ${VERSION} install complete"
|