grahampugh / erase-install

A script that automates downloading macOS installers, and optionally erasing or upgrading macOS in a single process. Watch the video!
https://grahamrpugh.com/2023/05/14/macaduk-presentation-eraseinstall.html
Apache License 2.0
836 stars 131 forks source link

during reinstall preinstall and post install command fail #383

Closed EdBascom closed 1 year ago

EdBascom commented 1 year ago

Describe the bug I am running Jamf Pro version 10.44.1 and have created a policy to deploy the erase-install-29.1 package and run the script to upgrade users to Ventura 13.2.1 as described below. The preinstall and post install commands fail. The commands are not complicated. I was attempting to remove the Google Chrome app before the upgrade and install a new version via policy after the install. This was being done because the Ventura upgrade often left the Google Chrome app corrupted. Why did the commands fail? I pulled the following from the logs after running the script;

[erase-install-launcher] Starting script "/Library/Management/erase-install/erase-install.sh" --reinstall --os=13 --check-power --fs --cleanup-after-use --preinstall-command "/bin/rm -rfv /Applications/Google*Chrome.app" --postinstall-command "/usr/local/bin/jamf policy -id 530"

 [erase-install] Now running preinstall command: "/bin/rm /bin/bash: -c: line 0: unexpected EOF while looking for matching `"' /bin/bash: -c: line 1: syntax error: unexpected end of file 2023-03-20 10:51:41

Screenshots see attached script arguments as shown in the policy

Environment (please complete the following information):

Screenshot 2023-03-21 at 1 12 03 PM
EdBascom commented 1 year ago

preinstall and post install both fail every time...

[STEP 1 of 5]
--
Executing Policy erase-install Ventura Upgrade Self Service
[STEP 2 of 5]
Downloading erase-install-29.1.pkg...
Downloading https://use1-jcds.services.jamfcloud.com//download/46124802ea354555ab2b54b569e1404d/erase-install-29.1.pkg?token=3f85cd1c21f547b98b6dc111301077b8o7clmy4w42o2dwkpyuifsxy5op7km0kx...
Verifying package integrity...
Installing erase-install-29.1.pkg...
Successfully installed erase-install-29.1.pkg.
[STEP 3 of 5]
Running script erase-install-launcher.sh...
Script exit code: 0
Script result: [erase-install-launcher] Starting script "/Library/Management/erase-install/erase-install.sh" --reinstall --os=13 --check-power --fs --cleanup-after-use --preinstall-command "/bin/rm -rfv /Applications/Google*Chrome.app" --postinstall-command "/usr/local/bin/jamf policy -id 530"

2023-03-24 13:58:20 [erase-install] v29.1 script execution started: Fri Mar 24 13:58:20 PDT 2023 
2023-03-24 13:58:20 [erase-install] System version: 12.5.1 (Build: 21G83) 

2023-03-24 13:58:20 [erase-install] Making log directory at /Library/Management/erase-install/log 
2023-03-24 13:58:20 [check_for_dialog_app] dialog is installed (/Library/Application Support/Dialog/Dialog.app) 
2023-03-24 13:58:20 [check_for_dialog_app] Creating dialog log (/var/tmp/dialog.15P)... 
2023-03-24 13:58:20 [log_rotate] Start rotating logs in /Library/Management/erase-install/log 
2023-03-24 13:58:20 [log_rotate] Finished rotating logs in /Library/Management/erase-install/log 
2023-03-24 13:58:20 [erase-install] Caffeinating this script (pid=74399) 
2023-03-24 13:58:20 [check_free_space] OK - 120 GB free/purgeable disk space detected 
2023-03-24 13:58:20 [erase-install] Looking for existing installer app or pkg 
2023-03-24 13:58:20 [find_existing_installer] Installer found at /Applications/Install macOS Ventura.app. 
2023-03-24 13:58:20 [check_installer_is_valid] Checking validity of /Applications/Install macOS Ventura.app. Volume Shared Support on disk4s2 force-unmounted 
2023-03-24 13:58:20 [check_installer_is_valid] Mounting /Applications/Install macOS Ventura.app/Contents/SharedSupport/SharedSupport.dmg 
2023-03-24 13:58:21 [check_installer_is_valid] Using Build value from com_apple_MobileAsset_MacSoftwareUpdate.xml Volume Shared Support on disk4s2 force-unmounted 
2023-03-24 13:58:23 [compare_build_versions] Comparing (1) 21G83 with (2) 22D68 
2023-03-24 13:58:23 [check_installer_is_valid] Installer: 22D68 >= System: 21G83 : valid build. 
2023-03-24 13:58:23 [erase-install] Running on architecture arm64 
2023-03-24 13:58:23 [get_user_details] ask for user credentials (attempt 1/5) 
2023-03-24 13:58:23 [get_default_dialog_args] Invoking utility dialog yes cooper is a member of everyone 
2023-03-24 13:58:30 [get_user_details] cooper is a Volume Owner 
2023-03-24 13:58:30 [check_password] Success: the password entered is the correct login password for cooper. 
2023-03-24 13:58:30 [check_power_status] OK - AC power detected 
2023-03-24 13:58:30 [erase-install] Installer is at: /Applications/Install macOS Ventura.app 
2023-03-24 13:58:30 [check_free_space] OK - 120 GB free/purgeable disk space detected 
2023-03-24 13:58:30 [erase-install] WARNING! Running /Applications/Install macOS Ventura.app with reinstall option 
2023-03-24 13:58:30 [erase-install] Sending quit message to dialog log (/var/tmp/dialog.15P) 
2023-03-24 13:58:30 [get_default_dialog_args] Invoking fullscreen dialog 
2023-03-24 13:58:31 [erase-install] Writing LaunchDaemon which will remove /Library/Management/erase-install at next boot 
2023-03-24 13:58:31  **[erase-install] Now running preinstall command: "/bin/rm /bin/bash: -c: line 0: unexpected EOF while looking for matching `"' /bin/bash: -c: line 1: syntax error: unexpected end of file 

