#!/bin/bash␊ |
␊ |
main ()␊ |
{␊ |
␉echo "==============================================="␊ |
␉echo "set com.apple.Boot.plist options"␊ |
␉echo "****************************************"␊ |
␊ |
␉temp="/private/tmp/Chameleon"␊ |
␉echo "Temp is ${temp}"␊ |
␊ |
␉cd ${temp}␊ |
␉Dirlist=$(find . -type d | grep "/")␊ |
␉for directory in $Dirlist ; do␊ |
␉␉overide=$(echo $directory | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)␊ |
␉␉string=$(echo $directory | tr -d "./@" |cut -d'+' -f2)␊ |
␊ |
␉␉bootplist="${3}/.Chameleon/Extra/com.apple.Boot.plist"␊ |
␉␉echo "bootplist = ${bootplist}"␉␊ |
␊ |
␉␉systemplist="/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"␊ |
␉␉echo "systemplist= ${systemplist}"␊ |
␉␉echo ""␊ |
␊ |
␉␉bootoptionshdextra[1]="<key>${overide}</key>"␊ |
␉␉bootoptionshdextra[2]="<string>${string}</string>"␊ |
␉␉echo "bootoptionshdextra 1 = ${bootoptionshdextra[1]}"␊ |
␉␉echo "bootoptionshdextra 2= ${bootoptionshdextra[2]}"␊ |
␉␉echo ""␊ |
␊ |
␉␉echo "if no directory exists named ${bootplist%/*} then mkdir ${bootplist%/*}"␊ |
␉␉echo ""␊ |
␉␉[ ! -d "${bootplist%/*}" ] && mkdir -p "${bootplist%/*}"␊ |
␉␊ |
␉␉echo "if ${bootplist} doesn't exist"␊ |
␉␉echo ""␊ |
␉␉if [ ! -f "${bootplist}" ]; then␊ |
␉␉␉echo "if ${systemplist} doesn't exist"␊ |
␉␉␉echo ""␊ |
␉␉␉if [ -f "${systemplist}" ]; then␊ |
␉␉␉␉echo "copy ${systemplist} to ${systemplist}"␊ |
␉␉␉␉echo ""␊ |
␉␉␉␉cp "${systemplist}" "${bootplist}"␊ |
␉␉␉fi␊ |
␉␉fi␊ |
␉␊ |
␉␉xmlvalue=$( getxmlvalue ${overide} "${bootplist}" | tr "[:upper:]" "[:lower:]" )␊ |
␉␉echo "xmlvalue = ${xmlvalue}"␊ |
␉␉echo ""␊ |
␊ |
␉␉case "${xmlvalue:0:1}" in␊ |
␉␉␉␉␊ |
␉␉␉y)␉echo "${overide}=y already set in ${bootplist} skipping."␊ |
␉␉␉␉echo ""␊ |
␉␉␉␉;;␊ |
␊ |
␉␉␉n)␉echo "${overide}=n is set in ${bootplist} leaving."␊ |
␉␉␉␉echo ""␊ |
␉␉␉␉;;␊ |
␉␊ |
␉ ␉␉*)␉echo "Adding ${overide}=${string} to ${bootplist}"␊ |
␉ ␉␉␉array=("${bootoptionshdextra[@]}")␊ |
␉␉␉␉searchfilereplaceline "${bootplist}" "<key>Kernel Flags</key>" "" "" "2"␊ |
␉␉␉␉echo ""␊ |
␉␉␉␉;;␊ |
␉␉esac␊ |
␊ |
␉␉echo "set owner privileges for ${bootplist}"␊ |
␉␉chown "${USER}:20" "${bootplist}"␊ |
␉done␊ |
}␊ |
␊ |
getxmlvalue ()␊ |
{␊ |
# 1 xml key␊ |
# 2 xml file␊ |
if [ -f "${2}" ]; then␊ |
␉local value␊ |
␉while read value; do␊ |
␉if [ ! "${value}" = "${value/<key>${1}</key>/}" ]; then␊ |
␉␉read value␊ |
␉␉value="${value#*<}" ; value="<${value}" ; value="${value#*>}" ; value="${value# *}" ; value="${value%%<*}"␊ |
␉␉echo "$value"␊ |
␉␉break␊ |
␉fi␊ |
␉done < "${2}"␊ |
fi␊ |
}␊ |
␊ |
searchfilereplaceline ()␊ |
{␊ |
␊ |
mv "${1}" "${1}.orig"␊ |
␊ |
prefunctionifs="${IFS}"␊ |
␊ |
unset fileinput␊ |
unset fileoutput␊ |
unset find␊ |
unset replace␊ |
unset deletelines␊ |
unset deletelinesskip␊ |
unset insertlinesskip␊ |
␊ |
fileinput="${1}.orig"␊ |
fileoutput="${1}"␊ |
find="${2}"␊ |
replace="${3}"␊ |
deletelines="${4%,*}"␊ |
insertlinesskip="${5}"␊ |
␊ |
matchlinefound="0"␊ |
␊ |
if [ "${#4}" = "${4#*,}" ]; then␊ |
deletelinesskip="0"␊ |
␉else␊ |
␉deletelinesskip="${4#*,}"␊ |
fi␊ |
␊ |
IFS="\n"␊ |
while read line␊ |
do␊ |
␉{␊ |
␉if [ ! "${line}" = "${line/${find}/}" ]; then␊ |
␉␉{␊ |
␉␉# Trim the longest match from the end for <*␊ |
␉␉xmlelementindent="${line%%<*}"␊ |
␊ |
␉␉# Trim the longest match from the start for *<␊ |
␉␉xmlelementtemp="${line#*<}"␊ |
␉␉# Add back in stripped <␊ |
␉␉xmlelement="<${xmlelementtemp}"␊ |
␊ |
␉␉# Trim the shortest match from the start for <␊ |
␉␉xmltagtemp="${xmlelement#<}"␊ |
␉␉# Trim the longest match from the end for >*␊ |
␉␉xmltag="${xmltagtemp%%>*}"␊ |
␊ |
␉␉# Trim the shortest match from the start for *>␊ |
␉␉xmltexttemp="${xmlelement#*>}"␊ |
␉␉# Trim the longest match from the end for <*␊ |
␉␉xmltext="${xmltexttemp%%<*}"␊ |
␊ |
␉␉if [ "${replace}" ]; then␊ |
␉␉␉{␊ |
␉␉␉␉echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉fi␊ |
␉␉matchlinefound="1"␊ |
␊ |
␉␉}␊ |
␉␉else␊ |
␉␉{␊ |
␊ |
␉␉if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then␊ |
␉␉␉{␊ |
␉␉␉if [ "${matchlinefound}" = "${insertlinesskip}" ]; then␊ |
␉␉␉␉{␊ |
␉␉␉␉arraysize=0␊ |
␉␉␉␉while [ ${arraysize} -lt ${#array[@]} ];␊ |
␉␉␉␉do␊ |
␉␉␉␉␉echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"␊ |
␉␉␉␉ let arraysize="${arraysize}+1"␊ |
␉␉␉␉done␊ |
␉␉␉␉}␊ |
␉␉␉fi␊ |
␉␉␉}␊ |
␉␉fi␊ |
␊ |
␉␉if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then␊ |
␉␉␉{␊ |
␉␉␉:␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉fi␊ |
␊ |
␉␉if [ "${matchlinefound}" -gt 0 ]; then␊ |
␉␉␉let matchlinefound="${matchlinefound}+1"␊ |
␉␉fi␊ |
␊ |
␉␉}␊ |
␉fi␊ |
␉}␊ |
done < "${fileinput}"␊ |
␊ |
IFS=${prefunctionifs}␊ |
␊ |
rm -f "${fileinput}"␊ |
}␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Post Script"␊ |
echo "***********"␊ |
echo ""␊ |
echo ""␊ |
␊ |
main "${1}" "${2}" "${3}" "${4}"␊ |
␊ |
temp="/private/tmp/Chameleon"␊ |
␊ |
#source com.apple.boot.plist␊ |
|
␉fi␊ |
fi␊ |
␊ |
# fix kext permissions␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Fix Kext Permissions"␊ |
echo "********************"␊ |
␊ |
find "${2}/.Chameleon/Extra/Extensions" -type f -exec chmod 644 {} \;␊ |
find "${2}/.Chameleon/Extra/Extensions" -type d -exec chmod 755 {} \;␊ |
chown -R 0:0 "${2}/.Chameleon/Extra/Extensions"␊ |
␊ |
# build mkext for extras␊ |
echo "-----------------------------------------------"␊ |
echo ""␊ |
echo ""␊ |
␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Build mkext for Extras"␊ |
echo "**********************"␊ |
␊ |
[ -d "${temp}" ] && rm -R -f "${temp}"␊ |
mkdir -p "${temp}/Extensions"␊ |
ditto --noextattr --noqtn --arch i386 "${2}/.Chameleon/Extra/Extensions" "${temp}/Extensions"␊ |
|
kextcache -m "${temp}/Extensions.mkext" "${temp}/Extensions"␊ |
cp -f "${temp}/Extensions.mkext" "${2}/.Chameleon/Extra"␊ |
#cp -f "${temp}/Extensions.mkext" "${2}/Extra"␊ |
rm -f -R "${temp}"␊ |
␊ |
# Check efi partition␊ |
echo "-----------------------------------------------"␊ |
echo ""␊ |
echo ""␊ |
␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Removing Temporary Chameleon Directory"␊ |
echo "**************************************"␊ |
␊ |
#rm -f -R "${temp}"␊ |
␊ |
echo "-----------------------------------------------"␊ |
echo ""␊ |
echo ""␊ |
␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Are there any EFI partitions mounted?"␊ |
echo "*************************************"␊ |
␊ |
if [ -d /Volumes/EFI ]; then␊ |
␊ |
# remove link for extras install␊ |
#unlink -r "${2}/.Chameleon"␊ |
␉echo "Yes.."␊ |
␉echo ""␊ |
␊ |
␉cp -R -f "${2}/.Chameleon/Extra" /Volumes/EFI/␊ |
␉umount -f /Volumes/EFI␊ |
␉rm -R -f /Volumes/EFI␊ |
␉# remove link for extras install␊ |
␉#unlink -r "${2}/.Chameleon"␊ |
␉#cp -R -f "${2}/.Chameleon/Extra" /Volumes/EFI/␊ |
␊ |
␉echo "==============================================="␊ |
␉echo "Unmount all EFI partitions"␊ |
␉echo "**************************"␊ |
␊ |
␉# loop through and un-mount all mounted EFI partitions - Thanks kizwan␊ |
␉attempts=1␊ |
␉while [ "$( df | grep EFI )" ] && [ "${attempts}" -lt 5 ]; do␊ |
␉␉echo "Unmounting $( df | grep EFI | awk '{print $1}' )"␊ |
␉␉umount -f $( df | grep EFI | awk '{print $1}' )␊ |
␉␉attempts=$(( ${attempts} + 1 ))␊ |
␉done␊ |
␉if [ ${attempts} != 5 ]; then␊ |
␉␉rm -R -f /Volumes/EFI␊ |
␉else␊ |
␉␉echo "failed to unmount EFI partitions."␊ |
␉fi␊ |
␉echo "-----------------------------------------------"␊ |
␉echo ""␊ |
␉echo ""␊ |
␊ |
␉rm -R -f "${2}/.Chameleon"␊ |
fi␊ |
␊ |