Skip to content

Commit

Permalink
Adds examples & install script
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesiscoding committed Mar 11, 2021
1 parent 720db1f commit 0e10784
Show file tree
Hide file tree
Showing 5 changed files with 399 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ While it was designed for use with Jamf Pro, it may be used with or MDM systems,

## Installation, Dependencies, and Compatibility

For normal installation, simply download the `jhelper.phar` to your utility path, and rename it, for example `/usr/local/bin/jhelper`. For installation on client systems, it is recommended that you use a policy with a script. See the `/resources` directory for an example.
For installation on client systems, it is recommended that you use a policy that runs a script, called via a trigger. See the `/resources` directory for an example. Once you have a policy created, you can use **jhelper** in your scripts by adding the following lines:

At this time, JSS Helper has no dependencies when used in macOS High Sierra, Mojave, Catalina, or Big Sur
[ -n "$(which jhelper)" ] || jamf policy --trigger <POLICY TRIGGER HERE> || (echo "ERROR: JHelper Not Installed" && exit 1)
source "$(jhelper prep)"

At this time, JSS Helper has no dependencies when used in macOS High Sierra, Mojave, Catalina, or Big Sur.

For testing, simply download the `jhelper.phar` to your utility path, and rename it, for example `/usr/local/bin/jhelper`.

## Script Output Helpers

Expand Down
8 changes: 8 additions & 0 deletions resources/_jhelper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# shellcheck shell=bash
# NOTE THIS FILE IS FOR USE IN THE EXAMPLES ONLY; USE 'jhelper prep' to generate.
JHELPER="../dist/jhelper.phar"
JH_PASS="${JHELPER} badge --format=pass "
JH_SUCCESS="${JHELPER} badge --format=success "
JH_FAIL="${JHELPER} badge --format=fail "
JH_ERROR="${JHELPER} badge --format=error "
JH_MSG="${JHELPER} msg --width=50 "
79 changes: 79 additions & 0 deletions resources/install-adobe-reader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

### region ############################################ DocBlock
#
# Installs the latest Adobe Acrobat Reader DC version, using
# JHelper for the heavy lifting.
#
# Credit to Joe Farage for the concepts in the version function(s)
# which were adapted from his scripts, written 3/18/2015.
#
### endregion ######################################### DocBlock

### region ############################################ Dependencies

[ -n "$(which jhelper)" ] || jamf policy --trigger InstallJHelper || (echo "ERROR: JHelper Not Installed" && exit 1)

# shellcheck source=_jhelper.sh
source "$(jhelper prep)"

### endregion ######################################### Dependencies

### region ############################################ Functions

function getLatestVersion() {
local OSvers_URL userAgent latestver latestvernorm i

## Get OS version and adjust for use with the URL string
OSvers_URL=$( sw_vers -productVersion | sed 's/[.]/_/g' )

## Set the User Agent string for use with curl
userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X ${OSvers_URL}) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2"

# Get the latest version of Adobe Reader DC available from Adobe Reader page.
for i in {1..5}
do
if [ -z "$latestver" ]; then
latestver=$(curl -LSs -A "$userAgent" "https://get.adobe.com/reader" | grep "id=\"AUTO_ID_columnleft_p_version\"" | awk -F '\\>Version ' '{print $NF}' | awk -F\< '{print $1}')
fi
done

if [ -n "$latestver" ]; then
latestvernorm=$(echo "${latestver}" | sed -e 's/20//')
echo "$latestvernorm"
fi

return 0
}

function getAdobeReaderUrl() {
local VERSION NORMALIZED

VERSION=${1}
NORMALIZED=$( echo "${VERSION}" | sed -e 's/[.]//g' )

echo "http://ardownload2.adobe.com/pub/adobe/reader/mac/AcrobatDC/${NORMALIZED}/AcroRdrDC_${NORMALIZED}_MUI.dmg"

return 0;
}

### endregion ######################################### Functions

# Display Message
echo ""
$JH_MSG "Checking Current Version"
# Get Current Version
CURRENT=$(getLatestVersion)
# Display Badge & Exit if No Version Given
([ -n "${CURRENT}" ] && $JH_SUCCESS) || ($JH_ERROR && exit 1)

# Set Variables
APP_PATH="/Applications/Adobe Acrobat Reader DC.app"
APP_URL=$(getAdobeReaderUrl "${CURRENT}")

# Install DMG
if $JHELPER install:dmg "${APP_PATH}" "${APP_URL}" --target="${CURRENT}"; then
echo "" && exit 0
else
echo "" && exit 1
fi
60 changes: 60 additions & 0 deletions resources/install-chrome.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

### region ############################################ DocBlock
#
# Installs the latest Google Chrome Enterprise version, using
# JHelper for the heavy lifting.
#
# Credit to Joe Farage for the concepts in the version function(s)
# which were adapted from his scripts, written 3/18/2015.
#
### endregion ######################################### DocBlock

### region ############################################ Dependencies

[ -n "$(which jhelper)" ] || jamf policy --trigger InstallJHelper || (echo "ERROR: JHelper Not Installed" && exit 1)

# shellcheck source=_jhelper.sh
source "$(jhelper prep)"

### endregion ######################################### Dependencies

### region ############################################ Functions

function getLatestVersion() {
local OSvers_URL userAgent lVersion
## Get OS version and adjust for use with the URL string
OSvers_URL=$( sw_vers -productVersion | sed 's/[.]/_/g' )

## Set the User Agent string for use with curl
userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X ${OSvers_URL}) AppleWebKit/535.6.2 (KHTML, like Gecko) Version/5.2 Safari/535.6.2"

# Get the latest version of Firefox available from Firefox page.
lVersion=$(/usr/bin/curl -s -A "$userAgent" https://omahaproxy.appspot.com/json | jq -r ".[] | select(.os==\"mac\").versions[] | select(.channel==\"stable\").current_version" )
if [ -z "$lVersion" ]; then
lVersion="ERROR"
fi

echo "${lVersion}"
}

### endregion ######################################### Functions

# Display Message
echo ""
$JH_MSG "Checking Current Version"
# Get Current Version
CURRENT=$(getLatestVersion)
# Display Badge & Exit if No Version Given
([ -n "${CURRENT}" ] && $JH_SUCCESS) || ($JH_ERROR && exit 1)

# Set Variables
APP_URL='https://dl.google.com/chrome/mac/stable/gcem/GoogleChrome.pkg'
APP_PATH="/Applications/Google Chrome.app"

# Install DMG
if $JHELPER install:pkg "${APP_PATH}" "${APP_URL}" --target="${CURRENT}"; then
echo "" && exit 0
else
echo "" && exit 1
fi
Loading

0 comments on commit 0e10784

Please sign in to comment.