Skip to content

Commit

Permalink
CLOUD-3175: prevent parse error on macos version check (#93)
Browse files Browse the repository at this point in the history
@cobbr2 noticed this error while he was testing the recent m2/m3 mac
changes:
```
ln: /usr/local/bin/docker: File exists
ln: /usr/local/bin/docker-compose: File exists

Parse error: bad token
    <stdin>:1

Rancher Desktop has been installed successfully
```

This is caused by an undefined variable, so this PR fixes that.

Rick also suggested I rewrite the version checking logic to avoid using
`bc -l` to make it simpler.
  • Loading branch information
pb-dod authored Apr 12, 2024
1 parent fc83ddb commit 1ca5d3a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.53
0.1.54
2 changes: 1 addition & 1 deletion formula/ih-core.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class IhCore < Formula
VERSION="0.1.53"
VERSION="0.1.54"
desc "Brew formula for installing core tools used at Included Health engineering."
homepage "https://github.com/ConsultingMD/homebrew-ih-public"
license "CC BY-NC-ND 4.0"
Expand Down
9 changes: 4 additions & 5 deletions lib/core/rancher/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ RANCHER_AUGMENT_DST="$IH_DEFAULT_DIR/11_rancher.sh"
PLIST_SRC="$IH_CORE_LIB_DIR/core/rancher/io.rancherdesktop.profile.defaults.plist"
PLIST_DST="$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist"

REQUIRED_APPLE_SILICON_MACOS_VERSION="13.3"

# Check if the step has been installed and return 0 if it has.
# Otherwise return 1.
function ih::setup::core.rancher::test() {
Expand Down Expand Up @@ -51,10 +53,8 @@ function ih::setup::core.rancher::test() {

# Use vz (requires macOS >=13.3) instead of qemu on M3 macs to resolve issues.
# More details: https://github.com/lima-vm/lima/issues/1996
local macos_version=$(ih::arch::get_macos_version)
if ih::arch::is_m2_or_m3_mac; then
if (( $(echo "$macos_version < 13.3" | bc -l) )); then
ih::log::error "macOS version 13.3 or higher is required for M3 Macs."
if ! ih::arch::check_macos_version_compatibility "$REQUIRED_APPLE_SILICON_MACOS_VERSION"; then
return 1
elif ! grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "The PLIST file needs to be updated to use 'vz' for M3 Macs."
Expand Down Expand Up @@ -163,8 +163,7 @@ function ih::setup::core.rancher::install() {
# Use vz (requires macOS >=13.3) instead of qemu on M3 macs to resolve issues.
# More details: https://github.com/lima-vm/lima/issues/1996
if ih::arch::is_m2_or_m3_mac; then
if (( $(echo "$macos_version < 13.3" | bc -l) )); then
ih::log::error "macOS version 13.3 or higher is required for M3 Macs."
if ! ih::arch::check_macos_version_compatibility "$REQUIRED_APPLE_SILICON_MACOS_VERSION"; then
return 1 # Abort the installation for M3 Macs
elif ! grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "Updating PLIST to use 'vz' for Virtualization for M3 Macs."
Expand Down
22 changes: 22 additions & 0 deletions lib/utils/arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ ih::arch::get_macos_version() {
sw_vers -productVersion | awk -F '.' '{ printf("%d.%d\n", $1, $2) }'
}

ih::arch::check_macos_version_compatibility() {
local required_version="$1"
local current_version=$(ih::arch::get_macos_version)

# Splitting the current and required versions into major and minor components
IFS='.' read -r current_major current_minor _ <<< "$current_version"
IFS='.' read -r required_major required_minor _ <<< "$required_version"

# Ensure variables are integers (default to 0 if empty for robust comparison)
current_major=${current_major:-0}
current_minor=${current_minor:-0}
required_major=${required_major:-0}
required_minor=${required_minor:-0}

if (( current_major > required_major )) || { (( current_major == required_major )) && (( current_minor >= required_minor )); }; then
return 0 # meets minimum requirement
else
ih::log::error "macOS version $required_version or higher is required. Current version: $current_version."
return 1
fi
}

ih::arch::is_m2_or_m3_mac() {
local hw_model=$(sysctl -n machdep.cpu.brand_string)
[[ "$hw_model" == *"M2"* ]] || [[ "$hw_model" == *"M3"* ]]
Expand Down

0 comments on commit 1ca5d3a

Please sign in to comment.