Script to download Java files and add them to quarantine (Primarily used for PhET Sims)

Kyle_vdk
New Contributor II

I began to get frustrated whenever a teacher requested a new PhET simulation be added to self service. I have to package in composer, add a script to quarantine the Java file so that students can open it. I finally decided to write a script for it and figured I'd share and take any input or ideas!

#!/bin/bash

##############################################
#
# Download and add Java files to quarantine.
#
##############################################
#
# USE
# Upload script to Jamf, create a new policy and use variable 4 for the direct download URL. 
# Use variable 5 for the EXACT file name
#
##############################################
#
# Version 1.0   
# Created February 1, 2019
#
#
#
#
#
#
#
#

#Get download URL from variable
downloadURL="$4"
quarantineSoftware="$5"

# Echo function
echoFunc () {
    # Date and Time function for the log file
    fDateTime () { echo $(date +"%a %b %d %T"); }

    # Title for beginning of line in log file
    Title="download $quarantineSoftware:"

    # Header string function
    fHeader () { echo $(fDateTime) $(hostname) $Title; }

    # Check for the log file
    if [ -e "/Library/Logs/download$quarantineSoftware.log" ]; then
        echo $(fHeader) "$1" >> "/Library/Logs/download$quarantineSoftware.log"
    else
        touch "/Library/Logs/download$quarantineSoftware.log"
        if [ -e "/Library/Logs/download$quarantineSoftware.log" ]; then
            echo $(fHeader) "$1" >> "/Library/Logs/download$quarantineSoftware.log"
        else
            echo "Failed to create log file, writing to JAMF log"
            echo $(fHeader) "$1" >> "/var/log/jamf.log"
        fi
    fi

    # Echo out
    echo $(fDateTime) ": $1"
}



echoFunc "Variable 4 is: $4"
echoFunc "Variable 5 is: $5"

echoFunc "Curling download file."
curl -s -o /tmp/"${5}" "${4}"

echoFunc "Copying download file."
cp -f /tmp/"$5" /Applications/

echoFunc "Adding to quarantine."
xattr -r -d com.apple.quarantine /Applications/"$5"

echoFunc "Removing temp file."
rm -f /tmp/"$5"

The only problem is that it can't be added to the dock or launchpad because it is a .jar. Next version I hope to add a piece to turn it into an App or see if I can alias it or something.

0 REPLIES 0