-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhost-name-changer2.5.1
94 lines (77 loc) · 2.16 KB
/
host-name-changer2.5.1
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
#welcome to zackn9nes jamf hostname script
jamfbinary=$(/usr/bin/which jamf)
location=$4 #for jamf operator input #required
model=$5 #for jamf operator input #not required
#*** testing
location="NY"
#get (serial for) year
YEAR=$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' | grep -o '....$')
echo "last four is" $YEAR
#use that (serial) for actual year
MNF_YEAR=$(curl "https://support-sp.apple.com/sp/product?cc=`echo $YEAR`" |grep -Eo '[0-9]{4}')
echo "determined year is" $MNF_YEAR
#get model
initialhweval=$(sysctl hw.model)
if [[ $initialhweval == *"Pro"* ]];
then
echo "Pro detected proceeding to eval model type"
model="MBP"
elif [[ $initialhweval == *"Air"* ]];
then
echo "You have a macbook air, sorry to hear that"
model="MBA"
elif [[ $initialhweval == *"iMac"* ]];
then
echo "Desktop mac"
model="iMac"
elif [[ $initialhweval == *"mini"* ]];
then
echo "Desktop mac"
model="Mini"
elif [ -z "$initialhweval" ];
then
echo "computer unknown"
exit 1
echo $model
fi
#check user
user=$( scutil <<< "show State:/Users/ConsoleUser" | awk -F': ' '/[[:space:]]+Name[[:space:]]:/ { if ( $2 != "loginwindow" ) { print $2 }}' )
echo "detected location is" $location
echo "detected user is:" $user
#sanitize user
user=$(echo $user | sed 's/[^a-zA-Z0-9]//g')
#killswitch
if [ -z "$user" ]
then
echo "user is null exiting with error"
exit 1
elif [ $user = "root" ]
then
echo "user is root user failing gracefully"
exit 1
elif [ $user = "splash" ]
then
echo "user is splash user failing gracefully"
exit 1
elif ((MNF_YEAR <= 2000 && MNF_YEAR >= 2030)); then
echo "year is out of range just giving up on the year"
$MNF_YEAR = ''
elif [ -z "$location" ]
then
echo "Location is broken exiting with error either set variable manually or put in $4 of jamf pro"
exit 1
elif [ -z "$model" ]
then
echo "Model is broken exiting with error"
exit 1
else
echo "proceeding"
fi
#do all of the things
hostname="${location}-${model}-${MNF_YEAR}-${user}"
echo $hostname
#***testing!!
#read -n 1 -s -r -p "Press any key to continue"
$jamfbinary setComputerName -name "$hostname"
$jamfbinary recon