From 4fa98ea9a5fa5da5d0024d68ee20dd6151353814 Mon Sep 17 00:00:00 2001 From: "T. R. Bernstein" <137705289+trbernstein@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:44:12 +0200 Subject: [PATCH] Remove zshlib as submodule --- .gitmodules | 3 -- bootstrap.sh | 96 +++++++++++++++++++++++++++++++++----------------- install.sh | 2 +- modules/lib.sh | 5 ++- zshlib | 1 - 5 files changed, 67 insertions(+), 40 deletions(-) delete mode 100644 .gitmodules delete mode 160000 zshlib diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index afd6216..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "zshlib"] - path = zshlib - url = https://github.com/astzweig/zshlib diff --git a/bootstrap.sh b/bootstrap.sh index f142152..ad44029 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,6 +1,39 @@ #!/usr/bin/env zsh # vi: set ft=zsh tw=80 ts=2 +# ================= +# Utility Functions +# ================= + +function isDebug() { + [[ ${DEBUG} == true || ${DEBUG} == 1 ]] +} + +function printSuccess() { + printOrLog "${colors[green]}${*}${colors[reset]}" +} + +function printError() { + printOrLog "${errColors[red]}${*}${errColors[reset]}" >&2 +} + +function printFailedWithError() { + printOrLog "${colors[red]}failed.${colors[reset]}" + printOrLog "$*" >&2 +} + +function printOrLog() { + if [[ -t 1 ]]; then + print "$@" + else + logger -t zshlib_bootstrap_sh "$@" + fi +} + +# ========================== +# Install Command Line Tools +# ========================== + function versionGT() { [[ "${1%.*}" -gt "${2%.*}" ]] || [[ "${1%.*}" -eq "${2%.*}" && "${1#*.}" -gt "${2#*.}" ]] } @@ -9,6 +42,10 @@ function majorMinor() { echo "${1%%.*}.$(x="${1#*.}" echo "${x%%.*}")" } +function isOnMacOS() { + [[ $(uname) == Darwin ]] +} + function shouldInstallCommandLineTools() { local macosVersion=$(majorMinor $(/usr/bin/sw_vers -productVersion)) if versionGT "${macosVersion}" "10.13" @@ -25,7 +62,7 @@ function removeNewlines() { } function acceptXcodeLicense() { - xcodebuild -license accept + xcodebuild -license accept 2> /dev/null } function installCommandLineTools() { @@ -50,10 +87,15 @@ function installCommandLineTools() { } function ensureCommandLineTools() { + isOnMacOS || return installCommandLineTools acceptXcodeLicense } +# ================== +# Download Resources +# ================== + function ensureDocopts() { which docopts > /dev/null && return local fileURL="${DOCOPTS_URL:-https://github.com/astzweig/docopts/releases/download/v.0.7.0/docopts_darwin_amd64}" @@ -76,22 +118,15 @@ function cloneZSHLibRepo() { git submodule -q update --depth 1 --init --recursive --remote 2> /dev/null || return 10 } -function isDebug() { - test "${DEBUG}" = true -o "${DEBUG}" = 1 +function downloadZSHLibWordCodeFromGithub() { + local apiURL=${ZSHLIB_RELEASE_API_URL:-https://api.github.com/repos/astzweig/zshlib/releases/latest} + local zwcURL=`curl -s $apiURL | python3 -c 'import json,sys;print(json.load(sys.stdin)["assets"][0]["browser_download_url"])' 2> /dev/null` + curl --output ./zshlib.zwc -fsSL "${zwcURL}" || return 10 } -function printSuccess() { - print "${colors[green]}${*}${colors[reset]}" -} - -function printError() { - print "${errColors[red]}${*}${errColors[reset]}" >&2 -} - -function printFailedWithError() { - print "${colors[red]}failed.${colors[reset]}" - print "$*" >&2 -} +# ==== +# Main +# ==== function defineColors() { local -A colorCodes=(red "`tput setaf 9`" green "`tput setaf 10`" reset "`tput sgr0`") @@ -99,20 +134,6 @@ function defineColors() { [ -t 2 ] && errColors=( ${(kv)colorCodes} ) } -function ensureRepo() { - local repoName="$1" cmdName="${2}" - print -n "Installing ${1}..." - $cmdName || { printFailedWithError "This script requires $repoName but was not able to clone it. Please ensure access to the $repoName repository."; return 10} - printSuccess 'done' -} - -function ensureBinary() { - local binaryName="$1" cmdName="${2}" - print -n "Ensure ${1} is installed..." - $cmdName || { printFailedWithError "This script requires $binaryName but was neither able to locate and install it. Please install $binaryName and add it to one of the PATH directories."; return 10} - printSuccess 'done' -} - function configureTerminal() { if [ -t 0 ]; then traps+=("stty $(stty -g)") @@ -126,6 +147,17 @@ function configureTerminal() { fi } +function ensure() { + local itemType=$1 itemName=$2 itemCmd=$3 + print -n "Installing ${itemName}..." + if [[ $itemType == 'repo' ]]; then + $itemCmd || { printFailedWithError "This script requires $itemName but was not able to clone it. Please ensure access to the $itemName repository."; return 10} + else + $itemCmd || { printFailedWithError "This script requires $itemName but was neither able to locate or install it. Please install $itemName and add it to one of the PATH directories."; return 10} + fi + printSuccess 'done' +} + function main() { local traps=() local -A colors=() errColors=() @@ -140,9 +172,9 @@ function main() { print 'Ensure command line tools are available.' ensureCommandLineTools - ensureRepo 'macos-system' cloneMacOSSystemRepo || return - ensureRepo 'zshlib' cloneZSHLibRepo || return - ensureBinary 'docopts' ensureDocopts || return + ensure 'repo' 'macos-system' cloneMacOSSystemRepo || return + ensure 'binary' 'zshlib' downloadZSHLibWordCodeFromGithub || return + ensure 'binary' 'docopts' ensureDocopts || return print 'Will now run the installer.' [ -t 1 ] && tput cnorm diff --git a/install.sh b/install.sh index a241a1d..d43d975 100755 --- a/install.sh +++ b/install.sh @@ -146,7 +146,7 @@ function main() { if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then _DIR="${0:A:h}" export ASTZWEIG_MACOS_SYSTEM_LIB=${_DIR}/modules/lib.sh - export ASTZWEIG_ZSHLIB=${_DIR}/zshlib + export ASTZWEIG_ZSHLIB=${_DIR}/zshlib.zwc source "${ASTZWEIG_MACOS_SYSTEM_LIB}" main "$@" fi diff --git a/modules/lib.sh b/modules/lib.sh index 7cb0aeb..fd30293 100644 --- a/modules/lib.sh +++ b/modules/lib.sh @@ -2,14 +2,13 @@ # vi: set ft=zsh tw=80 ts=2 function autoloadZShLib() { - test -d "${ASTZWEIG_ZSHLIB}" || { echo "This module needs astzweig/zshlib to work." >&2; return 99 } - FPATH="${ASTZWEIG_ZSHLIB}:${FPATH}" + [[ -d ${ASTZWEIG_ZSHLIB} || -f ${ASTZWEIG_ZSHLIB} ]] || { echo "This module needs astzweig/zshlib to work." >&2; return 99 } fpath+=(${ASTZWEIG_ZSHLIB}) if [[ -d ${ASTZWEIG_ZSHLIB} ]]; then local funcNames=($(find "${ASTZWEIG_ZSHLIB}" -type f -perm +u=x -maxdepth 1 | awk -F/ '{ print $NF }')) autoload -Uz ${funcNames} elif [[ -f ${ASTZWEIG_ZSHLIB} ]]; then - autoload -Uzw ${ASTZWEIG_ZSHLIB} + autoload -Uzw ${ASTZWEIG_ZSHLIB:t} fi } diff --git a/zshlib b/zshlib deleted file mode 160000 index 46cbbc2..0000000 --- a/zshlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 46cbbc2d3765a21b76cdb80d89a2a38095fb596f