Add module_main to lib.sh

This commit is contained in:
Rezart Qelibari
2022-02-16 23:09:28 +01:00
parent 4f9f97d44f
commit 0f6313e777
2 changed files with 26 additions and 23 deletions

View File

@@ -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

View File

@@ -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
}