Hi All,
I thought i would share with the community my method for deploying High Sierra with Casper Imaging.
The method basically consists for two scripts.
I have tested this with a 10.13.1 Netboot Image created with AutoDMG and AutoCasperNBI
restoreMacOS.sh To deploy the correct image which runs as a "before" script
imagingPostinstall. To run after reboot to run the Sierra Upgrade if needed.
The first script will decide which image to deploy to the Mac based on the currently installed Operating System or File system.
-If it is APFS it will deploy the 10.13.1 APFS image to the APFS container.
-If it is HFS+ it will check the currently installed OS. If the OS is already 10.13 it will image using the 10.13 HFS+ image.
-If the filesystem is HFS+ and the current OS is not 10.13 it will deploy 10.12.6 and then upgrade to 10.13 on next reboot using startOSInstall.
Script 1 RestoreMacOS.sh This replaces your base image in your Casper Admin Config
#!/bin/bash
######################################################################################
#
# RestoreMacOs.sh - Ashley Stonham <reddrop>
# Restores either High Sierra or Sierra based on a best guess
#
# Variables:
# DP - Set this to the path that your DP mounts as
# SIERRA - Set this to the filename of your Sierra image
# HSIERRAAPFS - Set this to the filename of your HighSierra APFS Image
# HSIERRAHFS - Set this to the filename of your HighSierra HFS Image
#
######################################################################################
## Set these Variables
DP="/Volumes/casperdp"
SIERRA="osx-10.12.6-16G29.hfs.dmg"
HSIERRAAPFS="osx-10.13.1-17B48.apfs.dmg"
HSIERRAHFS="osx-10.13.1-17B48.hfs.dmg"
## No need to change anything below
TARGET="$1"
SOURCE=""
FSTYPE=$( diskutil info "$TARGET" | grep 'Type (Bundle)' | awk '{print $3}' )
## If the filesystem is APFS just restore High Sierra APFS
if [ "$FSTYPE" == "apfs" ]; then
echo "APFS Detected setting SOURCE to $HSIERRAAPFS"
SOURCE="$HSIERRAAPFS"
fi
## If the filesystem is HFS check the currently installed OS Version
if [ "$FSTYPE" == "hfs" ]; then
echo "HFS Detected checking OS Version"
VERSION=$( defaults read "${TARGET}/System/Library/CoreServices/SystemVersion.plist" ProductVersion )
echo $VERSION
if [[ "$VERSION" == *"10.13"* ]]; then
echo "High Sierra Detected"
SOURCE="$HSIERRAHFS"
else
echo "High Sierra Not Detected"
SOURCE="$SIERRA"
fi
fi
if [ "$SOURCE" == "" ]; then
echo "ERROR: Unable to determine source"
exit 1
fi
echo "Running ASR ${DP}/Packages/${SOURCE} to $TARGET"
## If restoring APFS
if [ "$SOURCE" == "$HSIERRAAPFS" ]; then
echo "Restoring APFS Volume"
## Workout APFS Container
APFSDISK=$( diskutil list "$TARGET" | head -1 | cut -d' ' -f 1 )
APFSCONTAINER=$( diskutil apfs list "$APFSDISK" | grep 'APFS Physical Store Disk' | cut -d':' -f 2 | tr -d '[:space:]' );
if [[ "$APFSCONTAINER" == *"disk"* ]]; then
echo "Restoring ${DP}/Packages/${SOURCE} to /dev/${APFSCONTAINER}"
asr restore --source "${DP}/Packages/${SOURCE}" --target "/dev/${APFSCONTAINER}" --erase --noprompt
diskutil mountDisk "${APFSDISK}"
else
echo "Error unable to determine APFS container"
exit 1;
fi
else
echo "Restoring HFS Volume"
asr restore --source "${DP}/Packages/${SOURCE}" --target "$TARGET" --erase --noprompt --corestorageconvert
#diskutil cs convert "$TARGET"
fi
exit 0
ImagingPostinstall.sh this scripts runs as an After Reboot and will create a launchDaemon to install HighSierra if the current OS is 10.12
#!/bin/bash
## Check OS Version if 10.12 Upgrade to HighSierra
OSVERSION=$( defaults read /System/Library/CoreServices/SystemVersion.plist ProductVersion )
if [[ "$OSVERSION" != *"10.12"* ]]; then
## Do nothing and exit
echo "OS is not 10.12"
exit 0;
fi
/bin/mkdir /usr/local/scripts
cat <<"EOF" > "/usr/local/scripts/NextBoot.sh"
#!/bin/bash
OSVERSION=$( defaults read /System/Library/CoreServices/SystemVersion.plist ProductVersion )
## If already on 10.13 remove the scripts.
if [[ "$OSVERSION" == *"10.13"* ]]; then
## Remove LaunchDaemon
/bin/rm -f /Library/LaunchDaemons/com.scripts.NextBoot.plist
## Remove Script
/bin/rm -fdr /usr/local/scripts
launchctl remove com.scripts.NextBoot
exit 0
fi
## Sleep for 30s to give the mac a chance to connect to network
sleep 30
## Update Device Inventory
/usr/local/jamf/bin/jamf recon
## Run HighSierra Upgrade
/usr/local/jamf/bin/jamf policy -event highSierraUpgrade
exit 0
EOF
/usr/sbin/chown root:admin /usr/local/scripts/NextBoot.sh
/bin/chmod 755 /usr/local/scripts/NextBoot.sh
## Install the launchdaemon
cat << EOF > /Library/LaunchDaemons/com.scripts.NextBoot.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.scripts.NextBoot</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string>/usr/local/scripts/NextBoot.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
EOF
##Set the permission on the file just made.
/usr/sbin/chown root:wheel /Library/LaunchDaemons/com.scripts.NextBoot.plist
/bin/chmod 644 /Library/LaunchDaemons/com.scripts.NextBoot.plist
exit 0