\r")
htmlToInsert="$htmlToInsert"$(printf "
${message}<\/span>\r")
htmlToInsert="$htmlToInsert"$(printf " <\/div>\r")
htmlToInsert="$htmlToInsert"$(printf " <\/div> \r")
# Insert bootlog Html in to placeholder
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}Inserting nvram functionality message HTML in to managethemes.html"
#LANG=C sed -ie "s//${htmlToInsert}/g" "${PUBLIC_DIR}"/managethemes.html
LANG=C sed -ie "s//${htmlToInsert}/g" "${TEMPDIR}"/managethemes.html
# Clean up
if [ -f "${TEMPDIR}"/managethemes.htmle ]; then
rm "${TEMPDIR}"/managethemes.htmle
fi
fi
}
# ---------------------------------------------------------------------------------------
PopulateBootLogTitleBand()
{
[[ DEBUG -eq 1 ]] && WriteLinesToLog
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndent}PopulateBootLogTitleBand()"
# Create bootlog band and title html
bootlogBandTitleHtml=$(printf " \r")
bandTitle=$(printf "
LAST BOOT\ \ \&\#x25BE\ \ \ \ |<\/span>")
bandTitleDescStart=$(printf "")
if [ $blTextOnlyOption -eq 0 ] && [ $blFastOption -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} - Fast boot and TextOnly options were both set in config.plist so no theme was loaded<\/span>"
elif [ $blFastOption -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} - Fast boot option was set in config.plist so no theme was loaded<\/span>"
elif [ $blTextOnlyOption -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} - Text Only option was set in config.plist so no theme was loaded<\/span>"
else
# Was the Christmas or NewYear theme used?
if [ "$blThemeNameChosen" == "christmas" ] || [ "$blThemeNameChosen" == "newyear" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded ${blThemeNameChosen}<\/span> as it's that time of year. Uninstall theme if not wanted.<\/span><\/span>"
# No nvram theme entry and chosen theme matches config.plist entry as long as they're not blank
elif [ "$blNvramThemeEntry" == "" ] && [ "$blThemeNameChosen" != "" ] && [ "$blConfigPlistThemeEntry" != "" ] && [ "$blThemeNameChosen" == "$blConfigPlistThemeEntry" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded ${blThemeNameChosen}<\/span> as set in ${blConfigPlistFilePathPrint} on device ${gBootDeviceIdentifier}<\/span>"
# nvram theme entry was used
elif [ "$blNvramThemeEntry" != "" ] && [ "$blThemeNameChosen" == "$blNvramThemeEntry" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded ${blThemeNameChosen}<\/span> as set in Clover.Theme var from ${blNvramReadFromPrint}<\/span>"
# nvram theme entry points to non-existent theme AND chosen theme matches config.plist entry
elif [ "$blNvramThemeEntry" != "" ] && [ $blNvramThemeExists -eq 1 ] && [ "$blThemeNameChosen" == "$blConfigPlistThemeEntry" ] && [ "$themeExist" == "Yes" ] && [ $blNvramThemeAbsent -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded ${blThemeNameChosen}<\/span> as set in ${blConfigPlistFilePathPrint} as NVRAM theme was absent<\/span>"
# Any pointed to theme does not exist AND embedded theme was not used AND random theme was used
elif [ $blNvramThemeAbsent -eq 0 ] && [ $blUsingEmbedded -eq 1 ] && [ $blUsedRandomTheme -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded a random theme ($blThemeNameChosen)<\/span> as it couldn't find the theme asked for<\/span>"
# nvram entry was blank AND config.plist entry was blank AND embedded theme was not used AND random theme was used
elif [ "$blNvramThemeEntry" == "" ] && [ "$blConfigPlistThemeEntry" == "" ] && [ $blUsingEmbedded -eq 1 ] && [ $blUsedRandomTheme -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded a random theme ($blThemeNameChosen)<\/span> as no theme was set<\/span>"
# Embedded theme was used
elif [ $blUsingEmbedded -eq 0 ] && [ "$blThemeAskedForTitle" == "embedded" ] && [ "$blUsingTheme" == "" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded theme embedded as it couldn't find any themes<\/span>"
# Embedded theme was used
elif [ $blUsingEmbedded -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded theme embedded as it was asked for<\/span>"
# User set random
elif [ "$blConfigPlistThemeEntry" == "random" ] || [ "$blNvramThemeEntry" == "random" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded ${blThemeNameChosen}<\/span> as a random theme was asked for<\/span>"
# theme.plist missing so random theme chosen.
elif [ $blConfigThemePlistNotFound -eq 0 ] && [ $blUsedRandomTheme -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded a random theme ($blThemeNameChosen)<\/span> as theme asked for didn't exist.<\/span>"
# was theme overridden from GUI?
elif [ $blGuiOverrideThemeChanged -eq 0 ] && [ "$blGuiOverrideTheme" != "" ] && [ "$blGuiOverrideTheme" == "$blThemeNameChosen" ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} loaded theme ${blThemeNameChosen}<\/span> as chosen in the GUI<\/span>"
# was fast boot used?
elif [ "$blUsingTheme" == "" ] && [ "$blThemeUsedPath" == "" ] && [ "$blThemeNameChosen" == "" ] && [ $blFastOption -eq 0 ]; then
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision} - Fast Boot option was set in config.plist so no theme was loaded<\/span>"
# Something else happened
else
bootlogBandTitleHtml="${bootlogBandTitleHtml}${bandTitle}${bandTitleDescStart}${blBootType} Clover ${blCloverRevision}<\/span>"
fi
fi
bootlogBandTitleHtml="$bootlogBandTitleHtml"$(printf "\r <\/div> \r")
# Insert bootlog Html in to placeholder
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}Inserting bootlog Band Title HTML in to managethemes.html"
#LANG=C sed -ie "s//${bootlogBandTitleHtml}/g" "${PUBLIC_DIR}"/managethemes.html && (( insertCount++ ))
LANG=C sed -ie "s//${bootlogBandTitleHtml}/g" "${TEMPDIR}"/managethemes.html && (( insertCount++ ))
# Clean up
if [ -f "${TEMPDIR}"/managethemes.htmle ]; then
rm "${TEMPDIR}"/managethemes.htmle
fi
}
# ---------------------------------------------------------------------------------------
PopulateBootLog()
{
[[ DEBUG -eq 1 ]] && WriteLinesToLog
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndent}PopulateBootLog()"
# Create bootlog container HTML
bootlogHtml=$(printf " \r")
bootlogHtml="$bootlogHtml"$(printf "\r")
# Add HTML for Boot Device Info / Boot Device Sections
# If boot device was not found then present rescan button.
if [ "$gBootDeviceIdentifier" != "Failed" ]; then
if [ "$blBootDevicePartType" == "MBR" ]; then
bootlogHtml="${bootlogHtml}${blcOpen}${blcLineDeviceInfoMbr}${blcLineDevice}"
elif [ "$blBootDevicePartType" == "GPT" ]; then
bootlogHtml="${bootlogHtml}${blcOpen}${blcLineDeviceInfoGpt}${blcLineDevice}"
fi
else
if [ "$blBootDevicePartType" == "MBR" ]; then
bootlogHtml="${bootlogHtml}${blcOpen}${blcLineDeviceInfoMbr}${blcLineDeviceRescan}"
elif [ "$blBootDevicePartType" == "GPT" ]; then
bootlogHtml="${bootlogHtml}${blcOpen}${blcLineDeviceInfoGpt}${blcLineDeviceRescan}"
fi
fi
# Add HTML for NVRAM section
if [ "$blNvramReadFrom" != "" ]; then
if [ "$blNvramThemeEntry" != "" ]; then
bootlogHtml="${bootlogHtml}${blcLineNvram}"
else
bootlogHtml="${bootlogHtml}${blcLineNvramNoTheme}"
fi
fi
# Add HTML for Config.plist section
bootlogHtml="${bootlogHtml}${blcLineConfig}"
# Add HTML for Theme asked for section (providing a theme was asked for), and Text Only option was not used
if [ "$blThemeAskedForPath" != "" ] && [ "$blThemeAskedForTitle" != "" ] && [ $blTextOnlyOption -eq 1 ]; then
bootlogHtml="${bootlogHtml}${blcLineThemeAsked}"
fi
# If GUI was used to override theme then add this HTML section
if [ $blGuiOverrideThemeChanged -eq 0 ] && [ "$blGuiOverrideTheme" != "" ]; then
bootlogHtml="${bootlogHtml}${blcLineOverrideUi}"
fi
# If fast boot and text only options were not used then add HTML for Theme used section
if ([ "$blUsingTheme" != "" ] || [ "$blThemeUsedPath" != "" ] || [ "$blThemeNameChosen" != "" ]) && [ $blFastOption -eq 1 ] && [ $blTextOnlyOption -eq 1 ]; then
bootlogHtml="${bootlogHtml}${blcLineThemeUsed}"
fi
# Add ending HTML
bootlogHtml="${bootlogHtml} <\/div> "
# Insert bootlog Html in to placeholder
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}Inserting bootlog HTML in to managethemes.html"
#LANG=C sed -ie "s//${bootlogHtml}/g" "${PUBLIC_DIR}"/managethemes.html && (( insertCount++ ))
LANG=C sed -ie "s//${bootlogHtml}/g" "${TEMPDIR}"/managethemes.html && (( insertCount++ ))
# Clean up
#if [ -f "${PUBLIC_DIR}"/managethemes.htmle ]; then
# rm "${PUBLIC_DIR}"/managethemes.htmle
#fi
if [ -f "${TEMPDIR}"/managethemes.htmle ]; then
rm "${TEMPDIR}"/managethemes.htmle
fi
}
# Resolve path
SELF_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P) && SELF_PATH=$SELF_PATH/$(basename -- "$0")
source "${SELF_PATH%/*}"/shared.sh
# Check for missing temp dir in case of local script testing.
[[ ! -d $TEMPDIR ]] && mkdir -p $TEMPDIR
# *************************************************************************
# Copy managethemes.html.template for testing only.
# Comment these two lines out for normal use
#cp "$PUBLIC_DIR"/managethemes.html.template "$TEMPDIR"/managethemes.html && PUBLIC_DIR="$TEMPDIR"
# *************************************************************************
[[ DEBUG -eq 1 ]] && WriteLinesToLog
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndent}bootlog.sh"
gNvramWorkingType=""
gNvramWorking=1 # Set to 0 if writing to nvram can be saved for next boot
insertCount=0 # increments each time an html block is injected in to managethemes.html
gRunInfo="$1" # Will be either 'Init' or 'Rescan'
gBootDeviceIdentifier="$2" # The boot device identifier (if found)
gBootDeviceMountpoint="$3" # The boot device mountpoint (if found)
if [ -f "$bootLogFile" ]; then
# Note: Clover r2025 rebranded rEFIt to Clover.
# So any log pre r2025 will not be read correctly.
checkLog=$( grep -a "Starting Clover" "$bootLogFile" )
if [ "$checkLog" != "" ]; then
ReadBootLog
PostProcess
CheckNvramIsWorking
if [ "$gRunInfo" == "Init" ]; then
EscapeVarsForHtml
[[ DEBUG -eq 1 ]] && PrintVarsToLog
# Write boot device info to file
echo "${blBootDevicePartition}@${blBootDevicePartType}@${blBootDevicePartSignature}@${blBootDevicePartStartDec}@${blBootDevicePartSizeDec}" > "$bootDeviceInfo"
# Create NVRAM functionality band
PopulateNvramFunctionalityBand "0"
# Show user what happened last boot
PopulateBootLogTitleBand
SetBootlogTextColourClasses
SetHtmlBootlogSectionTemplates
PopulateBootLog
# Add message in to log for initialise.js to detect.
if [ $insertCount -eq 2 ]; then
WriteToLog "CTM_BootlogOK"
else
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}insertCount=$insertCount | boot.log html failed to be inserted".
fi
elif [ "$gRunInfo" == "Rescan" ]; then
# Remove paths file, incase this script is run a second time.
[[ -f "$bootlogScriptOutfile" ]] && rm "$bootlogScriptOutfile"
fi
# Write some vars to file for script.sh to use.
if [ "$blNvramReadFrom" != "" ]; then
echo "nvram‡$blNvramReadFrom" >> "$bootlogScriptOutfile"
elif [ $blNvramBootArgs -eq 0 ]; then
echo "nvram‡Native NVRAM" >> "$bootlogScriptOutfile"
fi
[[ "$blNvramThemeEntry" != "" ]] && echo "nvramThemeEntry‡$blNvramThemeEntry" >> "$bootlogScriptOutfile"
[[ "$blConfigPlistFilePath" != "" ]] && echo "config‡$blConfigPlistFilePath" >> "$bootlogScriptOutfile"
[[ "$blBootType" != "" ]] && echo "bootType‡$blBootType" >> "$bootlogScriptOutfile"
echo "nvramSave‡$gNvramWorking" >> "$bootlogScriptOutfile"
else
checkLog=$( grep -a "Starting rEFIt" "$bootLogFile" )
if [ "$checkLog" != "" ]; then
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}Found Clover boot.log but revision is older than r2025"
# Create NVRAM functionality band
PopulateNvramFunctionalityBand "1"
else
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}Found boot.log but Not Clover."
PopulateNvramFunctionalityBand "2"
fi
fi
else
# Show message that system was booted without using Clover
PopulateNvramFunctionalityBand "2"
# Add message in to log for initialise.js to detect.
WriteToLog "CTM_BootlogMissing"
[[ DEBUG -eq 1 ]] && WriteToLog "${debugIndentTwo}boot.log does not exist".
fi