Crashplan scripting question

AlistairCarr
New Contributor II

Hi all,

Hoping someone can help me here. We're going to be deploying crashplan ProE out to our org soon.

In the installer script on the local machine there is a variable for %CP_USERNAME% (or similar) which needs to be the individuals email address.

Is there anyway to pipe the casper $EMAIL variable into the Crashplan username variable?

We do not have AD/LDAP to perform this function unfortunately.

Once again, thank you all in advance.

2 ACCEPTED SOLUTIONS

dwandro92
Contributor III

Yes, this could be done using one of the following methods:

#!/bin/bash

###########################################################################################################
################## IMPORTANT - ENTER JSS INFORMATION IN "apiQuery" FUNCTION BEFORE USING ##################
###########################################################################################################

# Set field seperator to newline
IFS=$'
'

# Function for querying the JSS API
# Parameters:
# (1) URL Suffix for the page that needs to be queried.
# (2) Value that you are searching for within the JSS API.
apiQuery() {
    # Set full URL path to JSS hostname. Example:
    # jssURL="https://mycompany.mydomain.com:8443"
    jssURL=""

    # Set JSS API username. Example:
    # jssUser="CasperAPI"
    jssUser=""

    # Set JSS API password. Example:
    # jssPW="password"
    jssPW=""

    # If requesting JSON response
    if [ "$1" == "json" ]; then
        # Get data from JSS and return the JSON response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
        curl "$jssURL/JSSResource/$2" -H 'Accept: application/json' --user "$jssUser:$jssPW" --silent | python -m json.tool
    # If not requesting the JSON response
    else
        # Get data from JSS and return the XML response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
        curl -k "$jssURL/JSSResource/$1" --user "$jssUser:$jssPW" --silent | awk -F "<$2>|</$2>" '{ print $2 }'
    fi
}

###########################################################################################################
############################ OPTION 1 - GET EMAIL ADDRESS FROM COMPUTER RECORD ############################
###########################################################################################################

# Get hardware UUID/UDID of system
hwUDID=`system_profiler SPHardwareDataType | awk '/Hardware UUID/{ print $3 }'`

# Get assigned user's email address from the JSS computer record
assignedUserEmail=`apiQuery "computers/udid/$hwUDID/subset/location" email_address`

###########################################################################################################
############################## OPTION 2 - GET EMAIL ADDRESS FROM USER RECORD ##############################
###########################################################################################################

# Get currently logged in user
targetUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

# Get currently logged in user's email address from the JSS user record
currentUserEmail=`apiQuery "users/name/$targetUser" email`

# Output information
echo "Assigned User Email Address: $assignedUserEmail"
echo "Current User Email Address:  $currentUserEmail"

I hope this helps!

View solution in original post

dwandro92
Contributor III

The following white paper might help: Administering CrashPlan PROe with the Casper Suite

Basically, just use the code in the user info script (/Library/Application Support/CrashPlan/.custom/userInfo.sh) and set the "CP_USER_NAME" variable to the result of the command.

I created my installation package manually using Composer, and just put my custom.properties, userInfo.sh, and CrashPlan installer in /Library/Application Support/CrashPlan/.custom. In addition, I have a post-install script that runs the actual installer and removes the .custom directory once complete. The final piece of the puzzle is a custom script that is used in my deployment policies, which checks to ensure that requirements are met (i.e. the logged in user is the person that the machine is assigned to). If all of the requirements are met, it triggers the policy which actually installs the custom package.

View solution in original post

4 REPLIES 4

dwandro92
Contributor III

Yes, this could be done using one of the following methods:

#!/bin/bash

###########################################################################################################
################## IMPORTANT - ENTER JSS INFORMATION IN "apiQuery" FUNCTION BEFORE USING ##################
###########################################################################################################

# Set field seperator to newline
IFS=$'
'

# Function for querying the JSS API
# Parameters:
# (1) URL Suffix for the page that needs to be queried.
# (2) Value that you are searching for within the JSS API.
apiQuery() {
    # Set full URL path to JSS hostname. Example:
    # jssURL="https://mycompany.mydomain.com:8443"
    jssURL=""

    # Set JSS API username. Example:
    # jssUser="CasperAPI"
    jssUser=""

    # Set JSS API password. Example:
    # jssPW="password"
    jssPW=""

    # If requesting JSON response
    if [ "$1" == "json" ]; then
        # Get data from JSS and return the JSON response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
        curl "$jssURL/JSSResource/$2" -H 'Accept: application/json' --user "$jssUser:$jssPW" --silent | python -m json.tool
    # If not requesting the JSON response
    else
        # Get data from JSS and return the XML response. Add the "-k" switch to the "curl" command if SSL Cert is not trusted.
        curl -k "$jssURL/JSSResource/$1" --user "$jssUser:$jssPW" --silent | awk -F "<$2>|</$2>" '{ print $2 }'
    fi
}

###########################################################################################################
############################ OPTION 1 - GET EMAIL ADDRESS FROM COMPUTER RECORD ############################
###########################################################################################################

# Get hardware UUID/UDID of system
hwUDID=`system_profiler SPHardwareDataType | awk '/Hardware UUID/{ print $3 }'`

# Get assigned user's email address from the JSS computer record
assignedUserEmail=`apiQuery "computers/udid/$hwUDID/subset/location" email_address`

###########################################################################################################
############################## OPTION 2 - GET EMAIL ADDRESS FROM USER RECORD ##############################
###########################################################################################################

# Get currently logged in user
targetUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

# Get currently logged in user's email address from the JSS user record
currentUserEmail=`apiQuery "users/name/$targetUser" email`

# Output information
echo "Assigned User Email Address: $assignedUserEmail"
echo "Current User Email Address:  $currentUserEmail"

I hope this helps!

AlistairCarr
New Contributor II

You sir are a star, BUT how do i then get that information into the installer script that lives in the crashplan DMG on the local machine ?

dwandro92
Contributor III

The following white paper might help: Administering CrashPlan PROe with the Casper Suite

Basically, just use the code in the user info script (/Library/Application Support/CrashPlan/.custom/userInfo.sh) and set the "CP_USER_NAME" variable to the result of the command.

I created my installation package manually using Composer, and just put my custom.properties, userInfo.sh, and CrashPlan installer in /Library/Application Support/CrashPlan/.custom. In addition, I have a post-install script that runs the actual installer and removes the .custom directory once complete. The final piece of the puzzle is a custom script that is used in my deployment policies, which checks to ensure that requirements are met (i.e. the logged in user is the person that the machine is assigned to). If all of the requirements are met, it triggers the policy which actually installs the custom package.

AlistairCarr
New Contributor II

A massive thank you again, you've been a great help !!