2023-03-24 13:58:31** [launch_startosinstall] Launching startosinstall 
2023-03-24 13:58:31  [erase-install] Sending password to startosinstall By using the agreetolicense option, you are agreeing that you have run this tool with the license only option and have read and agreed to the terms. If you do not agree, press CTRL-C and cancel this process immediately. Preparing to run macOS Installer... 
Preparing: 0.0% 
Preparing: 0.1% 
Preparing: 2.3% 
Preparing: 2.4% 
Preparing: 2.5% 
Preparing: 2.6% 
Preparing: 2.7% 
Preparing: 2.8% 
Preparing: 2.9% 
Preparing: 3.0% 
Preparing: 3.1% 
Preparing: 3.2% 
Preparing: 3.3% 
Preparing: 3.4% 
Preparing: 3.5% 
Preparing: 3.6% 
Preparing: 3.7% 
Preparing: 3.8% 
Preparing: 3.9% 
Preparing: 4.0% 
Preparing: 4.1% 
Preparing: 4.2% 
Preparing: 4.3% 
Preparing: 4.4% 
Preparing: 4.5% 
Preparing: 4.6% 
Preparing: 4.7% 
Preparing: 4.8% 
Preparing: 4.9% 
Preparing: 5.0% 
Preparing: 5.1% 
Preparing: 5.2% 
Preparing: 5.3% 
Preparing: 5.4% 
Preparing: 5.5% 
Preparing: 5.6% 
Preparing: 5.7% 
Preparing: 5.8% 
Preparing: 5.9% 
Preparing: 6.0% 
Preparing: 6.1% 
Preparing: 6.2% 
Preparing: 6.3% 
Preparing: 6.4% 
Preparing: 6.5% 
Preparing: 6.6% 
Preparing: 6.7% 
Preparing: 6.8% 
Preparing: 6.9% 
Preparing: 7.0% 
Preparing: 7.1% 
Preparing: 7.2% 
Preparing: 7.3% 
Preparing: 7.4% 
Preparing: 7.5% 
Preparing: 7.6% 
Preparing: 7.7% 
Preparing: 7.8% 
Preparing: 7.9% 
Preparing: 8.0% 
Preparing: 8.1% 
Preparing: 8.2% 
Preparing: 8.3% 
Preparing: 8.4% 
Preparing: 8.5% 
Preparing: 8.6% 
Preparing: 8.7% 
Preparing: 8.8% 
Preparing: 8.9% 
Preparing: 9.0% 
Preparing: 9.1% 
Preparing: 9.2% 
Preparing: 31.0% 
Preparing: 31.7% 
Preparing: 36.4% 
Preparing: 36.5% 
Preparing: 41.2% 
Preparing: 41.3% 
Preparing: 46.2% 
Preparing: 51.0% 
Preparing: 82.1% 
Preparing: 84.0% 
Preparing: 85.9% 
Preparing: 87.0% 
Preparing: 88.7% 
Preparing: 90.4% 
Preparing: 91.6% 
Preparing: 92.6% 
Preparing: 93.6% 
Preparing: 94.3% 
Preparing: 94.9% 
Preparing: 95.9% 
Preparing: 96.7% 
Preparing: 97.6% 
Preparing: 98.5% 
Preparing: 99.9% 
Preparing: 100.0% 

