Refactor 01-system-settings.sh module

This commit is contained in:
Rezart Qelibari
2022-02-16 21:51:16 +01:00
parent 2afdfff2f2
commit 4f9f97d44f

View File

@@ -16,6 +16,82 @@ function checkPrerequisites() {
checkCommands checkCommands
} }
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
}
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`"
scutil --set ComputerName "${hostname}"
scutil --set HostName "${hostname}"
systemsetup -setcomputername "${hostname}" > /dev/null 2>&1
systemsetup -setlocalsubnetname "${hostname}" > /dev/null 2>&1
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=" "
systemsetup -settimezone "${timezone}" >&! /dev/null
systemsetup -setusingnetworktime on >&! /dev/null
systemsetup -setnetworktimeserver 'time.apple.com' >&! /dev/null
systemsetup -setsleep never >&! /dev/null
systemsetup -setwakeonnetworkaccess off >&! /dev/null
systemsetup -setrestartfreeze on >&! /dev/null
systemsetup -f -setremotelogin off >&! /dev/null
systemsetup -setremoteappleevents off >&! /dev/null
lop success 'done'
}
function configurePowerManagement() {
lop -n info 'Configuring power management...'
cmd=(pmset -a)
${cmd} displaysleep 0
${cmd} disksleep 0
${cmd} sleep 0
${cmd} womp 0
${cmd} acwake 0
${cmd} proximitywake 0
${cmd} destroyfvkeyonstandby 1 > /dev/null
pmset -b acwake 1
${cmd} lidwake 1
${cmd} halfdim 1
${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
${cmd} SHOWFULLNAME -bool false
${cmd} AdminHostInfo -string HostName
${cmd} GuestEnabled -bool false
lop success 'done'
}
function main() { function main() {
autoloadZShLib || return autoloadZShLib || return
checkPrerequisites || return checkPrerequisites || return
@@ -38,69 +114,14 @@ function main() {
USAGE`" USAGE`"
[ $# -eq 0 ] && return [ $# -eq 0 ] && return
configureLogging configureLogging
if [ "${show_questions}" = true ]; then [ "${show_questions}" = true ] && { showQuestions; return }
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' quitSystemPreferences
osascript -e 'tell application "System Preferences" to quit' configureComputerHostname
configureBasicSystem
configurePowerManagement
configureLoginWindow
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`"
scutil --set ComputerName "${hostname}"
scutil --set HostName "${hostname}"
systemsetup -setcomputername "${hostname}" > /dev/null 2>&1
systemsetup -setlocalsubnetname "${hostname}" > /dev/null 2>&1
else
lop debug 'Hostname of computer seems to have already been set. Skipping.' debug "Hostname: `scutil --get ComputerName`"
fi
lop -n info 'Configuring systemsetup and nvram...'
# Disable the sound effects on boot
nvram SystemAudioVolume=" "
systemsetup -settimezone "${timezone}" >&! /dev/null
systemsetup -setusingnetworktime on >&! /dev/null
systemsetup -setnetworktimeserver 'time.apple.com' >&! /dev/null
systemsetup -setsleep never >&! /dev/null
systemsetup -setwakeonnetworkaccess off >&! /dev/null
systemsetup -setrestartfreeze on >&! /dev/null
systemsetup -f -setremotelogin off >&! /dev/null
systemsetup -setremoteappleevents off >&! /dev/null
lop success 'done'
# ==
lop -n info 'Configuring power management...'
cmd=(pmset -a)
${cmd} displaysleep 0
${cmd} disksleep 0
${cmd} sleep 0
${cmd} womp 0
${cmd} acwake 0
${cmd} proximitywake 0
${cmd} destroyfvkeyonstandby 1 > /dev/null
pmset -b acwake 1
${cmd} lidwake 1
${cmd} halfdim 1
${cmd} powernap 1
${cmd} hibernatemode 0
lop success 'done'
# ==
lop -n info 'Configuring login window...'
cmd=(defaults write '/Library/Preferences/com.apple.loginwindow')
${cmd} DisableFDEAutoLogin -bool true
${cmd} SHOWFULLNAME -bool false
${cmd} AdminHostInfo -string HostName
${cmd} GuestEnabled -bool false
lop success 'done'
# ==
lop info 'Configuring global umask' lop info 'Configuring global umask'
launchctl config user umask 027 launchctl config user umask 027
} }