forked from alrra/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
computer_name.sh
executable file
·67 lines (45 loc) · 2.29 KB
/
computer_name.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")" \
&& . "../../utils.sh"
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# ----------------------------------------------------------------------
# | Main |
# ----------------------------------------------------------------------
main() {
local skipQuestions=false
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
skip_questions "$@" \
&& skipQuestions=true
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
print_in_purple "\n UI & UX\n\n"
declare -r netBiosName=$(defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName 2> /dev/null)
declare -r computerName=$(scutil --get ComputerName 2> /dev/null)
declare -r hostName=$(scutil --get HostName 2> /dev/null)
declare -r localHostName=$(scutil --get LocalHostName 2> /dev/null)
print_in_yellow "\
Current NetBIOS name: $netBiosName\n\
Current Computer name: $computerName\n\
Current Host name: $hostName\n\
Current Local Host name: $localHostName\n\n"
if ! $skipQuestions; then
ask_for_confirmation "Do you want to set the computer name?"
fi
if $skipQuestions || answer_is_yes; then
$skipQuestions && newComputerName="laptop" || newComputerName=""
while [ -z "$newComputerName" ]; do # -z : True if the length of string is zero.
ask "Please specify a computer name: "
newComputerName="$(get_answer)"
done
# System Preferences -> Sharing -> Computer Name
# http://osxdaily.com/2012/10/24/set-the-hostname-computer-name-and-bonjour-name-separately-in-os-x/
execute "sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string '$newComputerName' && \
sudo scutil --set ComputerName '$newComputerName' && \
sudo scutil --set HostName '$newComputerName' && \
sudo scutil --set LocalHostName '$newComputerName'" \
"Set computer name to $newComputerName"
printf "\n"
killall "SystemUIServer" &> /dev/null
fi
}
# Pass '-y' to script to skip questions
main "$@"