Minor tweaks and formatting changes

This commit is contained in:
Zack T
2023-09-06 11:06:58 -07:00
committed by GitHub
parent ac22108e09
commit ae92a637a0

View File

@@ -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
# <result>Monterey</result>
#
# 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
# <result>Monterey</result>
#
# 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
exit 0