From 0f6313e77788d81dbe416f94a4c30bf9a134540e Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Wed, 16 Feb 2022 23:09:28 +0100 Subject: [PATCH] Add module_main to lib.sh --- modules/01-system-settings.sh | 39 ++++++++++++++--------------------- modules/lib.sh | 10 +++++++++ 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/modules/01-system-settings.sh b/modules/01-system-settings.sh index 7750e41..d597826 100755 --- a/modules/01-system-settings.sh +++ b/modules/01-system-settings.sh @@ -92,10 +92,21 @@ function configureLoginWindow() { lop success 'done' } -function main() { - autoloadZShLib || return - checkPrerequisites || return - eval "`docopts -f -V - -h - : "$@" <<- USAGE +function configure_system() { + quitSystemPreferences + configureComputerHostname + configureBasicSystem + configurePowerManagement + configureLoginWindow + + lop info 'Configuring global umask' + launchctl config user umask 027 +} + +if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then + test -f "${ASTZWEIG_MACOS_SYSTEM_LIB}" || { echo 'This module requires macos-system library. Please run again with macos-system library provieded as a path in ASTZWEIG_MACOS_SYSTEM_LIB env variable.'; return 10 } + source "${ASTZWEIG_MACOS_SYSTEM_LIB}" + module_main "$@" <<- USAGE Usage: $0 show-questions $0 [-v] [-d FILE] --hostname NAME --timezone ZONE @@ -111,23 +122,5 @@ function main() { $0 0.1.0 Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law. - USAGE`" - [ $# -eq 0 ] && return - configureLogging - [ "${show_questions}" = true ] && { showQuestions; return } - - quitSystemPreferences - configureComputerHostname - configureBasicSystem - configurePowerManagement - configureLoginWindow - - lop info 'Configuring global umask' - launchctl config user umask 027 -} - -if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then - test -f "${ASTZWEIG_MACOS_SYSTEM_LIB}" || { echo 'This module requires macos-system library. Please run again with macos-system library provieded as a path in ASTZWEIG_MACOS_SYSTEM_LIB env variable.'; return 10 } - source "${ASTZWEIG_MACOS_SYSTEM_LIB}" - main "$@" + USAGE fi diff --git a/modules/lib.sh b/modules/lib.sh index c521b8f..1afb518 100644 --- a/modules/lib.sh +++ b/modules/lib.sh @@ -25,3 +25,13 @@ function checkCommands() { fi done } + +function module_main() { + autoloadZShLib || return + checkPrerequisites || return + eval "`docopts -f -V - -h - : "$@"`" + [ $# -le 1 ] && return + configureLogging + [ "${show_questions}" = true ] && { showQuestions; return } + configure_system +}