Clean up build-msi.sh script and make XML generation more readable

This commit is contained in:
Adam Honse 2025-02-16 18:26:24 -06:00
parent b7c8d63505
commit 015b28c7d1

View file

@ -52,6 +52,10 @@ EXTENSION="orp"
SAVE_FILE="${PRODUCTNAME}.${EXTENSION}"
count=1
#############################################################
# Build file list for files in the working path #
#############################################################
for file in "$WORKING_PATH"/*;
do
filename=$(basename "$file")
@ -60,55 +64,104 @@ do
EXE_ID=${PRODUCTNAME}00
EXE_FILE=${filename}
#Add special entry to files list
FILES="$FILES\t\t\t\t\t<File Id='${EXE_ID}' Source='${WORKING_PATH}${filename}'/>\n"
FILES="$FILES <File Id='${EXE_ID}' Source='${WORKING_PATH}${filename}'/>\n"
elif [ -d "$file" ] ; then
#If this is a directory then we need to add another component
COMPONENTS="${COMPONENTS}\t\t\t<ComponentRef Id='${filename}Files'/>\n"
TEMP="\t\t\t\t<Directory Id='${filename}' Name='${filename}'>\n\t\t\t\t\t<Component Id='${filename}Files' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\n"
COMPONENTS="${COMPONENTS} <ComponentRef Id='${filename}Files'/>\n"
TEMP=" <Directory Id='${filename}' Name='${filename}'>\n <Component Id='${filename}Files' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\n"
for file2 in "$file"/*;
do
filename2=$(basename "$file2")
TEMP="$TEMP\t\t\t\t\t\t<File Id='${PRODUCTNAME}${count}' Source='${WORKING_PATH}${filename}/${filename2}'/>\n"
TEMP="$TEMP <File Id='${PRODUCTNAME}${count}' Source='${WORKING_PATH}${filename}/${filename2}'/>\n"
count=$((count+1))
done
DIRECTORIES="$DIRECTORIES$TEMP\t\t\t\t\t</Component>\n\t\t\t\t</Directory>\n"
DIRECTORIES="$DIRECTORIES$TEMP </Component>\n </Directory>\n"
else
#Any other file to files list
FILES="$FILES\t\t\t\t\t<File Id='${PRODUCTNAME}${count}' Source='${WORKING_PATH}${filename}'/>\n"
FILES="$FILES <File Id='${PRODUCTNAME}${count}' Source='${WORKING_PATH}${filename}'/>\n"
count=$((count+1))
fi
done
echo -e "Building XML:\t" $XMLOUTFILE
#############################################################
# Create the Wix XML file #
# Set IFS to the empty string to allow arbitrary spacing #
# within the XML_FILE variable, then set it back to a #
# space character after we print the XML file #
#############################################################
IFS=""
XML_FILE=""
XML_PACKAGE="\t<Package Keywords='Installer' Description='${PRODUCTNAME} Installer'\n\t\tComments=\"${PRODUCTCOMMENT}\" Manufacturer='OpenRGB'\n\t\tInstallerVersion='200' Languages='1033' Compressed='yes' SummaryCodepage='1252' Platform='x64'/>\n"
XML_MEDIA="\t<Media Id='1' Cabinet='${PRODUCTNAME,,}.cab' EmbedCab='yes'/>\n"
XML_CONDITIONS="\t<Condition Message='This package supports Windows 64bit Only'>VersionNT64</Condition>\n"
XML_ACTION_RUNAS_ADMIN="\t<CustomAction Id='LaunchOpenRGBAdmin' FileKey='${EXE_ID}' ExeCommand='${EXE_FILE} --loglevel 1 --nodetect' Execute='deferred' Return='asyncNoWait' Impersonate='no'/>\n"
XML_ACTION_FIRSTRUN="\t<CustomAction Id='LaunchOpenRGB' FileKey='${EXE_ID}' ExeCommand='--gui --loglevel 6' Execute='immediate' Return='asyncNoWait' Impersonate='yes'/>\n"
XML_ICON="\t<Icon Id='OpenRGBIcon' SourceFile='${ICONFILE}'/>\n"
XML_PROPERTY="\t<Property Id='ARPPRODUCTICON' Value='OpenRGBIcon'/>\n\t<Property Id='ARPURLINFOABOUT' Value='https://www.openrgb.org'/>\n"
XML_ACTIONS_EXECUTE="\t<InstallExecuteSequence>\n\t\t<Custom Action='LaunchOpenRGBAdmin' After='InstallFiles'>NOT Installed</Custom>\n\t\t<Custom Action='LaunchOpenRGB' After='InstallFinalize'>NOT Installed</Custom>\n\t</InstallExecuteSequence>\n"
XML_WIX_UI="\t<Property Id='WIXUI_INSTALLDIR' Value='INSTALLDIR' />\n\t<UIRef Id='WixUI_InstallDir'/>\n\t<UIRef Id='WixUI_ErrorProgressText'/>\n\t<WixVariable Id='WixUILicenseRtf' Value='${LICENSEFILE}'/>\n\t<WixVariable Id='WixUIBannerBmp' Value='${BANNERIMAGE}'/>\n\t<WixVariable Id='WixUIDialogBmp' Value='${DIALOGBACKGROUND}'/>\n"
XML_MAJOR_UPGRADE="\t<MajorUpgrade Schedule='afterInstallInitialize' AllowDowngrades='yes'/>\n"
XML_METADATA="$XML_PACKAGE $XML_MEDIA $XML_CONDITIONS $XML_MAJOR_UPGRADE $XML_ACTION_RUNAS_ADMIN $XML_ACTION_FIRSTRUN $XML_ICON $XML_PROPERTY $XML_ACTIONS_EXECUTE $XML_WIX_UI"
XML_FILE+="<?xml version='1.0' encoding='windows-1252'?>\r\n"
XML_FILE+="<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\r\n"
XML_FILE+=" <Product Name='${PRODUCTNAME}' Manufacturer='${VENDOR}'\r\n"
XML_FILE+=" Id='*'\r\n"
XML_FILE+=" UpgradeCode='"${UPGRADECODE}"'\r\n"
XML_FILE+=" Language='1033' Codepage='1252' Version='${VERSION}'>\r\n"
XML_FILE+=" <Package Keywords='Installer' Description='${PRODUCTNAME} Installer'\r\n"
XML_FILE+=" Comments=\"${PRODUCTCOMMENT}\" Manufacturer='OpenRGB'\r\n"
XML_FILE+=" InstallerVersion='200' Languages='1033' Compressed='yes' SummaryCodepage='1252' Platform='x64'/>\r\n"
XML_FILE+=" <Media Id='1' Cabinet='${PRODUCTNAME,,}.cab' EmbedCab='yes'/>\r\n"
XML_FILE+=" <Condition Message='This package supports Windows 64bit Only'>VersionNT64</Condition>\r\n"
XML_FILE+=" <MajorUpgrade Schedule='afterInstallInitialize' AllowDowngrades='yes'/>\r\n"
XML_FILE+=" <CustomAction Id='LaunchOpenRGBAdmin' FileKey='${EXE_ID}' ExeCommand='${EXE_FILE} --loglevel 1 --nodetect' Execute='deferred' Return='asyncNoWait' Impersonate='no'/>\r\n"
XML_FILE+=" <CustomAction Id='LaunchOpenRGB' FileKey='${EXE_ID}' ExeCommand='--gui --loglevel 6' Execute='immediate' Return='asyncNoWait' Impersonate='yes'/>\r\n"
XML_FILE+=" <Icon Id='OpenRGBIcon' SourceFile='${ICONFILE}'/>\r\n"
XML_FILE+=" <Property Id='ARPPRODUCTICON' Value='OpenRGBIcon'/>\r\n"
XML_FILE+=" <Property Id='ARPURLINFOABOUT' Value='https://www.openrgb.org'/>\r\n"
XML_FILE+=" <InstallExecuteSequence>\r\n"
XML_FILE+=" <Custom Action='LaunchOpenRGBAdmin' After='InstallFiles'>NOT Installed</Custom>\r\n"
XML_FILE+=" <Custom Action='LaunchOpenRGB' After='InstallFinalize'>NOT Installed</Custom>\r\n"
XML_FILE+=" </InstallExecuteSequence>\r\n"
XML_FILE+=" <Property Id='WIXUI_INSTALLDIR' Value='INSTALLDIR'/>\r\n"
XML_FILE+=" <UIRef Id='WixUI_InstallDir'/>\r\n"
XML_FILE+=" <UIRef Id='WixUI_ErrorProgressText'/>\r\n"
XML_FILE+=" <WixVariable Id='WixUILicenseRtf' Value='${LICENSEFILE}'/>\r\n"
XML_FILE+=" <WixVariable Id='WixUIBannerBmp' Value='${BANNERIMAGE}'/>\r\n"
XML_FILE+=" <WixVariable Id='WixUIDialogBmp' Value='${DIALOGBACKGROUND}'/>\r\n"
XML_FILE+="\r\n"
XML_FILE+=" <Directory Id='TARGETDIR' Name='SourceDir'>\r\n"
XML_FILE+=" <Directory Id='ProgramFiles64Folder'>\r\n"
XML_FILE+=" <Directory Id='INSTALLDIR' Name='${PRODUCTNAME}'>\r\n"
XML_FILE+=" <Component Id='${PRODUCTNAME}Files' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\r\n"
XML_FILE+="${FILES}\r\n"
XML_FILE+=" <ProgId Id='${SAVE_FILE}' Description='${PRODUCTNAME} Profile'>\r\n"
XML_FILE+=" <Extension Id='${EXTENSION}' ContentType='application/${EXTENSION}'>\r\n"
XML_FILE+=" <Verb Id='open' Command='Open' TargetFile='${EXE_ID}' Argument='-p \"%1\"' />\r\n"
XML_FILE+=" </Extension>\r\n"
XML_FILE+=" </ProgId>\r\n"
XML_FILE+=" </Component>\r\n"
XML_FILE+="${DIRECTORIES}\r\n"
XML_FILE+=" </Directory>\r\n"
XML_FILE+=" </Directory>\r\n"
XML_FILE+=" <Directory Id='ProgramMenuFolder' Name='Programs'>\r\n"
XML_FILE+=" <Component Id='ProgramMenuShortcut' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\r\n"
XML_FILE+=" <Shortcut Id='startmenu${PRODUCTNAME}' Directory='ProgramMenuFolder' Name='${PRODUCTNAME}' Target='[#${EXE_ID}]' WorkingDirectory='INSTALLDIR' Advertise='no'/>\r\n"
XML_FILE+=" <RemoveFolder Id='ProgramMenuShortcut' On='uninstall'/>\r\n"
XML_FILE+=" <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes'/>\r\n"
XML_FILE+=" </Component>\r\n"
XML_FILE+=" </Directory>\r\n"
XML_FILE+=" </Directory>\r\n"
XML_FILE+=" <Feature Id='Complete' Title='${PRODUCTNAME}' Description='Install all ${PRODUCTNAME} files.' Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>\r\n"
XML_FILE+=" <Feature Id='${PRODUCTNAME}Complete' Title='${PRODUCTNAME}' Description='The complete package.' Level='1' AllowAdvertise='no' InstallDefault='local'>\r\n"
XML_FILE+=" <ComponentRef Id='${PRODUCTNAME}Files'/>\r\n"
XML_FILE+="${COMPONENTS}\r\n"
XML_FILE+=" <ComponentRef Id='ProgramMenuShortcut'/>\r\n"
XML_FILE+=" </Feature>\r\n"
XML_FILE+=" </Feature>\r\n"
XML_FILE+=" </Product>\r\n"
XML_FILE+="</Wix>"
XML_STARTMENU="\t\t<Directory Id='ProgramMenuFolder' Name='Programs'>\n\t\t\t<Component Id='ProgramMenuShortcut' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\n\t\t\t\t<Shortcut Id='startmenu${PRODUCTNAME}' Directory='ProgramMenuFolder' Name='${PRODUCTNAME}' Target='[#${EXE_ID}]' WorkingDirectory='INSTALLDIR' Advertise='no'/>\n\t\t\t\t<RemoveFolder Id='ProgramMenuShortcut' On='uninstall'/>\n\t\t\t\t<RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes'/>\n\t\t\t</Component>\n\t\t</Directory>\n"
XML_ASSOCIATE_FILE="\t\t\t\t\t<ProgId Id='${SAVE_FILE}' Description='${PRODUCTNAME} Profile'>\n\t\t\t\t\t\t<Extension Id='${EXTENSION}' ContentType='application/${EXTENSION}'>\n\t\t\t\t\t\t<Verb Id='open' Command='Open' TargetFile='${EXE_ID}' Argument='-p \"%1\"' />\n\t\t\t\t\t\t</Extension>\n\t\t\t\t\t</ProgId>\n"
XML_DIRECTORIES="\t<Directory Id='TARGETDIR' Name='SourceDir'>\n\t\t<Directory Id='ProgramFiles64Folder'>\n\t\t\t<Directory Id='INSTALLDIR' Name='${PRODUCTNAME}'>\n\t\t\t\t<Component Id='${PRODUCTNAME}Files' Guid='"$(uuidgen -t | awk '{ print toupper($0) }')"'>\n$FILES\n$XML_SHORTCUT\n$XML_ASSOCIATE_FILE\t\t\t\t</Component>\n$DIRECTORIES\t\t\t</Directory>\n\t\t</Directory>\n$XML_STARTMENU\t</Directory>\n"
XML_COMPONENTS="\t<Feature Id='Complete' Title='${PRODUCTNAME}' Description='Install all ${PRODUCTNAME} files.' Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR'>\n\t\t<Feature Id='${PRODUCTNAME}Complete' Title='${PRODUCTNAME}' Description='The complete package.' Level='1' AllowAdvertise='no' InstallDefault='local'>\n\t\t\t<ComponentRef Id='${PRODUCTNAME}Files'/>\n$COMPONENTS\t\t\t<ComponentRef Id='ProgramMenuShortcut'/>\n\t\t</Feature>\n\t</Feature>\n"
XML_DATA="$XML_DIRECTORIES $XML_COMPONENTS"
#Wipe out any previous XMLOUTFILE and add the header
XML_HEADER="<?xml version='1.0' encoding='windows-1252'?>\n<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>\n"
XML_PRODUCT="\t<Product Name='${PRODUCTNAME}' Manufacturer='${VENDOR}'\n\t\tId='*'\n\t\tUpgradeCode='"${UPGRADECODE}"'\n\t\tLanguage='1033' Codepage='1252' Version='${VERSION}'>\n$XML_METADATA\n$XML_DATA\n\t</Product>\n</Wix>"
echo -e $XML_HEADER $XML_PRODUCT > $XMLOUTFILE
echo -e "\t...Done!\n\n"
echo -e $XML_FILE > $XMLOUTFILE
IFS=" "
#############################################################
# Print the XML for debugging #
#############################################################
cat $XMLOUTFILE
#Once the XML file manifest is created create the package
#############################################################
# Once the XML file manifest is created, create the package #
#############################################################
candle -arch x64 ${PRODUCTNAME,,}.wxs
light -sval -ext WixUIExtension ${PRODUCTNAME,,}.wixobj -out ${PRODUCTNAME}_Windows_64.msi