-
Notifications
You must be signed in to change notification settings - Fork 5
/
JamfPro-Casper-ComputerName-Ask_Complex.sh
executable file
·71 lines (50 loc) · 1.61 KB
/
JamfPro-Casper-ComputerName-Ask_Complex.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
68
69
70
71
#!/bin/bash
#Author: https://github.com/aarondavidpolley
#Purpose: Request a computer asset number and then combines with prefix and room number to create and set Computer Name
#Feature: Supports script variable $4 to set the Prefix (without dash)
#Feature: Supports script variable $5 to set the room number
# Make sure we have an active desktop
dockStatus=$(pgrep -x Dock)
echo "Waiting for Desktop"
while [ "$dockStatus" == "" ]; do
echo "Desktop is not loaded. Waiting."
sleep 5
dockStatus=$(pgrep -x Dock)
done
AssetNumRAW=$(/usr/bin/osascript << EOT
tell application "System Events"
activate
set InputName to display dialog "Enter Asset Number of this Mac, i.e 09555" with icon caution default answer "" buttons{"Continue"}
end tell
EOT
)
AssetNum=$(echo "$AssetNumRAW" | awk -F':' '{print $3}')
#Check if custom variable is empty
if [ -z $4 ]; then
#If empty, use script logic for name
Prefix="M"
else
#If defined, use variable
Prefix="$4"
fi
#Check if custom variable is empty
if [ -z $5 ]; then
#If empty, use script logic for name
RoomNum="0000"
else
#If defined, use variable
RoomNum="$5"
fi
NewName="$Prefix-$RoomNum-$AssetNum"
echo "$NewName"
#Use Scutil Binary to set computername
/usr/sbin/scutil --set ComputerName "$NewName"
/usr/sbin/scutil --set HostName "$NewName"
/usr/sbin/scutil --set LocalHostName "$NewName"
#Report the name(s) that have been set#
ComputerName=$(/usr/sbin/scutil --get ComputerName)
HostName=$(/usr/sbin/scutil --get HostName)
LocalHostName=$(/usr/sbin/scutil --get LocalHostName)
echo "ComputerName: $ComputerName"
echo "HostName: $HostName"
echo "LocalHostName: $LocalHostName"