Skip to content

Commit

Permalink
Updated Mac Silent Installer logic.
Browse files Browse the repository at this point in the history
- Using new  -createaccount_or_signinaccount flag
- Uses computername fallback logic in case Username doesnt provide valid email
- Adds region support
  • Loading branch information
udarag committed Apr 29, 2022
1 parent f63c6c6 commit b5a73fe
Showing 1 changed file with 56 additions and 28 deletions.
84 changes: 56 additions & 28 deletions DeploymentScripts/Mac/JAMF_silentinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

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

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

# BZERROR MEANINGS
# BZERROR:190 - The System Preferences process is running on the computer. Close System Preferences and retry the installation.
# 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.
# 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,

var=0

################ FUNCTIONS #########################
function updateBackblaze {
return=$(sudo /Volumes/Backblaze\ Installer/Backblaze\ Installer.app/Contents/MacOS/bzinstall_mate -upgrade bzdiy)
}

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

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

function emailValidation {
[[ "$email" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]
rc=$?
if [ "$rc" != "0" ]
then
echo "The email retrieved from JAMF [$email] is an invalid email address"
echo "Please make sure JAMF credentials have READ access on the user object and endpoints have emails properly set"
exit 1
if [ "$var" = 1 ]
then
echo "Failed to retrieve valid email address from JAMF API. Parsed Email: [ $email ]"
echo "Please make sure JAMF credentials have READ access on the user object and endpoints have emails properly set"
exit 1
else
echo "Failed to retrieve valid email address from JAMF API. Attempting to use computername"
jamfAPIComputername
fi
else
echo "The email retrieved from JAMF [$email] seems to be a valid email address"
echo "The email retrieved from JAMF API [ $email ] seems to be a valid email address"
echo "Continuing with install"
fi
}

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

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

function jamfAPIComputername {
echo "Making GET request to Classic JAMF API using Computer Name"
response=$(curl -s "https://$JAMF_domain.jamfcloud.com/JSSResource/computers/name/$computername" -u "$JAMF_username:$JAMF_password")

email=$(echo $response | /usr/bin/awk -F'<email_address>|</email_address>' '{print $2}')
var=1
emailValidation
}

function successExit {
echo "Unmounting Installer..."
diskutil unmount /Volumes/Backblaze\ Installer
Expand Down Expand Up @@ -102,14 +125,14 @@ if open -Ra "Backblaze" ;
updateBackblaze
if [ "$return" == "BZERROR:1001" ]
then
echo Backblaze successfully updated
echo "Backblaze successfully updated"
successExit
else
#Try upgrade again incase there was a file lock on the mounted dmg causing errors
updateBackblaze
if [ "$return" == "BZERROR:1001" ]
then
echo Backblaze successfully updated
echo "Backblaze successfully updated"
successExit
else
echo "Backblaze was already installed but failed to update"
Expand All @@ -122,34 +145,39 @@ fi

#If email wasnt passed in from parameters, assume we need to access JAMF API to retrieve it
if [ "$email" == "" ]
then
echo "Email not hardcoded, attempting to pull from JAMF Pro API"
jamfAPI
then
echo "Email not hardcoded, attempting to pull from JAMF Pro API"
jamfAPIUsername
fi

echo "Trying to sign in account"
signinBackblaze
if [ "$return" == "BZERROR:1001" ]
then
echo Backblaze installed, $email already had an account with Backblaze
successExit
else
echo "Account doesnt exist, trying to create account"
createaccountBackblaze

if [ "$region" == "" ]
then
signinBackblaze
if [ "$return" == "BZERROR:1001" ]
then
echo Backblaze installed, account created and licensed to $email
echo "Backblaze successfully installed, $email signed in..."
successExit
else
echo "Create account failed, trying signing in account again"
signinBackblaze
signinBackblaze
if [ "$return" == "BZERROR:1001" ]
then
echo Backblaze installed, $email already had an account with Backblaze
echo "Backblaze successfully installed, $email signed in..."
successExit
else
echo Failed to install Backblaze, errorcode: $return
echo "Failed to install Backblaze, errorcode: $return"
failureExit
fi
fi
else
createRegionAccount
if [ "$return" == "BZERROR:1001" ]
then
echo "Backblaze account successfully created in $region, $email signed in..."
successExit
else
echo "Failed to install Backblaze, errorcode: $return"
failureExit
fi
fi

0 comments on commit b5a73fe

Please sign in to comment.