Skip to content

Commit

Permalink
0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
grahampugh committed Feb 13, 2020
1 parent 942410a commit 900ad86
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ CHANGELOG

# Version History

## 0.12.0
13.02.2020
* Removed downloaded OS validity check for modes where the installer is not required for reinstall or eraseinstall, to prevent unnecessary exit failures.
* Fixed a problem preveting `--move` from working when overwriting a valid installer.
* Other small bugfixes.

## 0.11.1
03.02.2020
* Restricted the add forcequitapps install_args option to macOS 10.15 or greater, as this is not functional with older versions (#35). Thanks to '@ahousseini' for the contribution.

## 0.11.0
22.01.2020
* Added the `--sameos` option, so you can have a single command which will always try to reinstall whatever macOS (major) version is currently installed on the host
* Added the `--sameos` option, so you can have a single command which will always try to reinstall whatever macOS (major) version is currently installed on the host.

## 0.10.1
11.12.2019
Expand Down
62 changes: 40 additions & 22 deletions erase-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ show_help() {
exit
}

kill_process() {
process="$1"
if /usr/bin/pgrep "$process" >/dev/null ; then
/usr/bin/pkill "$process" && echo " [erase-install] '$process' ended" || \
echo " [erase-install] '$process' could not be killed"
fi
}

free_space_check() {
free_disk_space=$(df -Pk . | column -t | sed 1d | awk '{print $4}')

Expand All @@ -162,7 +170,7 @@ free_space_check() {
}

check_installer_is_valid() {
echo " [find_existing_installer] Installer found at $installer_app."
echo " [check_installer_is_valid] Installer found at $installer_app."
# check installer validity:
# split the version of the downloaded installer into OS and minor versions
installer_version=$( /usr/bin/defaults read "$installer_app/Contents/Info.plist" DTPlatformVersion )
Expand All @@ -173,23 +181,23 @@ check_installer_is_valid() {
installed_os_version=$( echo "$installed_version" | cut -d '.' -f 2 )
installed_minor_version=$( echo "$installed_version" | cut -d '.' -f 3 )
if [[ $installer_os_version -lt $installed_os_version ]]; then
echo " [find_existing_installer] $installer_version < $installed_version so not valid."
echo " [check_installer_is_valid] $installer_version < $installed_version so not valid."
installmacOSApp="$installer_app"
app_is_in_applications_folder="yes"
invalid_installer_found="yes"
elif [[ $installer_os_version -eq $installed_os_version ]]; then
if [[ $installer_minor_version -lt $installed_minor_version ]]; then
echo " [find_existing_installer] $installer_version.$installer_minor_version < $installed_version so not valid."
echo " [check_installer_is_valid] $installer_version.$installer_minor_version < $installed_version so not valid."
installmacOSApp="$installer_app"
app_is_in_applications_folder="yes"
invalid_installer_found="yes"
else
echo " [find_existing_installer] $installer_version.$installer_minor_version >= $installed_version so valid."
echo " [check_installer_is_valid] $installer_version.$installer_minor_version >= $installed_version so valid."
installmacOSApp="$installer_app"
app_is_in_applications_folder="yes"
fi
else
echo " [find_existing_installer] $installer_version.$installer_minor_version >= $installed_version so valid."
echo " [check_installer_is_valid] $installer_version.$installer_minor_version >= $installed_version so valid."
installmacOSApp="$installer_app"
app_is_in_applications_folder="yes"
fi
Expand Down Expand Up @@ -227,6 +235,7 @@ overwrite_existing_installer() {
fi
rm -f "$macOSDMG" "$macOSSparseImage"
rm -rf "$installer_app"
app_is_in_applications_folder=""
}

move_to_applications_folder() {
Expand Down Expand Up @@ -278,22 +287,25 @@ run_fetch_full_installer() {

if [[ $? == 0 ]]; then
# Identify the installer
if find /Applications -maxdepth 1 -name 'Install_macOS*.app' -type d -print -quit ; then
installmacOSApp=$( find /Applications -maxdepth 1 -name 'Install_macOS*.app' -type d -print -quit 2>/dev/null )
if find /Applications -maxdepth 1 -name 'Install macOS*.app' -type d -print -quit 2>/dev/null ; then
installmacOSApp=$( find /Applications -maxdepth 1 -name 'Install macOS*.app' -type d -print -quit 2>/dev/null )
# if we actually want to use this installer we should check that it's valid
if [[ $erase == "yes" || $reinstall == "yes" ]]; then
check_installer_is_valid
if [[ $invalid_installer_found == "yes" ]]; then
echo " [run_fetch_full_installer] The downloaded app is invalid for this computer. Try with --version or without --fetch-full-installer"
/usr/bin/pkill jamfHelper
kill_process jamfHelper
exit 1
fi
fi
else
echo " [run_fetch_full_installer] No install app found. I guess nothing got downloaded."
/usr/bin/pkill jamfHelper
kill_process jamfHelper
exit 1
fi
else
echo " [run_fetch_full_installer] softwareupdate --fetch-full-installer failed. Try without --fetch-full-installer option."
/usr/bin/pkill jamfHelper
kill_process jamfHelper
exit 1
fi
}
Expand Down Expand Up @@ -390,7 +402,7 @@ run_installinstallmacos() {
installmacOSApp=$( find '/Volumes/'*macOS*/Applications/*.app -maxdepth 1 -type d -print -quit 2>/dev/null )
else
echo " [run_installinstallmacos] No disk image found. I guess nothing got downloaded."
/usr/bin/pkill jamfHelper
kill_process jamfHelper
exit
fi
}
Expand Down Expand Up @@ -480,7 +492,7 @@ find_existing_installer

if [[ $overwrite == "yes" && -d "$installmacOSApp" && ! $list ]]; then
overwrite_existing_installer
elif [[ $invalid_installer_found == "yes" && ! $list ]]; then
elif [[ $invalid_installer_found == "yes" && ($erase == "yes" || $reinstall == "yes") ]]; then
echo " [erase-install] ERROR: Invalid installer is present. Run with --overwrite option to ensure that a valid installer is obtained."
exit 1
fi
Expand All @@ -501,7 +513,7 @@ if [[ ! -d "$installmacOSApp" || $list ]]; then
run_installinstallmacos
fi
# Once finished downloading, kill the jamfHelper
/usr/bin/pkill jamfHelper
kill_process "jamfHelper"
fi

if [[ $erase != "yes" && $reinstall != "yes" ]]; then
Expand All @@ -513,18 +525,24 @@ if [[ $erase != "yes" && $reinstall != "yes" ]]; then
# Move to $installer_directory if move_to_applications_folder flag is included
# Not allowed for fetch_full_installer option
if [[ $move == "yes" && ! $ffi ]]; then
echo " [erase-install] Invoking --move option"
move_to_applications_folder
fi

# Unmount the dmg
existingInstaller=$(find /Volumes/*macOS* -maxdepth 2 -type d -name Install*.app -print -quit 2>/dev/null )
if [[ -d "$existingInstaller" ]]; then
echo " [erase-install] Mounted installer will be unmounted: $existingInstaller"
existingInstallerMountPoint=$(echo "$existingInstaller" | cut -d/ -f 1-3)
diskutil unmount force "$existingInstallerMountPoint"
if [[ ! $ffi ]]; then
existingInstaller=$(find /Volumes/*macOS* -maxdepth 2 -type d -name Install*.app -print -quit 2>/dev/null )
if [[ -d "$existingInstaller" ]]; then
echo " [erase-install] Mounted installer will be unmounted: $existingInstaller"
existingInstallerMountPoint=$(echo "$existingInstaller" | cut -d/ -f 1-3)
diskutil unmount force "$existingInstallerMountPoint"
fi
fi
# Clear the working directory
echo " [erase-install] Cleaning working directory '$workdir/content'"
rm -rf "$workdir/content"
# kill caffeinate
kill_process "caffeinate"
echo
exit
fi
Expand Down Expand Up @@ -615,7 +633,7 @@ fi
# run it!
"$installmacOSApp/Contents/Resources/startosinstall" "${install_args[@]}" --agreetolicense --nointeraction "${install_package_list[@]}"

# Kill Self Service if running
/usr/bin/pgrep "Self Service" && /usr/bin/pkill "Self Service"
# Kill Jamf FUD if startosinstall ends before a reboot
/usr/bin/pgrep "jamfHelper" && /usr/bin/pkill "jamfHelper"
# kill Self Service if running
kill_process "Self Service"
# kill Jamf FUD if startosinstall ends before a reboot
kill_process "jamfHelper"

0 comments on commit 900ad86

Please sign in to comment.