Refactor 01-system-settings.sh module
This commit is contained in:
@@ -16,38 +16,24 @@ function checkPrerequisites() {
|
|||||||
checkCommands
|
checkCommands
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function showQuestions() {
|
||||||
autoloadZShLib || return
|
local timezones questions question
|
||||||
checkPrerequisites || return
|
timezones="`systemsetup -listtimezones | tail -n +2 | awk '{print $1}' | paste -sd, -`"
|
||||||
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
questions=(
|
||||||
Usage:
|
'i: hostname=What shall the hostname of this host be?'
|
||||||
$0 show-questions
|
's: timezone=What shall the timezone of this host be? # choose from:'"${timezones};"
|
||||||
$0 [-v] [-d FILE] --hostname NAME --timezone ZONE
|
)
|
||||||
|
for question in ${questions}; do
|
||||||
|
hio info "${question}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
Set energy, basic network and host preferences.
|
function quitSystemPreferences() {
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
lop debug 'Quitting System Preferences App'
|
lop debug 'Quitting System Preferences App'
|
||||||
osascript -e 'tell application "System Preferences" to quit'
|
osascript -e 'tell application "System Preferences" to quit'
|
||||||
|
}
|
||||||
|
|
||||||
|
function configureComputerHostname() {
|
||||||
lop info 'Configuring computer hostname.' debug "Current hostname: `scutil --get ComputerName`"
|
lop info 'Configuring computer hostname.' debug "Current hostname: `scutil --get ComputerName`"
|
||||||
if [[ "`scutil --get ComputerName`" != "${hostname}" ]]; then
|
if [[ "`scutil --get ComputerName`" != "${hostname}" ]]; then
|
||||||
lop debug 'Hostname of computer has not been set.' debug "Current hostname: `scutil --get ComputerName`"
|
lop debug 'Hostname of computer has not been set.' debug "Current hostname: `scutil --get ComputerName`"
|
||||||
@@ -59,7 +45,9 @@ function main() {
|
|||||||
else
|
else
|
||||||
lop debug 'Hostname of computer seems to have already been set. Skipping.' debug "Hostname: `scutil --get ComputerName`"
|
lop debug 'Hostname of computer seems to have already been set. Skipping.' debug "Hostname: `scutil --get ComputerName`"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function configureBasicSystem(){
|
||||||
lop -n info 'Configuring systemsetup and nvram...'
|
lop -n info 'Configuring systemsetup and nvram...'
|
||||||
# Disable the sound effects on boot
|
# Disable the sound effects on boot
|
||||||
nvram SystemAudioVolume=" "
|
nvram SystemAudioVolume=" "
|
||||||
@@ -74,7 +62,9 @@ function main() {
|
|||||||
systemsetup -setremoteappleevents off >&! /dev/null
|
systemsetup -setremoteappleevents off >&! /dev/null
|
||||||
lop success 'done'
|
lop success 'done'
|
||||||
|
|
||||||
# ==
|
}
|
||||||
|
|
||||||
|
function configurePowerManagement() {
|
||||||
lop -n info 'Configuring power management...'
|
lop -n info 'Configuring power management...'
|
||||||
cmd=(pmset -a)
|
cmd=(pmset -a)
|
||||||
${cmd} displaysleep 0
|
${cmd} displaysleep 0
|
||||||
@@ -90,8 +80,9 @@ function main() {
|
|||||||
${cmd} powernap 1
|
${cmd} powernap 1
|
||||||
${cmd} hibernatemode 0
|
${cmd} hibernatemode 0
|
||||||
lop success 'done'
|
lop success 'done'
|
||||||
|
}
|
||||||
# ==
|
|
||||||
|
function configureLoginWindow() {
|
||||||
lop -n info 'Configuring login window...'
|
lop -n info 'Configuring login window...'
|
||||||
cmd=(defaults write '/Library/Preferences/com.apple.loginwindow')
|
cmd=(defaults write '/Library/Preferences/com.apple.loginwindow')
|
||||||
${cmd} DisableFDEAutoLogin -bool true
|
${cmd} DisableFDEAutoLogin -bool true
|
||||||
@@ -99,8 +90,38 @@ function main() {
|
|||||||
${cmd} AdminHostInfo -string HostName
|
${cmd} AdminHostInfo -string HostName
|
||||||
${cmd} GuestEnabled -bool false
|
${cmd} GuestEnabled -bool false
|
||||||
lop success 'done'
|
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'
|
lop info 'Configuring global umask'
|
||||||
launchctl config user umask 027
|
launchctl config user umask 027
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user