Skip to content

Commit b5a73fe

Browse files
committed
Updated Mac Silent Installer logic.
- Using new -createaccount_or_signinaccount flag - Uses computername fallback logic in case Username doesnt provide valid email - Adds region support
1 parent f63c6c6 commit b5a73fe

File tree

1 file changed

+56
-28
lines changed

1 file changed

+56
-28
lines changed

DeploymentScripts/Mac/JAMF_silentinstall.sh

Lines changed: 56 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# The following parameters are pulled directly from the "Parameter Values" section of your Backblaze deployment policy.
44
# Please make sure they are filled out respectively prior to your push
5+
computername="$2"
56
username="$3"
67
groupid="$4"
78
grouptoken="$5"
89
email="$6" #If email is entered in parameters, script will skip over using JAMF API, make sure related password is entered as well
9-
password="$7"
10+
region="$7" #Specify if account is to be deployed in specific region [us-west or eu-central]
1011
JAMF_domain="$8"
1112

1213
# The script needs access to the JAMF Pro API to gather related the related email for a given user
@@ -15,41 +16,63 @@ JAMF_domain="$8"
1516
JAMF_username="$9"
1617
JAMF_password="${10}"
1718

19+
# BZERROR MEANINGS
20+
# BZERROR:190 - The System Preferences process is running on the computer. Close System Preferences and retry the installation.
21+
# BZERROR:1000 - This is a general error code. One possible reason is that the Backblaze installer doesn’t have root permissions and is failing. Please see the install log file for more details.
22+
# BZERROR:1016/1003 - Login Error... Email account exists but is not a member of indicated Group, Group ID is incorrect, or Group token is incorrect,
23+
24+
var=0
25+
1826
################ FUNCTIONS #########################
1927
function updateBackblaze {
2028
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -upgrade bzdiy)
2129
}
2230

2331
function signinBackblaze {
24-
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -nogui -signin $email $password)
32+
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -nogui -createaccount_or_signinaccount $email $groupid $grouptoken)
2533
}
2634

27-
function createaccountBackblaze {
28-
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -nogui -createaccount $email $password $groupid $grouptoken)
35+
function createRegionAccount {
36+
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -nogui -createaccount_or_signinaccount $email $groupid $grouptoken $region)
2937
}
3038

3139
function emailValidation {
3240
[[ "$email" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]
3341
rc=$?
3442
if [ "$rc" != "0" ]
3543
then
36-
echo "The email retrieved from JAMF [$email] is an invalid email address"
37-
echo "Please make sure JAMF credentials have READ access on the user object and endpoints have emails properly set"
38-
exit 1
44+
if [ "$var" = 1 ]
45+
then
46+
echo "Failed to retrieve valid email address from JAMF API. Parsed Email: [ $email ]"
47+
echo "Please make sure JAMF credentials have READ access on the user object and endpoints have emails properly set"
48+
exit 1
49+
else
50+
echo "Failed to retrieve valid email address from JAMF API. Attempting to use computername"
51+
jamfAPIComputername
52+
fi
3953
else
40-
echo "The email retrieved from JAMF [$email] seems to be a valid email address"
54+
echo "The email retrieved from JAMF API [ $email ] seems to be a valid email address"
4155
echo "Continuing with install"
4256
fi
4357
}
4458

45-
function jamfAPI {
46-
echo "Making GET request to Classic JAMF API"
59+
function jamfAPIUsername {
60+
echo "Making GET request to Classic JAMF API using Username"
4761
response=$(curl -s "https://$JAMF_domain.jamfcloud.com/JSSResource/users/name/$username" -u "$JAMF_username:$JAMF_password")
4862

4963
email=$(echo $response | /usr/bin/awk -F'<email_address>|</email_address>' '{print $2}')
5064
emailValidation
5165
}
5266

67+
function jamfAPIComputername {
68+
echo "Making GET request to Classic JAMF API using Computer Name"
69+
response=$(curl -s "https://$JAMF_domain.jamfcloud.com/JSSResource/computers/name/$computername" -u "$JAMF_username:$JAMF_password")
70+
71+
email=$(echo $response | /usr/bin/awk -F'<email_address>|</email_address>' '{print $2}')
72+
var=1
73+
emailValidation
74+
}
75+
5376
function successExit {
5477
echo "Unmounting Installer..."
5578
diskutil unmount /Volumes/Backblaze\ Installer
@@ -102,14 +125,14 @@ if open -Ra "Backblaze" ;
102125
updateBackblaze
103126
if [ "$return" == "BZERROR:1001" ]
104127
then
105-
echo Backblaze successfully updated
128+
echo "Backblaze successfully updated"
106129
successExit
107130
else
108131
#Try upgrade again incase there was a file lock on the mounted dmg causing errors
109132
updateBackblaze
110133
if [ "$return" == "BZERROR:1001" ]
111134
then
112-
echo Backblaze successfully updated
135+
echo "Backblaze successfully updated"
113136
successExit
114137
else
115138
echo "Backblaze was already installed but failed to update"
@@ -122,34 +145,39 @@ fi
122145

123146
#If email wasnt passed in from parameters, assume we need to access JAMF API to retrieve it
124147
if [ "$email" == "" ]
125-
then
126-
echo "Email not hardcoded, attempting to pull from JAMF Pro API"
127-
jamfAPI
148+
then
149+
echo "Email not hardcoded, attempting to pull from JAMF Pro API"
150+
jamfAPIUsername
128151
fi
129152

130153
echo "Trying to sign in account"
131-
signinBackblaze
132-
if [ "$return" == "BZERROR:1001" ]
133-
then
134-
echo Backblaze installed, $email already had an account with Backblaze
135-
successExit
136-
else
137-
echo "Account doesnt exist, trying to create account"
138-
createaccountBackblaze
154+
155+
if [ "$region" == "" ]
156+
then
157+
signinBackblaze
139158
if [ "$return" == "BZERROR:1001" ]
140159
then
141-
echo Backblaze installed, account created and licensed to $email
160+
echo "Backblaze successfully installed, $email signed in..."
142161
successExit
143162
else
144-
echo "Create account failed, trying signing in account again"
145-
signinBackblaze
163+
signinBackblaze
146164
if [ "$return" == "BZERROR:1001" ]
147165
then
148-
echo Backblaze installed, $email already had an account with Backblaze
166+
echo "Backblaze successfully installed, $email signed in..."
149167
successExit
150168
else
151-
echo Failed to install Backblaze, errorcode: $return
169+
echo "Failed to install Backblaze, errorcode: $return"
152170
failureExit
153171
fi
154172
fi
173+
else
174+
createRegionAccount
175+
if [ "$return" == "BZERROR:1001" ]
176+
then
177+
echo "Backblaze account successfully created in $region, $email signed in..."
178+
successExit
179+
else
180+
echo "Failed to install Backblaze, errorcode: $return"
181+
failureExit
182+
fi
155183
fi

0 commit comments

Comments
 (0)