1#!/bin/bash
2
3##############################################################################################################
4# renameMacCSV.sh
5# Modified by Reggie Santos
6# Last modified 05/31/2018
7# add auto-prefix function using system_profiler SPHardwareDataType | grep "Model Identifier" if not using Custom Prefix in parameter $4
8
9#Written by: Frederick Abeloos | Field Technician | Jamf
10#Created On: March 8th, 2018 / script is provided "AS IS" /
11
12#Purpose: Jamf Pro @enrollment script to rename the mac prior to binding to AD (optional)
13
14#Put this script in a policy with option AFTER (important when using .pkg)
15
16#Upload a pkg in JamfPro which puts an assettag.csv file in /tmp/assettags.csv
17#First column serialnumber and second column the desired assettag
18
19#OR use CURL to download any .csv from a public link
20
21# Optional: Create a policy with the directory binding payload and custom trigger 'bindToAD'
22
23##############################################################################################################
24
25### RENAMING SETTINGS ########################################################################################
26
27# Don't change any settings here. Use $4-$9 parameters in Jamf Pro script payload options.
28
29# First choose a naming convention for your Mac.
30# Custom Prefix can be set via the $4 parameter in the Jamf Pro policy.
31# Leave the parameter $4 in Jamf Pro empty if you like to auto-prefix computername base on "Model Identifier", e.g. type "MBP-" (without the quotes).
32prefix="$4"
33# Suffix will be set via the $5 parameter in the Jamf Pro policy (script payload).
34# Leave the parameter empty if no suffix is required. e.g. type "Mac_" (without the quotes).
35suffix="$5"
36# Choose serialnumber or assettag via the $6 parameter in the Jamf Pro policy (script payload).
37# Set it to "serialnumber" or "assettag" (without the quotes).
38namingType="$6"
39# Define if you are adding the .pkg with the /tmp/assettags.csv file or using curl to download any .csv file.
40# When using curl, the script below will download and rename the file to /tmp/assettags.csv
41# Type will be set via $7 paremeter in the Jamf Pro Policy. Type "curl" or "package" (without the quotes).
42csvType="$7"
43# Define the public link to the .csv file. Leave blank when using .pkg
44# Link will be set via th $8 parameter in the Jamf Pro policy. Add the full "https://URL" (without the quotes).
45csvURL="$8"
46# Path to local csv file, via package in same policy: pkg putting assettags.csv in /tmp/
47csvPath="/tmp/assettags.csv"
48# Do you want to bind or not? Set to "bind" or leave blank
49bindSetting="$9"
50
51### RENAMING SCRIPT ########################################################################################
52MBA=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "BookAir"`
53
54MBP=`/usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier" | grep "BookPro"`
55
56if [ "$4" == "" ] && [ "$MBP" == "" ] && [ "$MBA" != "" ]; then
57 prefix="MBA"
58elif [ "$4" == "" ] && [ "$MBA" == "" ] && [ "$MBP" != "" ]; then
59 prefix="MBP"
60elif [ "$4" == "" ] && [ "$MBA" == "" ] && [ "$MBP" == "" ]; then
61 prefix="MAC"
62
63fi
64
65if [ "$csvType" = "curl" ]; then
66
67 curl -L -o $csvPath $csvURL
68
69fi
70
71
72
73if [ "$namingType" = "serialnumber" ]; then
74
75 echo "using serialnumber"
76 jamf setComputerName -useSerialNumber -prefix $prefix -suffix $suffix
77
78elif [ "$namingType" = "assettag" ]; then
79
80 echo "using assettag"
81 jamf setComputerName -fromFile "$csvPath" -prefix $prefix -suffix $suffix
82
83fi
84
85### AD BINDING ###########################################################################################
86
87if [ "$bindSetting" = "bind" ]; then
88
89 echo "Binding to AD"
90
91 jamf policy -event bindToAD
92
93else echo "Not binding"
94
95fi
96
97
98### CLEAN UP #############################################################################################
99
100#delete the assettags.csv
101
102rm "$csvPath"
103
104#update Jamf Pro inventory
105jamf recon