Mac - Generic DMG Installer - JumpCloud

Mac - Generic DMG Installer - JumpCloud

Name

Mac - Generic DMG Installer - JumpCloud

Content- 

#!/bin/bash
# *** USAGE *** Version: 1.2

# *NOTE* this template is only designed to work with DMG files and does not support .pkg, .zip files or DMGs that contain .pkg installers.

# Update the DownloadUrl="" variable with the URL of the target .DMG download file. This URL must resolve to a .DMG file directly or point to a URL which has the .DMG file in the curl header Location field.

# The command: 'curl -s --head $DownloadUrl' can be used to query a given URLs header to determine if the Location field points to a .DMG file.
 

Process - 

1. Log in to the JumpCloud Admin Portal.
2. Go to Devices > Commands.
3. Click the "+" to create a new command.
4. Select macOS as the type.
5. Enter a name and the shell script command.
6. Assign it to a device or device group.
7. Click Save.

Command- 

DownloadUrl="DOWNLOAD_URL"
### Modify below this line at your own risk!
# Locate DMG Download Link From URL
regex='^https.*.dmg$'
if [[ $DownloadUrl =~ $regex ]]; then
    echo "URL points to direct DMG download"
    validLink="True"
else
    echo "Searching headers for download links"
    urlHead=$(curl -s --head "$DownloadUrl")
    locationSearch=$(echo "$urlHead" | grep https:)
    if [ -n "$locationSearch" ]; then
        locationRaw=$(echo "$locationSearch" | awk '{print $2}')
        locationFormatted="$(echo "${locationRaw}" | tr -d '[:space:]')"
        regex='^https.*'
        if [[ $locationFormatted =~ $regex ]]; then
            echo "Download link found"
            DownloadUrl="$locationFormatted"
        else
            echo "No https location download link found in headers"
            exit 1
        fi
    else
        echo "No location download link found in headers"
        exit 1
    fi
fi
# Create Temp Folder
DATE=$(date '+%Y-%m-%d-%H-%M-%S')
TempFolder="Download-$DATE"
mkdir -p "/tmp/$TempFolder"
# Navigate to Temp Folder
cd "/tmp/$TempFolder" || exit
# Download File into Temp Folder
curl -s -O "$DownloadUrl"
# Capture name of Download File
DownloadFile="$(ls)"
echo "Downloaded $DownloadFile to /tmp/$TempFolder"
# Verify DMG File
regex='\.dmg$'
if [[ $DownloadFile =~ $regex ]]; then
    DMGFile="$DownloadFile"
    echo "DMG File Found: $DMGFile"
else
    echo "File: $DownloadFile is not a DMG"
    rm -r "/tmp/$TempFolder"
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi
# Mount DMG File (-nobrowse prevents the volume from popping up in Finder)
hdiutilAttach=$(hdiutil attach "/tmp/$TempFolder/$DMGFile" -nobrowse)
echo "Used hdiutil to mount $DMGFile"
err=$?
if [ ${err} -ne 0 ]; then
    echo "Could not mount $DMGFile Error: ${err}"
    rm -r "/tmp/$TempFolder"
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi
regex='\/Volumes\/.*'
if [[ $hdiutilAttach =~ $regex ]]; then
    DMGVolume="${BASH_REMATCH[0]}"
    echo "Located DMG Volume: $DMGVolume"
else
    echo "DMG Volume not found"
    rm -r "/tmp/$TempFolder"
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi
# Identify the mount point for the DMG file
DMGMountPoint=$(hdiutil info | grep "$DMGVolume" | awk '{ print $1 }')
echo "Located DMG Mount Point: $DMGMountPoint"
# Capture name of App file
cd "$DMGVolume" || exit
AppName=$(ls | grep '.app')
cd ~ || exit
echo "Located App: $AppName"
# Test to ensure App is not already installed
ExistingSearch=$(find "/Applications/" -name "$AppName" -depth 1)
if [ -n "$ExistingSearch" ]; then
    echo "$AppName already present in /Applications folder"
    hdiutil detach "$DMGMountPoint"
    echo "Used hdiutil to detach $DMGFile from $DMGMountPoint"
    rm -r "/tmp/$TempFolder"
    echo "Deleted /tmp/$TempFolder"
    exit 1
else
    echo "$AppName not present in /Applications folder"
fi
DMGAppPath=$(find "$DMGVolume" -name "*.app" -depth 1)
# Copy the contents of the DMG file to /Applications/
# Preserves all file attributes and ACLs
cp -pPR "$DMGAppPath" /Applications/
err=$?
if [ ${err} -ne 0 ]; then
    echo "Could not copy $DMGAppPath Error: ${err}"
    hdiutil detach "$DMGMountPoint"
    echo "Used hdiutil to detach $DMGFile from $DMGMountPoint"
    rm -r "/tmp/$TempFolder"
    echo "Deleted /tmp/$TempFolder"
    exit 1
fi
echo "Copied $DMGAppPath to /Applications"
# Unmount the DMG file
hdiutil detach "$DMGMountPoint"
echo "Used hdiutil to detach $DMGFile from $DMGMountPoint"
err=$?
if [ ${err} -ne 0 ]; then
    echo "Could not detach DMG: $DMGMountPoint Error: ${err}"
fi
# Remove Temp Folder and download
rm -r "/tmp/$TempFolder"
echo "Deleted /tmp/$TempFolder"


Examples of some Dmg Download URL's - 

4. https://slack.com/ssb/download-osx

For More Information Visit this Article:

    • Related Articles

    • Deploy Netskope Client for Mac using Jumpcloud MDM

      Silent deploy the Netskope Client on Mac devices using IDP enrollment mode with Jumpcloud MDM Prerequisite: SAML Forward Proxy integration with Jumpcloud as an IDP must be configured prior to deploying the Netskope Client Configuration Steps 1 - ...
    • Jumpcloud LDAP Integration with Synology NAS

      Environment / Prerequisite Your Synology NAS must be running DSM 7.0 or above. Contents Bind users to JumpCloud LDAP Configure groups Enable Samba authentication for JumpCloud LDAP Join your Synology NAS to JumpCloud LDAP Resolution Bind users to ...
    • Suspended Mac user unlock

      Re-Enable a Disabled Mac User Account When you remove access to a Mac from a user in JumpCloud, the user account is disabled, not deleted. The user’s files and data are preserved, but disabled users will not appear on: The macOS login screen System ...
    • Deleting Unwanted User Profiles from macOS and Windows using JumpCloud

      Deleting Unwanted User Profiles from macOS and Windows using JumpCloud Overview This guide provides steps to identify and remove unwanted/suspended user profiles from macOS and Windows systems through JumpCloud Commands. It ensures that only the ...
    • Mac User Profile Locked/Disabled – Resolution Guide

      Issue Summary Name: Mac User Profile Got Locked/Disabled Possible Reasons for Locked/Disabled Account 1. Exceeding the allowed number of incorrect password attempts. 2. Jumpcloud password doesn’t match the local account. it may trigger a lockout 3. ...