From a51d8e46d6011fdd633d4948c7b473b1512e15e8 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Thu, 12 Nov 2020 00:42:05 -0800 Subject: [PATCH] Add lego install script --- bin/install-lego-system | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 bin/install-lego-system diff --git a/bin/install-lego-system b/bin/install-lego-system new file mode 100755 index 0000000..6cae5f5 --- /dev/null +++ b/bin/install-lego-system @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -e + +VERSION=${VERSION:-v4.1.0} + +PREFIX_DIR=/usr/local +BIN_DIR=${PREFIX_DIR}/bin + +APP=lego + +APP_PREFIX_DIR=${PREFIX_DIR}/apps/${APP} +APP_DEST_DIR=${APP_PREFIX_DIR}/${VERSION} +APP_CURRENT=${APP_PREFIX_DIR}/current + +OS= +if [[ $OSTYPE =~ linux ]]; then + OS=linux +elif [[ $OSTYPE =~ darwin ]]; then + OS=darwin +else + echo unknown os: "$OSTYPE" + exit 1 +fi + +ARCH= +if [[ $(uname -m) == x86_64 ]]; then + ARCH=amd64 +else + echo arch not yet supported: "$(uname -m)" + exit 1 +fi + +URL=https://github.com/go-acme/lego/releases/download/${VERSION}/lego_${VERSION}_${OS}_${ARCH}.tar.gz + +[[ -d ${APP_DEST_DIR} ]] || sudo mkdir -p "${APP_DEST_DIR}" + +TMP_DIR= +if [[ ! -f ${APP_DEST_DIR}/lego ]]; then + TMP_DIR=$(mktemp --directory) + DEST_FILE=$TMP_DIR/${APP}.tar.gz + echo downloading "${APP}" "${VERSION}" to temp directory "${TMP_DIR}" + curl --silent --location --output "${DEST_FILE}" "${URL}" + + sudo tar xf "${DEST_FILE}" --directory "${APP_DEST_DIR}" + sudo chown --recursive root:root "${APP_DEST_DIR}" +else + echo "${APP}" "${VERSION}" already installed +fi + +cd ${APP_PREFIX_DIR} +[[ -s current ]] && sudo unlink current +sudo ln --symbolic "${APP_DEST_DIR}" current +echo current version set to "${VERSION}" + +cd ${BIN_DIR} +# shellcheck disable=SC2044 +for bin in $(find ${APP_CURRENT}/ -maxdepth 1 -executable -type f -exec basename {} \;); do + [[ -s $bin ]] || sudo ln --symbolic "${APP_CURRENT}/$bin" +done + +if [[ $TMP_DIR != "" ]]; then + rm -rf "${TMP_DIR}" + echo removed up temp directory "${TMP_DIR}" +fi