From ff374e3dcca5f29e9f3687531d5b91c2d6b97ec2 Mon Sep 17 00:00:00 2001 From: "T. R. Bernstein" <137705289+trbernstein@users.noreply.github.com> Date: Mon, 1 Jul 2024 21:40:31 +0200 Subject: [PATCH] Use binary to install zsh libraries --- bin/azw | 33 ++++++++++++++++++ bin/azw-update-zsh-libraries | 34 +++++++++++++++++++ modules/08-install-zsh-libraries.sh | 52 +++++++++++++++++++++-------- 3 files changed, 106 insertions(+), 13 deletions(-) create mode 100755 bin/azw create mode 100755 bin/azw-update-zsh-libraries diff --git a/bin/azw b/bin/azw new file mode 100755 index 0000000..6c9a616 --- /dev/null +++ b/bin/azw @@ -0,0 +1,33 @@ +#!/usr/bin/env zsh +# vi: set ft=zsh tw=80 ts=2 +autoload -w zshlib + +function dispatchToExtern() { + local cmdName="$1" + whence azw-$cmdName &> /dev/null || { + lop -- -e "Unknown command $cmdName." + exit 10 + } + azw-$cmdName "$@" +} + +function dispatchCommand() { + local cmdName="$1" + case $cmdName in + *) + dispatchToExtern $cmdName + ;; + esac +} + +function main() { + local cmdName="$1" + [[ $# -gt 1 ]] && shift + + dispatchCommand $cmdName +} + +if [[ "${ZSH_EVAL_CONTEXT}" == toplevel || "${ZSH_EVAL_CONTEXT}" == cmdarg ]]; then + _DIR="${0:A:h}" + main "$@" +fi diff --git a/bin/azw-update-zsh-libraries b/bin/azw-update-zsh-libraries new file mode 100755 index 0000000..5a2846e --- /dev/null +++ b/bin/azw-update-zsh-libraries @@ -0,0 +1,34 @@ +#!/usr/bin/env zsh +# vi: set ft=zsh tw=80 ts=2 + +function ensureLocalBinFolder() { + local folder="/usr/local/bin" + if [[ ! -d "${folder}" ]]; then + mkdir -p "${folder}" 2> /dev/null || return 10 + chown root:admin "${folder}" + chmod ug=rwx,o=rx "${folder}" + fi +} + +function installZshlib() { + /bin/zsh -c "$(curl -fsSL https://raw.githubusercontent.com/astzweig/zshlib/main/bootstrap.sh)" + [[ -f '/usr/local/share/zsh/site-functions/zshlib.zwc' ]] +} + +function installMacOSSystemLibrary() { + local destPath=/usr/local/bin/macos-system-lib.sh + curl --output $destPath -fsSL https://raw.githubusercontent.com/astzweig/macos-system/main/modules/lib.sh + chown root:admin $destPath + chmod ugo=r $destPath +} + +function main() { + installZshlib + ensureLocalBinFolder || return $? + installMacOSSystemLibrary +} + +if [[ "${ZSH_EVAL_CONTEXT}" == toplevel || "${ZSH_EVAL_CONTEXT}" == cmdarg ]]; then + _DIR="${0:A:h}" + main "$@" +fi diff --git a/modules/08-install-zsh-libraries.sh b/modules/08-install-zsh-libraries.sh index 9ad9ac1..112694f 100755 --- a/modules/08-install-zsh-libraries.sh +++ b/modules/08-install-zsh-libraries.sh @@ -1,29 +1,55 @@ #!/usr/bin/env zsh # vi: set ft=zsh tw=80 ts=2 -function installZshlib() { - /bin/zsh -c "$(curl -fsSL https://raw.githubusercontent.com/astzweig/zshlib/main/bootstrap.sh)" - [[ -f '/usr/local/share/zsh/site-functions/zshlib.zwc' ]] +function createLaunchDaemon() { + cat > ${launchDaemonPath} <<- LDAEMON + + + + + Label + ${serviceName} + ProgramArguments + + azw + update-zsh-libraries + + StartCalendarInterval + + Hour + 11 + Minute + 22 + + + + LDAEMON + chown root:wheel ${launchDaemonPath} + chmod ugo=rx ${launchDaemonPath} } -function installMacOSSystemLibrary() { - ensureLocalBinFolder - local destPath=/usr/local/bin/macos-system-lib.sh - cp ${ASTZWEIG_MACOS_SYSTEM_LIB} $destPath - chown root:admin $destPath - chmod ugo=r $destPath +function enableLaunchDaemon() { + launchctl enable system/${launchDaemonPath%.*} + launchctl bootstrap system ${launchDaemonPath} +} + +function createLaunchdService() { + local serviceName="de.astzweig.macos.launchdaemons.zsh-library-updater" + local launchDaemonPath="/Library/LaunchDaemons/${serviceName}.plist" + [[ -f ${launchDaemonPath} ]] || indicateActivity -- 'Create Launch Daemon' createLaunchDaemon + indicateActivity -- 'Enable Launch Daemon' enableLaunchDaemon } function configure_system() { lop -y h1 -- -i 'Install ZSh Library' - indicateActivity -- 'Install zshlib' installZshlib - indicateActivity -- 'Install macos-system library' installMacOSSystemLibrary + indicateActivity -- 'Install zsh libraries' azw update-zsh-libraries + createLaunchdService } function getExecPrerequisites() { cmds=( - [zsh]='' - [curl]='' + [azw]='' + [azw-update-zsh-libraries]='' ) }