From eb56b66a0dc173db4b7b7efe05e55648f5d4e022 Mon Sep 17 00:00:00 2001 From: Paul Brown <67805647+pb-dod@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:19:00 -0500 Subject: [PATCH] prevent always detecting out-of-sync rancher plist file (#99) @JDuskey and @rachelkathleen were seeing the rancher step always saying "The PLIST file is out of sync": ``` DBUG: File /Users//Library/Preferences/io.rancherdesktop.profile.defaults.plist does not match source DBUG: The PLIST file is out of sync. ``` This is happening because the install step makes changes to the PLIST file, but the test step is comparing based on the original file - so it never takes those changes into account. This PR creates a temporary file, modifies it, and uses it for both the test and install steps. --- VERSION | 2 +- formula/ih-core.rb | 2 +- lib/core/rancher/step.sh | 64 +++++++++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/VERSION b/VERSION index 6167106..09d8256 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.58 +0.1.59 diff --git a/formula/ih-core.rb b/formula/ih-core.rb index 839b09d..39ee933 100644 --- a/formula/ih-core.rb +++ b/formula/ih-core.rb @@ -1,5 +1,5 @@ class IhCore < Formula - VERSION="0.1.58" + VERSION="0.1.59" 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" diff --git a/lib/core/rancher/step.sh b/lib/core/rancher/step.sh index 4408378..f8dcc68 100644 --- a/lib/core/rancher/step.sh +++ b/lib/core/rancher/step.sh @@ -14,9 +14,33 @@ PLIST_DST="$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist" REQUIRED_APPLE_SILICON_MACOS_VERSION="13.3" +TEMP_PLIST_DST="" # filled by create_temp_plist + +# Create a temporary plist file with our modifications, to allow for sharing logic between test/install. +# This allows us to avoid making a lot of different versions of the plist file. +function ih::setup::core.rancher::create_temp_plist() { + TEMP_PLIST_DST=$(mktemp /tmp/io.rancherdesktop.profile.defaults.XXXXXX) + cp -f "$PLIST_SRC" "$TEMP_PLIST_DST" + + # Use vz instead of qemu on M2+ macs to resolve issues. + # More details: https://github.com/lima-vm/lima/issues/1996 + if ih::arch::is_m2_or_m3_mac; then + ih::log::debug "Updating temporary PLIST to use 'vz' and 'virtiofs' for Virtualization for M2+ Macs." + sudo sed -i '' 's/qemu<\/string>/vz<\/string>/g' "$TEMP_PLIST_DST" + sudo sed -i '' 's/reverse-sshfs<\/string>/virtiofs<\/string>/g' "$TEMP_PLIST_DST" + fi + + return 0 +} + # Check if the step has been installed and return 0 if it has. # Otherwise return 1. function ih::setup::core.rancher::test() { + ih::setup::core.rancher::create_temp_plist + if [ $? -ne 0 ]; then + ih::log::error "Failed to create and modify the temporary PLIST file." + return 1 + fi # Check if Rancher was installed manually brew list rancher >/dev/null 2>&1 @@ -46,22 +70,15 @@ function ih::setup::core.rancher::test() { return 1 fi - if ! ih::file::check-file-in-sync "$PLIST_SRC" "$PLIST_DST"; then + if ! ih::file::check-file-in-sync "$TEMP_PLIST_DST" "$PLIST_DST"; then ih::log::debug "The PLIST file is out of sync." return 1 fi - # 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 + # VZ requires macOS >=13.3 if ih::arch::is_m2_or_m3_mac; then if ! ih::arch::check_macos_version_compatibility "$REQUIRED_APPLE_SILICON_MACOS_VERSION"; then return 1 - elif ! grep -q "vz" "$PLIST_DST"; then - ih::log::debug "The PLIST file needs to be updated to use 'vz' for M3 Macs." - return 1 - elif ! grep -q "virtiofs" "$PLIST_DST"; then - ih::log::debug "The PLIST file needs to be updated to use 'virtiofs' for M3 Macs." - return 1 fi fi @@ -89,10 +106,23 @@ function ih::setup::core.rancher::install() { cp -f "$RANCHER_AUGMENT_SRC" "$RANCHER_AUGMENT_DST" + ih::setup::core.rancher::create_temp_plist + if [ $? -ne 0 ]; then + ih::log::error "Failed to create and modify the temporary PLIST file." + return 1 + fi + + # Check macOS version compatibility with VZ for M2+ Macs (VZ requires macOS >=13.3) + if ih::arch::is_m2_or_m3_mac; then + if ! ih::arch::check_macos_version_compatibility "$REQUIRED_APPLE_SILICON_MACOS_VERSION"; then + ih::log::error "macOS version is not compatible for M2+ Macs." + return 1 # Abort the installation for M3 Macs + fi + fi + echo "A configuration file for Rancher Desktop will be copied to your system" echo "You may be required to enter your password" - local THIS_DIR="$IH_CORE_LIB_DIR/core/rancher" - sudo cp "${THIS_DIR}/io.rancherdesktop.profile.defaults.plist" "$PLIST_DST" + sudo cp "$TEMP_PLIST_DST" "$PLIST_DST" # Check if Rancher was installed manually brew list rancher >/dev/null 2>&1 @@ -160,18 +190,6 @@ function ih::setup::core.rancher::install() { fi fi - # 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 ! ih::arch::check_macos_version_compatibility "$REQUIRED_APPLE_SILICON_MACOS_VERSION"; then - return 1 # Abort the installation for M3 Macs - elif ! grep -q "vz" "$PLIST_DST"; then - ih::log::debug "Updating PLIST to use 'vz' for Virtualization for M3 Macs." - sudo sed -i '' 's/qemu<\/string>/vz<\/string>/g' "$PLIST_DST" - sudo sed -i '' 's/reverse-sshfs<\/string>/virtiofs<\/string>/g' "$PLIST_DST" - fi - fi - echo "Rancher Desktop has been installed successfully" else ih::log::warn "Could not install Rancher Desktop"