From ac22108e093e0a15614c021ac6ccaf735bdf8d7f Mon Sep 17 00:00:00 2001
From: hkystar35 <32749858+hkystar35@users.noreply.github.com>
Date: Thu, 6 Jul 2023 16:41:49 -0600
Subject: [PATCH 1/2] Added test options
---
.../Get-LatestOSSupported.sh | 40 ++++++++++++++++---
1 file changed, 35 insertions(+), 5 deletions(-)
diff --git a/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh b/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
index f1b257c..140ce9e 100644
--- a/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
+++ b/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
@@ -1,15 +1,22 @@
-#!/bin/bash
+#!/usr/bin/env bash
# set -x
####################################################################################################
# Script Name: Get-LatestOSSupported.sh
# By: Zack Thompson / Created: 9/26/2017
-# Version: 2.4.1 / Updated: 6/5/2023 / By: ZT
+# Version: 2.4.2 / Updated: 7/6/2023 / By: Nic Wendlowsky
#
# Description: A Jamf Pro Extension Attribute to check the latest compatible version of macOS.
#
# Updates: For each OS version released, a new Regex string and each function will need to be
# updated.
+# New Feature - When running as standalone script, you can pass a Model number and OS version
+# to the script to validate regex.
+# EXAMPLE
+# % sudo ./Get-LatestOSSupported.sh "MacBookPro13,3" "12.0"
+# Test OS value: 12.0
+# Test Model value: MacBookPro13,3
+# Monterey
#
# System Requirements can be found here:
# Full List - https://support.apple.com/en-us/HT211683
@@ -31,6 +38,19 @@
#
####################################################################################################
+##################################################
+# Define test values
+
+# Allow for specifying a Model and OS Version to the script to validate regex.
+# If these values are passed, the write_to_ea_history function is ignored so that
+# incorrect information is not written to the test computer.
+# Supported actions:
+# TEST_MODEL - example: "MacBookPro13,3"
+# TEST_OS - example: "14.0"
+
+TEST_MODEL="$1"
+TEST_OS="$2"
+
##################################################
# Define organization's environment values
@@ -66,7 +86,7 @@ write_to_ea_history() {
local key="${1}"
local value="${2}"
- if [[ "${locally_log}" == "true" ]]; then
+ if [[ "${locally_log}" == "true" && ${TEST_OS} == "" && ${TEST_MODEL} == "" ]]; then
if [[ ! -e "${local_inventory}" ]]; then
@@ -367,13 +387,23 @@ storage_check() {
bytes_in_gigabytes="1073741824" # $((1024 * 1024 * 1024)) # Transforms one gigabyte into bytes
# Get the current OS version
-os_version=$( /usr/bin/sw_vers -productVersion )
+if [[ ! ${TEST_OS} == "" ]]; then
+ os_version="$TEST_OS"
+ echo "Test OS value: ${TEST_OS}"
+ else
+ os_version=$( /usr/bin/sw_vers -productVersion )
+fi
current_os_major=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $1}' )
current_os_minor=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $2}' )
current_os_patch=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $3}' )
# Get the Model Type
-mac_model=$( /usr/sbin/sysctl -n hw.model )
+if [[ ! ${TEST_MODEL} == "" ]]; then
+ mac_model="$TEST_MODEL"
+ echo "Test Model value: ${TEST_MODEL}"
+ else
+ mac_model=$( /usr/sbin/sysctl -n hw.model )
+fi
# Check for compatibility
model_result=$( model_check "${mac_model}" )
From ae92a637a0234ebc14e32822aede80e23bbe120b Mon Sep 17 00:00:00 2001
From: Zack T
Date: Wed, 6 Sep 2023 11:06:58 -0700
Subject: [PATCH 2/2] Minor tweaks and formatting changes
---
.../Get-LatestOSSupported.sh | 58 ++++++++++---------
1 file changed, 31 insertions(+), 27 deletions(-)
diff --git a/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh b/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
index 140ce9e..1835fce 100644
--- a/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
+++ b/Jamf Pro/Extension Attributes/Get-LatestOSSupported.sh
@@ -1,22 +1,25 @@
-#!/usr/bin/env bash
+#!/bin/bash
# set -x
####################################################################################################
# Script Name: Get-LatestOSSupported.sh
# By: Zack Thompson / Created: 9/26/2017
-# Version: 2.4.2 / Updated: 7/6/2023 / By: Nic Wendlowsky
+# Version: 2.5.0 / Updated: 7/6/2023 / By: Nic Wendlowsky
#
# Description: A Jamf Pro Extension Attribute to check the latest compatible version of macOS.
#
+# New Feature: When running as standalone script, you can pass a Model number and OS version
+# to the script to validate regex.
+# EXAMPLE
+# $ bash ./Get-LatestOSSupported.sh "MacBookPro13,3" "12.0"
+# Test OS value: 12.0
+# Test Model value: MacBookPro13,3
+# Monterey
+#
+# Courtesy of Nic Wendlowsky (@hkystar35)
+#
# Updates: For each OS version released, a new Regex string and each function will need to be
# updated.
-# New Feature - When running as standalone script, you can pass a Model number and OS version
-# to the script to validate regex.
-# EXAMPLE
-# % sudo ./Get-LatestOSSupported.sh "MacBookPro13,3" "12.0"
-# Test OS value: 12.0
-# Test Model value: MacBookPro13,3
-# Monterey
#
# System Requirements can be found here:
# Full List - https://support.apple.com/en-us/HT211683
@@ -42,14 +45,14 @@
# Define test values
# Allow for specifying a Model and OS Version to the script to validate regex.
-# If these values are passed, the write_to_ea_history function is ignored so that
-# incorrect information is not written to the test computer.
+# If these values are passed, the write_to_ea_history function is ignored so that incorrect
+# information is not written to the test computer.
# Supported actions:
-# TEST_MODEL - example: "MacBookPro13,3"
-# TEST_OS - example: "14.0"
+# TEST_MODEL - example: "MacBookPro13,3"
+# TEST_OS - example: "14.0"
-TEST_MODEL="$1"
-TEST_OS="$2"
+TEST_MODEL="${1}"
+TEST_OS="${2}"
##################################################
# Define organization's environment values
@@ -86,7 +89,7 @@ write_to_ea_history() {
local key="${1}"
local value="${2}"
- if [[ "${locally_log}" == "true" && ${TEST_OS} == "" && ${TEST_MODEL} == "" ]]; then
+ if [[ "${locally_log}" == "true" && -z "${TEST_OS}" && -z "${TEST_MODEL}" ]]; then
if [[ ! -e "${local_inventory}" ]]; then
@@ -387,22 +390,23 @@ storage_check() {
bytes_in_gigabytes="1073741824" # $((1024 * 1024 * 1024)) # Transforms one gigabyte into bytes
# Get the current OS version
-if [[ ! ${TEST_OS} == "" ]]; then
- os_version="$TEST_OS"
- echo "Test OS value: ${TEST_OS}"
- else
- os_version=$( /usr/bin/sw_vers -productVersion )
+if [[ -z "${TEST_OS}" ]]; then
+ os_version=$( /usr/bin/sw_vers -productVersion )
+else
+ os_version="${TEST_OS}"
+ echo "Test OS value: ${TEST_OS}"
fi
+
current_os_major=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $1}' )
current_os_minor=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $2}' )
current_os_patch=$( echo "${os_version}" | /usr/bin/awk -F '.' '{print $3}' )
# Get the Model Type
-if [[ ! ${TEST_MODEL} == "" ]]; then
- mac_model="$TEST_MODEL"
- echo "Test Model value: ${TEST_MODEL}"
- else
- mac_model=$( /usr/sbin/sysctl -n hw.model )
+if [[ -z "${TEST_MODEL}" ]]; then
+ mac_model=$( /usr/sbin/sysctl -n hw.model )
+else
+ mac_model="${TEST_MODEL}"
+ echo "Test Model value: ${TEST_MODEL}"
fi
# Check for compatibility
@@ -464,4 +468,4 @@ else
fi
-exit 0
\ No newline at end of file
+exit 0