#!/bin/bash␊ |
␊ |
echo "==============================================="␊ |
echo "Post Post-Install Script"␊ |
echo "*********************************"␊ |
echo "-----------------------------------------------"␊ |
echo ""␊ |
␊ |
#echo "DEBUG: $ 1 = Full path to the installation package the installer app is processing: " $1␊ |
#echo "DEBUG: $ 2 = Full path to the installation destination: " $2␊ |
#echo "DEBUG: $ 3 = Installation volume (mountpoint) to receive the payload: " $3␊ |
#echo "DEBUG: $ 4 = Root directory for the system: " $4␊ |
␊ |
# Check target exists␊ |
if [ ! -e "$3" ]␊ |
then␊ |
echo "$3 volume does not exist!"␊ |
exit 1␊ |
fi␊ |
␊ |
# clean up what would otherwise turn into "//" paths␊ |
if [ "$3" == "/" ]␊ |
then␊ |
dest_vol=""␊ |
else␊ |
dest_vol="$3"␊ |
fi ␊ |
␊ |
# Find script location so to find the Install Log script.␊ |
MYLOCATION="${PWD}/${BASH_ARGV[0]}"␊ |
export MYLOCATION="${MYLOCATION%/*}"␊ |
scriptDir=$MYLOCATION␊ |
␊ |
# Has install log already been generated?␊ |
if [ ! -f "${dest_vol}"/.ChameleonLogFlag ]; then␊ |
␉# Write some information to the Install Log␊ |
␉versionNumber=`cat "${scriptDir}"/Resources/version`␊ |
␉revisionNumber=`cat "${scriptDir}"/Resources/revision`␊ |
␉"$scriptDir"InstallLog.sh "${dest_vol}" "Installer version: ${versionNumber} ${revisionNumber}"␊ |
␉"$scriptDir"InstallLog.sh "${dest_vol}" "Running Post postinstall script"␊ |
␉"$scriptDir"InstallLog.sh "${dest_vol}" "Target volume = ${dest_vol}"␊ |
else␊ |
␉"$scriptDir"InstallLog.sh "${dest_vol}" "Running Post postinstall script"␊ |
fi␊ |
␊ |
# set temporary directory␊ |
chamTemp="$dest_vol/usr/local/chamTemp"␊ |
␊ |
# Check for stopped installation due to Chameleon␊ |
# already existing on the same disk.␊ |
if [ ! -f "$dest_vol"/.ChameleonExists ]; then␊ |
␊ |
# ---------------------------------------------␊ |
# Add any installed modules to the Install Log␊ |
# ---------------------------------------------␊ |
if [ -e "${chamTemp}"/Extra/modules ]; then␊ |
ls "${chamTemp}"/Extra/modules | while read FILE␊ |
do␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Installed module:$FILE"␊ |
done␊ |
fi␊ |
␉␉␉␊ |
# ---------------------------------------------␊ |
# Add any installed themes to the Install Log␊ |
# ---------------------------------------------␊ |
if [ -e "${chamTemp}"/Extra/Themes ]; then␊ |
ls "${chamTemp}"/Extra/Themes | while read FILE␊ |
do␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Installed Theme:$FILE"␊ |
done␊ |
fi␊ |
␊ |
# ---------------------------------------------␊ |
# Build org.chameleon.Boot.plist␊ |
# ---------------------------------------------␊ |
# All options selected are now dummy files with␊ |
# the filename of the option and value residing␊ |
# in /usr/local/chamTemp/options/␊ |
# for example. Boot Banner=Yes␊ |
␊ |
# Are there any options to build?␊ |
if [ "$(ls -A ${chamTemp}/options )" ]; then␊ |
␊ |
# Check for temporary directory/Extra folder.␊ |
if [ ! -d "$chamTemp"/Extra ]; then␊ |
mkdir "$chamTemp"/Extra␊ |
fi␊ |
␊ |
# Create template for org.chameleon.Boot.plist"␊ |
tempOCBP="$chamTemp"/Extra/org.chameleon.Boot.plist␊ |
cp "$4"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist "$tempOCBP"␊ |
␊ |
# Read list of all boot options the user added.␊ |
arrayCount=0␊ |
kernelFlagCount=0␊ |
while read FILE␊ |
do␊ |
options[arrayCount]="${FILE##*/}"␊ |
␊ |
# Check keyRead for 'KF' at beginning to␊ |
# indicate that should be a kernel flag␊ |
if [ ${options[arrayCount]:0:2} = "KF" ];then␊ |
# plistbuddy only add's if the key doesn't already exist.␊ |
# So let's store any kernelflags and add them all at the␊ |
# same time once when we reach the end of the options list.␉␊ |
kernelflag[kernelFlagCount]="${options[arrayCount]##*flag=}"␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Added kernel flag: ${kernelflag[kernelFlagCount]}"␊ |
(( kernelFlagCount++ ))␉␊ |
else␊ |
keyRead="${options[$arrayCount]%=*}"␊ |
value="${options[$arrayCount]#*=}"␊ |
# escape any spaces␊ |
keyToUse=$( echo $keyRead | sed 's/ /\\ /g' )␊ |
if [ "${keyToUse}" != "DONT" ] && [ "${value}" != "ADD" ]; then␊ |
sudo /usr/libexec/plistbuddy -c "Add :${keyToUse} string ${value}" "$tempOCBP"␊ |
returnValue=$?␊ |
␉␉␉␉␉if [ ${returnValue} -ne 1 ]; then␊ |
␉␉␉␉␉␉"$scriptDir"InstallLog.sh "${dest_vol}" "Added boot option: ${keyRead}=${value}"␊ |
␉␉␉␉␉else␊ |
␉␉␉␉␉␉"$scriptDir"InstallLog.sh "${dest_vol}" "Can't add ${keyRead}=${value} as an option already exists for: ${keyRead}"␊ |
␉␉␉␉␉fi␊ |
fi␊ |
fi␉␊ |
(( arrayCount++ ))␊ |
done < <(ls "${chamTemp}"/options )␊ |
␊ |
␉␉# If exclusive options were used and the 'None' option was chosen,␊ |
␉␉# then a dummy file named DONT=ADD would be in /$chamTemp/Extra/options.␊ |
␉␉#Â If that was the only option then the above code would have made a ␊ |
␉␉# temporary Extra folder with a default org.chameleon.Boot.plist␊ |
␉␉# In this case we don't need it and should discard it otherwise the folder␊ |
␉␉#Â will be copied to the users / directory when it's not wanted.␊ |
␉␉if [ ${arrayCount} == 1 ] && [ "${keyToUse}" == "DONT" ] && [ "${value}" == "ADD" ]; then␊ |
␉␉␉if [ -e "${chamTemp}"/Extra ] && [ ! -e "${chamTemp}"/Extra/Themes ] && [ ! -e "${chamTemp}"/Extra/Modules ]; then␊ |
␉␉␉␉rm -r -f "$chamTemp"/Extra␊ |
␉␉␉fi␊ |
␉␉fi␊ |
␉␊ |
if [ $kernelFlagCount -gt 0 ]; then␊ |
# Add kernel flags␊ |
for (( i=0 ; i < $kernelFlagCount ; i++ ))␊ |
do␉␊ |
# Add any kernel flags together in to one string.␊ |
kernelFlagString="${kernelFlagString} ${kernelflag[i]}"␊ |
done␊ |
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"␊ |
if [ ${returnValue}=1 ]; then # key already exists.␊ |
sudo /usr/libexec/plistbuddy -c "Delete :Kernel\ Flags" "$tempOCBP"␊ |
sudo /usr/libexec/plistbuddy -c "Add :Kernel\ Flags string $kernelFlagString" "$tempOCBP"␊ |
fi␊ |
fi␉␊ |
fi␊ |
␊ |
# ---------------------------------------------␊ |
# Copy temp Extra folder to target destination␊ |
# ---------------------------------------------␊ |
# If we've made a temporary Extra folder to use then␊ |
# check for an existing /Extra folder. If found, back it up␊ |
# before copying the temporary Extra folder to destination.␊ |
# Extra folder now resides in /usr/local/chamTemp/␊ |
# Copy /usr/local/chamTemp/Extra to correct location.␊ |
␊ |
if [ -d "$chamTemp"/Extra ]; then␊ |
if [ ! -f "$dest_vol"/.ChameleonEFI ]; then␊ |
# The Standard install option chosen␊ |
␊ |
# Does an /Extra folder already exist?␊ |
if [ -e "$dest_vol"/Extra ]; then␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Found existing $dest_vol/Extra folder. Renaming it $dest_vol/Extra-OLD-$( date "+%H-%M-%S" )"␊ |
mv "$dest_vol/Extra" "$dest_vol/Extra_OLD-"$( date "+%H-%M-%S" )␊ |
fi␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing folder: $dest_vol/Extra"␊ |
cp -R "$chamTemp"/Extra "$dest_vol"␊ |
else␊ |
# The EFI system partition install option was chosen␊ |
# Does a /Volumes/Extra folder already exist?␊ |
if [ -e "/Volumes/EFI/Extra" ]; then␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Found existing /Volumes/EFI/Extra folder. Renaming it Extra-OLD-$( date "+%H-%M-%S" )"␊ |
mv "/Volumes/EFI/Extra" "/Volumes/EFI/Extra_OLD-"$( date "+%H-%M-%S" )␊ |
fi␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Writing folder: /Volumes/EFI/Extra"␊ |
cp -R "$chamTemp"/Extra "/Volumes/EFI"␊ |
fi␊ |
fi␊ |
␊ |
␉# Unmount ALL mounted volumes named EFI␊ |
␉"$scriptDir"UnMountEFIvolumes.sh "${dest_vol}" "${scriptDir}"␊ |
else␊ |
cleanUp="${cleanUp},0"␊ |
rm "$dest_vol"/.ChameleonExists␊ |
fi␊ |
␊ |
# ---------------------------------------------␊ |
# Cleanup␊ |
# ---------------------------------------------␊ |
␊ |
# remove any temporary boot sector files if they exist␊ |
if [ -d /tmp/newbs ]; then␊ |
␉cleanUp="${cleanUp},1a"␊ |
␉rm /tmp/newbs␊ |
fi␊ |
if [ -d /tmp/origbs ]; then␊ |
␉cleanUp="${cleanUp},1b"␊ |
␉rm /tmp/origbs␊ |
fi␊ |
if [ -d /tmp/newBootSector ]; then␊ |
␉cleanUp="${cleanUp},1c"␊ |
␉rm /tmp/newbs␊ |
fi␊ |
if [ -d /tmp/originalBootSector ]; then␊ |
␉cleanUp="${cleanUp},1d"␊ |
␉rm /tmp/origbs␊ |
fi␊ |
␊ |
# delete the temporary Chameleon folder␊ |
if [ -e "$chamTemp" ]; then␊ |
␉cleanUp="${cleanUp},2"␊ |
␉rm -rf "$chamTemp"␊ |
fi␊ |
␊ |
# Remove /.ChameleonEFI file␊ |
if [ -f "$dest_vol"/.ChameleonEFI ]; then␊ |
␉cleanUp="${cleanUp},3"␊ |
␉rm "$dest_vol"/.ChameleonEFI␊ |
fi␊ |
␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Cleanup: ${cleanUp}"␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "LineBreak"␊ |
"$scriptDir"InstallLog.sh "${dest_vol}" "Post script complete"␊ |
␊ |
echo "==============================================="␊ |
echo "END - Post Post-Install Script"␊ |
echo "*********************************"␊ |
echo "-----------------------------------------------"␊ |
echo "" |