From 4f9f97d44f934a0650751c723c1d73e7297a18cf Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Wed, 16 Feb 2022 21:51:16 +0100 Subject: [PATCH] Refactor 01-system-settings.sh module --- modules/01-system-settings.sh | 89 ++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 34 deletions(-) diff --git a/modules/01-system-settings.sh b/modules/01-system-settings.sh index 2b8dc48..7750e41 100755 --- a/modules/01-system-settings.sh +++ b/modules/01-system-settings.sh @@ -16,38 +16,24 @@ function checkPrerequisites() { checkCommands } -function main() { - autoloadZShLib || return - checkPrerequisites || return - eval "`docopts -f -V - -h - : "$@" <<- USAGE - Usage: - $0 show-questions - $0 [-v] [-d FILE] --hostname NAME --timezone ZONE +function showQuestions() { + local timezones questions question + timezones="`systemsetup -listtimezones | tail -n +2 | awk '{print $1}' | paste -sd, -`" + questions=( + 'i: hostname=What shall the hostname of this host be?' + 's: timezone=What shall the timezone of this host be? # choose from:'"${timezones};" + ) + for question in ${questions}; do + hio info "${question}" + done +} - Set energy, basic network and host preferences. - - Options: - --hostname NAME Set NAME as current host's host name. - --timezone ZONE Set ZONE as current host's timezone [default: Europe/Berlin]. - -d FILE, --logfile FILE Print log message to logfile instead of stdout. - -v, --verbose Be more verbose. - ---- - $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 - if [ "${show_questions}" = true ]; then - local timezones="`systemsetup -listtimezones | tail -n +2 | awk '{print $1}' | paste -sd, -`" - hio info 'i: hostname=What shall the hostname of this host be?' - hio info 's: timezone=What shall the timezone of this host be? # choose from:'"${timezones};" - return - fi - +function quitSystemPreferences() { lop debug 'Quitting System Preferences App' osascript -e 'tell application "System Preferences" to quit' - +} + +function configureComputerHostname() { lop info 'Configuring computer hostname.' debug "Current hostname: `scutil --get ComputerName`" if [[ "`scutil --get ComputerName`" != "${hostname}" ]]; then lop debug 'Hostname of computer has not been set.' debug "Current hostname: `scutil --get ComputerName`" @@ -59,7 +45,9 @@ function main() { else lop debug 'Hostname of computer seems to have already been set. Skipping.' debug "Hostname: `scutil --get ComputerName`" fi - +} + +function configureBasicSystem(){ lop -n info 'Configuring systemsetup and nvram...' # Disable the sound effects on boot nvram SystemAudioVolume=" " @@ -74,7 +62,9 @@ function main() { systemsetup -setremoteappleevents off >&! /dev/null lop success 'done' - # == +} + +function configurePowerManagement() { lop -n info 'Configuring power management...' cmd=(pmset -a) ${cmd} displaysleep 0 @@ -90,8 +80,9 @@ function main() { ${cmd} powernap 1 ${cmd} hibernatemode 0 lop success 'done' - - # == +} + +function configureLoginWindow() { lop -n info 'Configuring login window...' cmd=(defaults write '/Library/Preferences/com.apple.loginwindow') ${cmd} DisableFDEAutoLogin -bool true @@ -99,8 +90,38 @@ function main() { ${cmd} AdminHostInfo -string HostName ${cmd} GuestEnabled -bool false lop success 'done' +} + +function main() { + autoloadZShLib || return + checkPrerequisites || return + eval "`docopts -f -V - -h - : "$@" <<- USAGE + Usage: + $0 show-questions + $0 [-v] [-d FILE] --hostname NAME --timezone ZONE + + Set energy, basic network and host preferences. + + Options: + --hostname NAME Set NAME as current host's host name. + --timezone ZONE Set ZONE as current host's timezone [default: Europe/Berlin]. + -d FILE, --logfile FILE Print log message to logfile instead of stdout. + -v, --verbose Be more verbose. + ---- + $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 }