Make config of hostname a setup step
This commit is contained in:
@@ -1,73 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
# vi: set ft=zsh tw=80 ts=2
|
|
||||||
|
|
||||||
function configureLogging() {
|
|
||||||
local output=tostdout level=info
|
|
||||||
[ -n "${logfile}" ] && output=${logfile}
|
|
||||||
[ "${verbose}" = true ] && level=debug
|
|
||||||
lop setoutput -l ${level} ${output}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getUsage() {
|
|
||||||
local cmdName=$1 text=''
|
|
||||||
read -r -d '' text <<- USAGE
|
|
||||||
Usage:
|
|
||||||
$cmdName [-v] [-d FILE] --hostname NAME
|
|
||||||
|
|
||||||
Configure host specific settings.
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--hostname NAME Set NAME as current host's host name.
|
|
||||||
-d FILE, --logfile FILE Print log message to logfile instead of stdout.
|
|
||||||
-v, --verbose Be more verbose.
|
|
||||||
----
|
|
||||||
$cmdName 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
|
|
||||||
print -- ${text}
|
|
||||||
}
|
|
||||||
|
|
||||||
function quitSystemPreferences() {
|
|
||||||
ps -A -o pid,comm | grep "MacOS/System Settings" | awk '{print "kill -9 " $1}' | /bin/sh
|
|
||||||
}
|
|
||||||
|
|
||||||
function setComputerName() {
|
|
||||||
scutil --set ComputerName "${hostname}"
|
|
||||||
scutil --set HostName "${hostname}"
|
|
||||||
scutil --set LocalHostName "${hostname}"
|
|
||||||
systemsetup -setcomputername "${hostname}"
|
|
||||||
systemsetup -setlocalsubnetname "${hostname}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function configureComputerHostname() {
|
|
||||||
local currentComputerName="`scutil --get ComputerName`"
|
|
||||||
if [[ "${currentComputerName}" != "${hostname}" ]]; then
|
|
||||||
lop -- -i 'Hostname of computer has not been set.' -i "Will set to ${hostname}."
|
|
||||||
indicateActivity -- 'Set computer name' setComputerName
|
|
||||||
else
|
|
||||||
lop -- -i 'Hostname of computer seems to have already been set. Skipping.' -i "Hostname: $currentComputerName"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function requireRootPrivileges() {
|
|
||||||
[[ `id -u` -eq 0 ]] || { lop -- -e 'Need root access to change hostname. Aborting.'; return 10 }
|
|
||||||
}
|
|
||||||
|
|
||||||
function main() {
|
|
||||||
local cmdPath=${1} cmdName=${1:t}
|
|
||||||
shift
|
|
||||||
eval "`getUsage $cmdName | docopts -f -V - -h - : "$@"`"
|
|
||||||
configureLogging
|
|
||||||
requireRootPrivileges || return $?
|
|
||||||
|
|
||||||
lop -y h1 -- -i 'Configure System Settings'
|
|
||||||
indicateActivity -- 'Quitting System Preferences' quitSystemPreferences
|
|
||||||
configureComputerHostname
|
|
||||||
}
|
|
||||||
|
|
||||||
if [[ "${ZSH_EVAL_CONTEXT}" == toplevel || "${ZSH_EVAL_CONTEXT}" == cmdarg ]]; then
|
|
||||||
_DIR="${0:A:h}"
|
|
||||||
source autoload-zshlib
|
|
||||||
main $0 "$@"
|
|
||||||
fi
|
|
||||||
@@ -65,6 +65,24 @@ function configureMacOSFirewall() {
|
|||||||
${cmd} --setallowsignedapp on
|
${cmd} --setallowsignedapp on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setComputerName() {
|
||||||
|
scutil --set ComputerName "${hostname}"
|
||||||
|
scutil --set HostName "${hostname}"
|
||||||
|
scutil --set LocalHostName "${hostname}"
|
||||||
|
systemsetup -setcomputername "${hostname}"
|
||||||
|
systemsetup -setlocalsubnetname "${hostname}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function configureComputerHostname() {
|
||||||
|
local currentComputerName="`scutil --get ComputerName`"
|
||||||
|
if [[ "${currentComputerName}" != "${hostname}" ]]; then
|
||||||
|
lop -- -i 'Hostname of computer has not been set.' -i "Will set to ${hostname}."
|
||||||
|
indicateActivity -- 'Set computer name' setComputerName
|
||||||
|
else
|
||||||
|
lop -- -i 'Hostname of computer seems to have already been set. Skipping.' -i "Hostname: $currentComputerName"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function configure_system() {
|
function configure_system() {
|
||||||
lop -y h1 -- -i 'Configure System Settings'
|
lop -y h1 -- -i 'Configure System Settings'
|
||||||
indicateActivity -- 'Quitting System Preferences' quitSystemPreferences
|
indicateActivity -- 'Quitting System Preferences' quitSystemPreferences
|
||||||
@@ -73,6 +91,13 @@ function configure_system() {
|
|||||||
indicateActivity -- 'Configuring login window' configureLoginWindow
|
indicateActivity -- 'Configuring login window' configureLoginWindow
|
||||||
indicateActivity -- 'Configure global umask' launchctl config user umask 027
|
indicateActivity -- 'Configure global umask' launchctl config user umask 027
|
||||||
indicateActivity -- 'Configure macOS firewall' configureMacOSFirewall
|
indicateActivity -- 'Configure macOS firewall' configureMacOSFirewall
|
||||||
|
configureComputerHostname
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQuestions() {
|
||||||
|
questions=(
|
||||||
|
'i: hostname=What shall the systems hostname be?'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUsage() {
|
function getUsage() {
|
||||||
@@ -80,11 +105,12 @@ function getUsage() {
|
|||||||
read -r -d '' text <<- USAGE
|
read -r -d '' text <<- USAGE
|
||||||
Usage:
|
Usage:
|
||||||
$cmdName show-questions [<modkey> <modans>]...
|
$cmdName show-questions [<modkey> <modans>]...
|
||||||
$cmdName [-v] [-d FILE]
|
$cmdName [-v] [-d FILE] --hostname NAME
|
||||||
|
|
||||||
Set energy, network and basic preferences.
|
Set energy, network and basic preferences.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
|
--hostname NAME Set NAME as current host's host name.
|
||||||
-d FILE, --logfile FILE Print log message to logfile instead of stdout.
|
-d FILE, --logfile FILE Print log message to logfile instead of stdout.
|
||||||
-v, --verbose Be more verbose.
|
-v, --verbose Be more verbose.
|
||||||
----
|
----
|
||||||
|
|||||||
Reference in New Issue
Block a user