2023-03-24 14:08:15  **[post_prep_work] Now running postinstall command: "/usr/local/bin/jamf /bin/bash: -c: line 0: unexpected EOF while looking for matching `"' /bin/bash: -c: line 1: syntax error: unexpected end of file 
2023-03-24 14:08:15** [post_prep_work] Reboot delay set to 0s 
2023-03-24 14:08:15  [erase-install] attempting to terminate the 'Self Service' process - Termination message indicates success 
2023-03-24 14:08:15 [erase-install] attempting to terminate the 'caffeinate' process - Termination message indicates success 
2023-03-24 14:08:15 [finish] Script exit code: 0 [erase-install-launcher] Exit (0)
[STEP 4 of 5]
[STEP 5 of 5]
grahampugh commented 1 year ago

This may be a problem specific to the erase-install-launcher.sh script. Have you by any chance tried this command locally on a machine?

EdBascom commented 1 year ago

Yes. Both the pre and post commands were tested locally in the terminal app.

grahampugh commented 1 year ago

I meant specifically, did you try the erase-install command in terminal before trying it in Jamf?

EdBascom commented 1 year ago

I did not. I will setup a test.

Ed Bascom Sys Admin 

On Apr 4, 2023, at 10:25 PM, Graham Pugh @.***> wrote:

I meant specifically, did you try the erase-install command in terminal before trying it in Jamf?

— Reply to this email directly, view it on GitHub https://www.google.com/url?q=https://github.com/grahampugh/erase-install/issues/383%23issuecomment-1496935475&source=gmail-imap&ust=1681277126000000&usg=AOvVaw0uUnA_4GJibhjVCDsFit9s, or unsubscribe https://www.google.com/url?q=https://github.com/notifications/unsubscribe-auth/A4B2RNMYULMM5D5ROBVN6M3W7T64LANCNFSM6AAAAAAWC6RTII&source=gmail-imap&ust=1681277126000000&usg=AOvVaw2BzmSvBUAGiIxdWAkolTgV. You are receiving this because you authored the thread.

EdBascom commented 1 year ago

I just finished running the script from terminal and it worked as it should. After following the instructions on your web page I deployed it via Jamf Pro and the pre and post commands fail. It works well when I do not use theses commands. Please look at the log listing above showing the preinstall and postinstall commands - why does the script fail?

grahampugh commented 1 year ago

There must be an issue with how the launcher script is breaking up the parameters. I did not write that script so will need to dig into it a bit or ask the author to take a look (paging @cvgs).

cvgs commented 1 year ago

Yes, that's true. The launcher is rather simple, but because it allows to enter multiple commands in one parameter it does not really check for spaces that are protected by double quotes; and that's why the postinstall command fails.

It might make sense to add a caveat to the documentation.

I do not see a straightforward way to fix this behaviour without further complicating the launcher script by parsing the parameters for quotes or losing the ability of entering multiple parameters into one parameter field.

If you really want to use the postinstall command, you simply could add your own launcher script, which can be as simple as this:

#!/bin/sh

"/Library/Management/erase-install/erase-install.sh"\
  --reinstall --os=13 --check-power --fs --cleanup-after-use\
  --preinstall-command "/bin/rm -rfv /Applications/Google*Chrome.app"\
  --postinstall-command "/usr/local/bin/jamf policy -id 530"

Or you clone the existing launcher script and manually add the pre-/postinstall commands there.

However, using a postinstall command can be dangerous by itself: the command will be executed when startosinstall has finished and is going to reboot the machine. Depending on the "rebootdelay" (which isn't set in your example) and other timing factors like the speed of your network or SSD, the reboot might just kill your running policy, leaving the machine without a properly installed Chrome. It might be more reliable to install a package which calls a custom Jamf trigger at next reboot, or by just letting Chrome be installed at next recurring checkin by scoping the Chrome policy to machines on Ventura which do not have it installed already…

grahampugh commented 1 year ago

Good answer. I'll augment the documentation to warn against using preinstall/postinstall commands with the supplied launcher script.

grahampugh commented 1 year ago

We don't have much in the wiki about a launcher script, but I've added a little note here: https://github.com/grahampugh/erase-install/wiki/6.-Use-in-Jamf-Pro#policy-logs