␉␉␉echo "Build Extra/com.apple.Boot.plist"␊ |
␉␉␉echo "********************************"␊ |
␊ |
␉␉␉for bootOptionFile in $Dirlist ; do␊ |
␉␉␉␉overide=$(echo $bootOptionFile | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)␊ |
␉␉␉␉string=$(echo $bootOptionFile | tr -d "./@" |cut -d'+' -f2)␊ |
␉␉␉mv "${bootplist}" "${bootplist}.orig"␊ |
␊ |
␉␉␉␉bootoptionshdextra[1]="<key>${overide}</key>"␊ |
␉␉␉␉bootoptionshdextra[2]="<string>${string}</string>"␊ |
␉␉␉␉#echo "DEBUG: bootoptionshdextra 1 = ${bootoptionshdextra[1]}"␊ |
␉␉␉␉#echo "DEBUG: bootoptionshdextra 2= ${bootoptionshdextra[2]}"␊ |
␉␉␉#prefunctionifs="${IFS}"␊ |
␊ |
␉␉␉␉echo "Attempting to add ${overide}=${string} to ${bootplist}"␊ |
␉ ␉␉␉array=("${bootoptionshdextra[@]}")␊ |
␉␉␉␉searchfilereplaceline "${bootplist}" "<key>Kernel Flags</key>" "" "" "2"␊ |
␉␉␉␉echo ""␊ |
␉␉␉fileinput="${bootplist}.orig"␊ |
␉␉␉fileoutput="${bootplist}"␊ |
␉␉␉find="<key>Kernel Flags</key>"␊ |
␉␉␉replace=""␊ |
␉␉␉deletelines=""␊ |
␉␉␉insertlinesskip="2"␊ |
␊ |
␉␉␉␉#echo "set owner privileges for ${bootplist}"␊ |
␉␉␉␉chown "${USER}:20" "${bootplist}"␊ |
␉␉␉done␊ |
␉␉␉matchlinefound="0"␊ |
␊ |
␉␉␉echo "-----------------------------------------------"␊ |
␉␉␉echo ""␊ |
␉␉␊ |
␉␉␉while read line␊ |
␉␉␉do␊ |
␉␉␉{␊ |
␉␉␉␉if [ ! "${line}" = "${line/${find}/}" ]; then␊ |
␉␉␉␉{␊ |
␉␉␉␉# Trim the longest match from the end for <*␊ |
␉␉␉␉xmlelementindent="${line%%<*}"␊ |
␊ |
␉␉␉echo "==============================================="␊ |
␉␉␉echo "Clean up and Remove Boot Option Null Files"␊ |
␉␉␉echo "******************************************"␊ |
␉␉␉␉# Trim the longest match from the start for *<␊ |
␉␉␉␉xmlelementtemp="${line#*<}"␊ |
␉␉␉␉# Add back in stripped <␊ |
␉␉␉␉xmlelement="<${xmlelementtemp}"␊ |
␊ |
␉␉␉# make sure we're in the right directory␊ |
␉␉␉cd "${tempDir}"␊ |
␉␉␉␉# Trim the shortest match from the start for <␊ |
␉␉␉␉xmltagtemp="${xmlelement#<}"␊ |
␉␉␉␉# Trim the longest match from the end for >*␊ |
␉␉␉␉xmltag="${xmltagtemp%%>*}"␊ |
␊ |
␉␉␉Dirlist=$(find . -type f | grep "@")␊ |
␉␉␉for bootOptionFile in ${Dirlist} ; do␊ |
␉␉␉␉echo "Removing temporary boot option file: ${bootOptionFile}"␊ |
␉␉␉␉rm $bootOptionFile␊ |
␉␉␉done␊ |
␉␉␉␉# Trim the shortest match from the start for *>␊ |
␉␉␉␉xmltexttemp="${xmlelement#*>}"␊ |
␉␉␉␉# Trim the longest match from the end for <*␊ |
␉␉␉␉xmltext="${xmltexttemp%%<*}"␊ |
␊ |
␉␉␉echo "-----------------------------------------------"␊ |
␉␉␉echo ""␊ |
␉␉␉␉if [ "${replace}" ]; then␊ |
␉␉␉␉␉echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"␊ |
␉␉␉␉else␊ |
␉␉␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉␉fi␊ |
␊ |
␉␉else␊ |
␉␉␉echo "No boot options in the temporary directory."␊ |
␉␉fi␊ |
␉fi␊ |
}␊ |
␉␉␉␉matchlinefound="1"␊ |
␊ |
␉␉␉␉}␊ |
␉␉␉␉else␊ |
␉␉␉␉{␊ |
␊ |
searchfilereplaceline ()␊ |
{␊ |
␉␉␉␉if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then␊ |
␉␉␉␉␉if [ "${matchlinefound}" = "${insertlinesskip}" ]; then␊ |
␊ |
mv "${1}" "${1}.orig"␊ |
␉␉␉␉␉␉for bootOptionFile in $Dirlist ; do␊ |
␉␉␉␉␉␉␉overide=$(echo $bootOptionFile | sed 's/_/ /g' | tr -d "./@" |cut -d '+' -f1)␊ |
␉␉␉␉␉␉␉string=$(echo $bootOptionFile | tr -d "./@" |cut -d'+' -f2)␊ |
␊ |
prefunctionifs="${IFS}"␊ |
␉␉␉␉␉␉␉bootoptionshdextra[1]="<key>${overide}</key>"␊ |
␉␉␉␉␉␉␉bootoptionshdextra[2]="<string>${string}</string>"␊ |
␊ |
unset fileinput␊ |
unset fileoutput␊ |
unset find␊ |
unset replace␊ |
unset deletelines␊ |
unset deletelinesskip␊ |
unset insertlinesskip␊ |
␉␉␉␉␉␉␉echo "Adding ${overide}=${string} to ${bootplist}"␊ |
␉ ␉␉␉␉␉␉array=("${bootoptionshdextra[@]}")␊ |
␉␉␉␉␉␉␉arraysize=0␊ |
␊ |
fileinput="${1}.orig"␊ |
fileoutput="${1}"␊ |
find="${2}"␊ |
replace="${3}"␊ |
deletelines="${4%,*}"␊ |
insertlinesskip="${5}"␊ |
␉␉␉␉␉␉␉#prefunctionifs="${IFS}"␊ |
␉␉␉␉␉␉␉#IFS="\n"␊ |
␊ |
matchlinefound="0"␊ |
␉␉␉␉␉␉␉while [ ${arraysize} -lt ${#array[@]} ];␊ |
␉␉␉␉␉␉␉do␊ |
␉␉␉␉␉␉␉␉echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"␊ |
␉␉␉ ␉␉␉␉␉let arraysize="${arraysize}+1"␊ |
␉␉␉␉␉␉␉done␊ |
␊ |
if [ "${#4}" = "${4#*,}" ]; then␊ |
deletelinesskip="0"␊ |
␉else␊ |
␉deletelinesskip="${4#*,}"␊ |
fi␊ |
␉␉␉␉␉␉␉#IFS=${prefunctionifs}␊ |
␉␉␉␉␉␉done␊ |
␊ |
IFS="\n"␊ |
while read line␊ |
do␊ |
␉{␊ |
␉if [ ! "${line}" = "${line/${find}/}" ]; then␊ |
␉␉{␊ |
␉␉# Trim the longest match from the end for <*␊ |
␉␉xmlelementindent="${line%%<*}"␊ |
␉␉␉␉␉␉#echo "set owner privileges for ${bootplist}"␊ |
␉␉␉␉␉␉chown "${USER}:20" "${bootplist}"␊ |
␉␉␉␉␉fi␊ |
␉␉␉␉fi␊ |
␊ |
␉␉# Trim the longest match from the start for *<␊ |
␉␉xmlelementtemp="${line#*<}"␊ |
␉␉# Add back in stripped <␊ |
␉␉xmlelement="<${xmlelementtemp}"␊ |
␉␉␉␉if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then␊ |
␉␉␉␉␉:␊ |
␉␉␉␉else␊ |
␉␉␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉␉fi␊ |
␊ |
␉␉# Trim the shortest match from the start for <␊ |
␉␉xmltagtemp="${xmlelement#<}"␊ |
␉␉# Trim the longest match from the end for >*␊ |
␉␉xmltag="${xmltagtemp%%>*}"␊ |
␉␉␉␉if [ "${matchlinefound}" -gt 0 ]; then␊ |
␉␉␉␉␉let matchlinefound="${matchlinefound}+1"␊ |
␉␉␉␉fi␊ |
␊ |
␉␉# Trim the shortest match from the start for *>␊ |
␉␉xmltexttemp="${xmlelement#*>}"␊ |
␉␉# Trim the longest match from the end for <*␊ |
␉␉xmltext="${xmltexttemp%%<*}"␊ |
␉␉␉␉}␊ |
␉␉␉␉fi␊ |
␉␉␉␉}␊ |
␉␉␉done < "${fileinput}"␊ |
␊ |
␉␉if [ "${replace}" ]; then␊ |
␉␉echo "DEBUG: Replace=${replace}"␊ |
␉␉␉{␊ |
␉␉␉␉echo "${xmlelementindent}<${xmltag}>${replace}</${xmltag}>" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉fi␊ |
␉␉matchlinefound="1"␊ |
␉␉␉#IFS=${prefunctionifs}␊ |
␉␉␉rm -f "${fileinput}"␊ |
␊ |
␉␉}␊ |
␉␉else␊ |
␉␉{␊ |
␉␉␉echo ""␊ |
␊ |
␉␉if [ "${insertlinesskip}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -le "${insertlinesskip}" ]; then␊ |
␉␉␉{␊ |
␉␉␉if [ "${matchlinefound}" = "${insertlinesskip}" ]; then␊ |
␉␉␉␉{␊ |
␉␉␉␉arraysize=0␊ |
␉␉␉␉while [ ${arraysize} -lt ${#array[@]} ];␊ |
␉␉␉␉do␊ |
␉␉␉␉␉#echo "DEBUG: ${xmlelementindent}${array[${arraysize}]}"␊ |
␉␉␉␉␉echo "${xmlelementindent}${array[${arraysize}]}" >>"${fileoutput}"␊ |
␉␉␉␉ let arraysize="${arraysize}+1"␊ |
␉␉␉␉done␊ |
␉␉␉␉}␊ |
␉␉␉fi␊ |
␉␉␉}␊ |
␉␉fi␊ |
␉␉␉echo "-----------------------------------------------"␊ |
␉␉␉echo ""␊ |
␉␉␊ |
␊ |
␉␉if [ "${deletelines}" ] && [ "${matchlinefound}" -gt 0 ] && [ "${matchlinefound}" -lt $((${deletelines}+${deletelinesskip})) ] && [ "${matchlinefound}" -ge ${deletelinesskip} ]; then␊ |
␉␉echo "DEBUG: Delete=${matchlinefound}"␊ |
␉␉␉{␊ |
␉␉␉:␊ |
␉␉␉}␊ |
␉␉␉else␊ |
␉␉␉{␊ |
␉␉␉echo "${line}" >>"${fileoutput}"␊ |
␉␉␉}␊ |
␉␉fi␊ |
␉␉␉echo "==============================================="␊ |
␉␉␉echo "Clean up and Remove Boot Option Null Files"␊ |
␉␉␉echo "******************************************"␊ |
␊ |
␉␉if [ "${matchlinefound}" -gt 0 ]; then␊ |
␉␉␉let matchlinefound="${matchlinefound}+1"␊ |
␉␉fi␊ |
␉␉␉# make sure we're in the right directory␊ |
␉␉␉cd "${tempDir}"␊ |
␊ |
␉␉}␊ |
␉fi␊ |
␉}␊ |
done < "${fileinput}"␊ |
␉␉␉Dirlist=$(find . -type f | grep "@")␊ |
␉␉␉for bootOptionFile in ${Dirlist} ; do␊ |
␉␉␉␉echo "Removing temporary boot option file: ${bootOptionFile}"␊ |
␉␉␉␉rm $bootOptionFile␊ |
␉␉␉done␊ |
␊ |
IFS=${prefunctionifs}␊ |
␉␉␉echo "-----------------------------------------------"␊ |
␉␉␉echo ""␊ |
␊ |
echo " rm -f ${fileinput}"␊ |
rm -f "${fileinput}"␊ |
␉␉else␊ |
␉␉␉echo "No boot options in the temporary directory."␊ |
␉␉fi␊ |
␉fi␊ |
}␊ |
␊ |
␊ |
␊ |
echo "==============================================="␊ |
echo "Enter Build Boot Options script"␊ |
echo "*******************************"␊ |