Use loadModules and askUserModuleQuestions

This commit is contained in:
Rezart Qelibari
2022-03-08 12:42:48 +01:00
parent 79693877b2
commit 322a2aa757
14 changed files with 77 additions and 628 deletions

View File

@@ -12,7 +12,7 @@ function checkPrerequisites() {
[defaults]=''
[launchctl]=''
)
test "`id -u`" -eq 0 || { lop error 'This module requires root access. Please run as root.'; return 11 }
test "`id -u`" -eq 0 || { lop -e 'This module requires root access. Please run as root.'; return 11 }
checkCommands
}
@@ -26,26 +26,27 @@ function getQuestions() {
}
function quitSystemPreferences() {
lop debug 'Quitting System Preferences App'
lop -d '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`"
lop -i 'Configuring computer hostname.'
lop -d "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`"
lop -d 'Hostname of computer has not been set.' -d "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`"
lop -d 'Hostname of computer seems to have already been set. Skipping.' -d "Hostname: `scutil --get ComputerName`"
fi
}
function configureBasicSystem(){
lop -n info 'Configuring systemsetup and nvram...'
lop --no-newline -i 'Configuring systemsetup and nvram...'
# Disable the sound effects on boot
nvram SystemAudioVolume=" "
@@ -57,12 +58,12 @@ function configureBasicSystem(){
systemsetup -setrestartfreeze on >&! /dev/null
systemsetup -f -setremotelogin off >&! /dev/null
systemsetup -setremoteappleevents off >&! /dev/null
lop success 'done'
lop -i 'done'
}
function configurePowerManagement() {
lop -n info 'Configuring power management...'
lop --no-newline -i 'Configuring power management...'
cmd=(pmset -a)
${cmd} displaysleep 0
${cmd} disksleep 0
@@ -76,17 +77,17 @@ function configurePowerManagement() {
${cmd} halfdim 1
${cmd} powernap 1
${cmd} hibernatemode 0
lop success 'done'
lop -i 'done'
}
function configureLoginWindow() {
lop -n info 'Configuring login window...'
lop --no-newline -i '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 -i 'done'
}
function configure_system() {
@@ -96,7 +97,7 @@ function configure_system() {
configurePowerManagement
configureLoginWindow
lop info 'Configuring global umask'
lop -i 'Configuring global umask'
launchctl config user umask 027
}

View File

@@ -2,25 +2,25 @@
function getDefaultFullname() {
local computerName="`scutil --get ComputerName 2> /dev/null`"
lop debug 'Default full name based on current computer name is:' debug "$computerName"
lop -d 'Default full name based on current computer name is:' -d "$computerName"
print "${computerName}"
}
function getDefaultUsername() {
local username="`getDefaultFullname | tr '[:upper:]' '[:lower:]' | tr -C '[:alnum:]\n' '-'`"
lop debug 'Default username based on current computer name is:' debug "$username"
lop -d 'Default username based on current computer name is:' -d "$username"
print "${username}"
}
function getUsersWithSecureToken() {
local username
for username in ${(f)"$(dscl . -list /Users | grep -v '^_.*')"}; do
lop -n debug 'Checking if user' debug "${username}" debug 'has a secure token set...'
lop --no-newline -d 'Checking if user' -d "${username}" -d 'has a secure token set...'
if checkSecureTokenForUser "${username}"; then
lop debug 'found'
lop -d 'found'
secureTokenUsers+=("${username}")
else
lop debug 'not found'
lop -d 'not found'
fi
done
}
@@ -33,14 +33,14 @@ function getDefaultUserPictures() {
function convertPathToDefaultPicture() {
local resolved=''
lop debug 'Converting path' debug "${filevault_picture}" debug 'to default picture path if necessary.'
lop -d 'Converting path' -d "${filevault_picture}" -d 'to default picture path if necessary.'
if [ -r "${filevault_picture}" ]; then
lop debug 'Path seems to be a valid path already. Skipping conversion.'
lop -d 'Path seems to be a valid path already. Skipping conversion.'
return
fi
pushd -q '/Library/User Pictures'
resolved="`find . -type f -path "*${filevault_picture}" 2> /dev/null`"
lop debug 'Resolved path is' debug "${resolved}"
lop -d 'Resolved path is' -d "${resolved}"
popd -q
[ -n "${resolved}" -a -r "${resolved}" ] && filevault_picture="${resolved}"
}
@@ -48,7 +48,7 @@ function convertPathToDefaultPicture() {
function isPathToPicture() {
local filevault_picture=$1
convertPathToDefaultPicture
[ -r "${filevault_picture}" ] || { lop debug 'Resolved path is not a valid path. Returning.'; return 10 }
[ -r "${filevault_picture}" ] || { lop -d 'Resolved path is not a valid path. Returning.'; return 10 }
[[ "${filevault_picture:e:l}" =~ (tif|png|jpeg|jpg) ]] || return 11
}
@@ -67,9 +67,9 @@ function doesFileVaultUserExist() {
function createFileVaultUser() {
local un=${filevault_username} fn=${filevault_fullname} pw=${filevault_password}
lop -n info 'Creating FileVault user' debug "${un}" info '...'
lop --no-newline -d 'Creating FileVault user' -d "${un}" -d '...'
sysadminctl -addUser "${un}" -fullName "${fn}" -shell /usr/bin/false -home '/var/empty' -password "${pw}" > /dev/null 2>&1
lop success done
lop -d done
}
function configureFileVaultUser() {
@@ -127,13 +127,11 @@ function allowOnlyFileVaultUserToUnlock() {
for fdeuser in ${(f)"$(fdesetup list | cut -d',' -f1)"}; do
[ "${fdeuser}" != "${username}" ] && fdesetup remove -user "${fdeuser}"
done
}
function configure_system() {
checkSecureTokenForUser "${secure_token_user_username}" || { lop error 'The provided secure token user has no secure token.'; return 10 }
checkSecureTokenUserPassword || { lop error 'The secure token user password is incorrect.'; return 11 }
} function configure_system() {
checkSecureTokenForUser "${secure_token_user_username}" || { lop -e 'The provided secure token user has no secure token.'; return 10 }
checkSecureTokenUserPassword || { lop -e 'The secure token user password is incorrect.'; return 11 }
convertPathToDefaultPicture
isPathToPicture "${filevault_picture}" || { lop error 'The provided FileVault user picture is not a valid path to a TIF, PNG or JPEG file.'; return 12 }
isPathToPicture "${filevault_picture}" || { lop -e 'The provided FileVault user picture is not a valid path to a TIF, PNG or JPEG file.'; return 12 }
doesFileVaultUserExist || createFileVaultUser
configureFileVaultUser
@@ -154,7 +152,7 @@ function checkPrerequisites() {
[sysadminctl]=''
[scutil]=''
)
test "`id -u`" -eq 0 || { lop error 'This module requires root access. Please run as root.'; return 11 }
test "`id -u`" -eq 0 || { lop -e 'This module requires root access. Please run as root.'; return 11 }
checkCommands
}

View File

@@ -20,7 +20,7 @@ function checkCommands() {
if ! which "${cmd}" >&! /dev/null; then
local comment=''
[ -n "${cmds[$cmd]}" ] && comment=" ${cmds[$cmd]}"
lop error "This module needs ${cmd}${comment} to work."
lop -e "This module needs ${cmd}${comment} to work."
return 11
fi
done
@@ -30,7 +30,7 @@ function showQuestions() {
local questions=()
getQuestions
for question in ${questions}; do
hio info "${question}"
hio -- body "${question}"
done
}