#!/bin/bash␊ |
␊ |
# $1 Path to store built package␊ |
␊ |
packagesidentity="org.chameleon"␊ |
␊ |
packagename="Chameleon"␊ |
␊ |
pkgroot="${0%/*}"␊ |
␊ |
#version=$( grep I386BOOT_CHAMELEONVERSION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )␊ |
version=$( cat version )␊ |
stage=${version##*-}␊ |
revision=$( grep I386BOOT_CHAMELEONREVISION sym/i386/vers.h | awk '{ print $3 }' | tr -d '\"' )␊ |
builddate=$( grep I386BOOT_BUILDDATE sym/i386/vers.h | awk '{ print $3,$4 }' | tr -d '\"' )␊ |
timestamp=$( date -j -f "%Y-%m-%d %H:%M:%S" "${builddate}" "+%s" )␊ |
␊ |
distributioncount=0␊ |
xmlindent=0␊ |
␊ |
indent[0]="\t"␊ |
indent[1]="\t\t"␊ |
indent[2]="\t\t\t"␊ |
indent[3]="\t\t\t\t"␊ |
␊ |
main ()␊ |
{␊ |
␊ |
# clean up the destination path␊ |
␊ |
␉rm -R -f "${1}"␊ |
␉␊ |
␉echo "Building $packagename Install Package (Dummy) v${version%%-*} $stage r$revision $builddate"␊ |
␉␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}<choices-outline>"␊ |
␊ |
# Start␊ |
␊ |
# build Chameleon package ␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Chameleon\">"␊ |
␉choices[$((choicescount++))]="<choice\n\tid=\"Chameleon\"\n\ttitle=\"Chameleon_title\"\n\tdescription=\"Chameleon_description\"\n>\n</choice>\n"␊ |
␉((xmlindent++))␊ |
␊ |
␉# build standard package ␊ |
␉␉mkdir -p ${1}/Standard/Root␊ |
␉␉echo "Building boot0 package"␊ |
␉␉buildpackage "${1}/Standard" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"upgrade_allowed()\" selected=\"exclusive(choices['EnhancedHFS']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""␊ |
␉# End build standard package␊ |
␊ |
␉# build standard package with boot0hfs␊ |
␉␉mkdir -p ${1}/Standardhfs/Root␊ |
␉␉echo "Building boot0hfs package"␊ |
␉␉buildpackage "${1}/Standardhfs" "/" "${coresize}" "start_enabled=\"true\" start_selected=\"false\" selected=\"exclusive(choices['EnhancedHFS']) && exclusive(choices['Standard']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""␊ |
␉# End build standard package with boot0hfs␊ |
␊ |
␉# build efi fat32 package ␊ |
␉␉mkdir -p ${1}/EnhancedFAT/Root␊ |
␉␉echo "Building efi fat32 package"␊ |
␉␉buildpackage "${1}/EnhancedFAT" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedHFS']) && exclusive(choices['noboot'])\""␊ |
␉# End build efi fat32 package ␊ |
␊ |
␉# build efi hfs package ␊ |
␉␉mkdir -p ${1}/EnhancedHFS/Root␊ |
␉␉echo "Building efi hfs package"␊ |
␉␉buildpackage "${1}/EnhancedHFS" "/" "${coresize}" "start_visible=\"systemHasGPT()\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['noboot'])\""␊ |
␉# End build efi hfs package ␊ |
␊ |
␉# build reset choice package ␊ |
␉␉mkdir -p ${1}/noboot/Root␊ |
␉␉echo "Building reset choice package"␊ |
␉␉buildpackage "${1}/noboot" "/" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs']) && exclusive(choices['EnhancedFAT']) && exclusive(choices['EnhancedHFS'])\""␊ |
␉# End build reset choice package ␊ |
␊ |
␉((xmlindent--))␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>" # End Chameleon pakage␊ |
␊ |
# build theme packages␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Themes\">"␊ |
␉choices[$((choicescount++))]="<choice\n\tid=\"Themes\"\n\ttitle=\"Themes_title\"\n\tdescription=\"Themes_description\"\n>\n</choice>\n"␊ |
␉((xmlindent++))␊ |
␉␉packagesidentity="org.chameleon.theme"␊ |
␉␉artwork="${1%/*}"␊ |
␉artwork="${1%/*}"␊ |
␉themes=($( find "${artwork%/*}/artwork/themes" -type d -depth 1 -not -name '.svn' ))␊ |
␉for (( i = 0 ; i < ${#themes[@]} ; i++ )) ␊ |
␉do␊ |
␉␉theme=$( echo ${themes[$i]##*/} | awk 'BEGIN{OFS=FS=""}{$1=toupper($1);print}' )␊ |
␉␉mkdir -p "${1}/${theme}/Root/"␊ |
␉␉buildpackage "${1}/${theme}" "/" "" "start_selected=\"false\""␊ |
␉␉rm -R -f "${1}/${i##*/}"␊ |
␉done␊ |
␉echo "Building themes package"␊ |
␉((xmlindent--))␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
# End build theme packages␊ |
␊ |
# build options packages␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Options\">"␊ |
␉choices[$((choicescount++))]="<choice\n\tid=\"Options\"\n\ttitle=\"Options_title\"\n\tdescription=\"Options_description\"\n>\n</choice>\n"␊ |
␉((xmlindent++))␊ |
␉␉packagesidentity="org.chameleon.options"␊ |
␉␉options=($( find "${pkgroot}/Scripts/BaseOptions" -type d -depth 1 -not -name '.svn' ))␊ |
␉␉␉for (( i = 0 ; i < ${#options[@]} ; i++ )) ␊ |
␉␉␉do␊ |
␉␉␉␉mkdir -p "${1}/${options[$i]##*/}/Root"␊ |
␉␉␉␉buildpackage "${1}/${options[$i]##*/}" "/" "" "start_selected=\"false\""␊ |
␉␉␉␉rm -R -f "${1}/${i##*/}"␊ |
␉␉␉done␊ |
␉␉# build resolution packages␊ |
␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Resolution\">"␊ |
␉␉␉choices[$((choicescount++))]="<choice\n\tid=\"Resolution\"\n\ttitle=\"Resolution_title\"\n\tdescription=\"Resolution_description\"\n>\n</choice>\n"␊ |
␉␉␉((xmlindent++))␊ |
␉␉␉␉packagesidentity="org.chameleon.resolution"␊ |
␉␉␉␉resolutions=($( find "${pkgroot}/Scripts/Resolutions" -type d -depth 1 -not -name '.svn' ))␊ |
␉␉␉␉␉for (( y = 0 ; y < ${#resolutions[@]} ; y++ )) ␊ |
␉␉␉␉␉do␊ |
␉␉␉␉␉␉mkdir -p "${1}/${resolutions[$y]##*/}/Root"␊ |
␉␉␉␉␉␉buildpackage "${1}/${resolutions[$y]##*/}" "/" "" "start_selected=\"false\""␊ |
␉␉␉␉␉␉rm -R -f "${1}/${y##*/}"␊ |
␉␉␉␉␉done␊ |
␉␉␉((xmlindent--))␊ |
␉␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
␉␉# End build resolution packages␊ |
␉␉echo "Building Options package"␊ |
␊ |
␉((xmlindent--))␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
# End build options packages␊ |
␊ |
␉# build utility package␊ |
␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Utility\">"␊ |
␉␉choices[$((choicescount++))]="<choice\n\tid=\"Utility\"\n\ttitle=\"Utility_title\"\n\tdescription=\"Utility_description\"\n>\n</choice>\n"␊ |
␉␉((xmlindent++))␊ |
␉␉packagesidentity="org.chameleon.utility"␊ |
␊ |
␉␉# build package for Chameleon PrefPanel␊ |
␉␉␉mkdir -p "${1}/PrefPanel/Root/"␊ |
␉␉␉echo "Building Chameleon Preference Panel package"␊ |
␉␉␉buildpackage "${1}/PrefPanel" "/" "" "start_selected=\"false\""␊ |
␉␉# End build package for Chameleon PrefPanel␊ |
␊ |
␉␉# build package for SMBIOSDefault␊ |
␉␉␉mkdir -p "${1}/SMBIOSDefault/Root/"␊ |
␉␉␉echo "Building SMBIOSDefault package"␊ |
␉␉␉buildpackage "${1}/SMBIOSDefault" "/" "" "start_selected=\"false\""␊ |
␉␉# End build package for SMBIOSDefault␊ |
␉␉␊ |
␉␉# build package for EFIMounter␊ |
␉␉␉mkdir -p "${1}/EFIMounter/Root/"␊ |
␉␉␉echo "Building EFIMounter package"␊ |
␉␉␉buildpackage "${1}/EFIMounter" "/" "" "start_selected=\"false\""␊ |
␉␉# End build package for EFIMounter␊ |
␊ |
␉␉((xmlindent--))␊ |
␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
␉# End utility package␊ |
␊ |
␉# build kext packages ␊ |
␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"Kexts\">"␊ |
␉␉choices[$((choicescount++))]="<choice\n\tid=\"Kexts\"\n\ttitle=\"Kexts_title\"\n\tdescription=\"Kexts_description\"\n>\n</choice>\n"␊ |
␉␉((xmlindent++))␊ |
␉␉packagesidentity="org.chameleon"␊ |
␉␉kexts=($( find "${pkgroot}/Kexts" -type d -name '*.kext' -depth 1 ))␊ |
␉␉for (( i = 0 ; i < ${#kexts[@]} ; i++ )) ␊ |
␉␉do␊ |
␉␉␉filename="${kexts[$i]##*/}"␊ |
␉␉␉mkdir -p "${1}/${filename%.kext}/Root/"␊ |
␉␉␉buildpackage "${1}/${filename%.kext}" "/" "" "start_selected=\"false\""␊ |
␉␉done␊ |
␉␉echo "Building kext package"␊ |
␉␉((xmlindent--))␊ |
␉␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t</line>"␊ |
␉# End build kext packages ␊ |
␊ |
# build package for Documents␊ |
␉packagesidentity="org.chameleon.Documents"␊ |
␉mkdir -p "${1}/Documents/Root"␊ |
␉echo "Building Documents package"␊ |
␉buildpackage "${1}/Documents" "/" "" "start_visible=\"false\" start_selected=\"true\""␊ |
# End build package for Documents␊ |
␊ |
# build package for bdmesg␊ |
␉packagesidentity="org.chameleon.bdmesg"␊ |
␉mkdir -p "${1}/bdmesg/Root"␊ |
␉echo "Building bdmesg package"␊ |
␉buildpackage "${1}/bdmesg" "/" "" "start_visible=\"false\" start_selected=\"true\""␊ |
# End build package for bdmesg␊ |
␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}</choices-outline>" # End main package␊ |
␊ |
# build meta package␊ |
␊ |
␉makedistribution "${1}" "${2}" "${3}" "${4}" "${5}"␊ |
␊ |
# clean up ␊ |
␊ |
␉rm -R -f "${1}"␊ |
␊ |
}␊ |
␊ |
fixperms ()␊ |
{␊ |
␉# $1 path␊ |
␉find "${1}" -type f -exec chmod 644 {} \;␊ |
␉find "${1}" -type d -exec chmod 755 {} \;␊ |
␉chown -R 0:0 "${1}"␊ |
}␊ |
␊ |
buildpackage ()␊ |
{␊ |
# $1 Path to package to build containing Root and or Scripts␊ |
# $2 Install Location␊ |
# $3 Size␊ |
# $4 Options␊ |
␊ |
if [ -d "${1}/Root" ] && [ "${1}/Scripts" ]; then␊ |
␊ |
␉local packagename="${1##*/}"␊ |
␉local identifier=$( echo ${packagesidentity}.${packagename//_/.} | tr [:upper:] [:lower:] )␊ |
␉find "${1}" -name '.DS_Store' -delete␊ |
␉local filecount=$( find "${1}/Root" | wc -l )␊ |
␉if [ "${3}" ]; then␊ |
␉␉local installedsize="${3}"␊ |
␉else␊ |
␉␉local installedsize=$( du -hkc "${1}/Root" | tail -n1 | awk {'print $1'} )␊ |
␉fi␊ |
␉local header="<?xml version=\"1.0\"?>\n<pkg-info format-version=\"2\" "␊ |
␊ |
␉#[ "${3}" == "relocatable" ] && header+="relocatable=\"true\" "␉␉␊ |
␊ |
␉header+="identifier=\"${identifier}\" "␊ |
␉header+="version=\"${version}\" "␊ |
␊ |
␉[ "${2}" != "relocatable" ] && header+="install-location=\"${2}\" "␊ |
␊ |
␉header+="auth=\"root\">\n"␊ |
␉header+="\t<payload installKBytes=\"${installedsize##* }\" numberOfFiles=\"${filecount##* }\"/>\n"␊ |
␉rm -R -f "${1}/Temp"␊ |
␊ |
␉[ -d "${1}/Temp" ] || mkdir -m 777 "${1}/Temp"␊ |
␉[ -d "${1}/Root" ] && mkbom "${1}/Root" "${1}/Temp/Bom"␊ |
␊ |
␉if [ -d "${1}/Scripts" ]; then ␊ |
␉␉header+="\t<scripts>\n"␊ |
␉␉for script in $( find "${1}/Scripts" -type f \( -name 'pre*' -or -name 'post*' \) )␊ |
␉␉do␊ |
␉␉␉header+="\t\t<${script##*/} file=\"./${script##*/}\"/>\n"␊ |
␉␉done␊ |
␉␉header+="\t</scripts>\n"␊ |
␉␉chown -R 0:0 "${1}/Scripts"␊ |
␉␉pushd "${1}/Scripts" >/dev/null␊ |
␉␉find . -print | cpio -o -z -H cpio > "../Temp/Scripts"␊ |
␉␉popd >/dev/null␊ |
␉fi␊ |
␊ |
␉header+="</pkg-info>"␊ |
␉echo -e "${header}" > "${1}/Temp/PackageInfo"␊ |
␉pushd "${1}/Root" >/dev/null␊ |
␉find . -print | cpio -o -z -H cpio > "../Temp/Payload"␊ |
␉popd >/dev/null␊ |
␉pushd "${1}/Temp" >/dev/null␊ |
␊ |
␉xar -c -f "${1%/*}/${packagename// /}.pkg" --compression none .␊ |
␊ |
␉popd >/dev/null␊ |
␊ |
␉outline[$((outlinecount++))]="${indent[$xmlindent]}\t<line choice=\"${packagename// /}\"/>"␊ |
␊ |
␉if [ "${4}" ]; then␊ |
␉␉local choiceoptions="${indent[$xmlindent]}${4}\n"␉␊ |
␉fi␊ |
␉choices[$((choicescount++))]="<choice\n\tid=\"${packagename// /}\"\n\ttitle=\"${packagename}_title\"\n\tdescription=\"${packagename}_description\"\n${choiceoptions}>\n\t<pkg-ref id=\"${identifier}\" installKBytes='${installedsize}' version='${version}.0.0.${timestamp}' auth='root'>#${packagename// /}.pkg</pkg-ref>\n</choice>\n"␊ |
␊ |
␉rm -R -f "${1}"␊ |
fi␊ |
}␊ |
␊ |
makedistribution ()␊ |
{␊ |
␉rm -f "${1%/*}/${packagename// /}"-Dummy.pkg␊ |
␉find "${1}" -type f -name '*.pkg' -depth 1 | while read component␊ |
␉do␊ |
␉␉mkdir -p "${1}/${packagename}/${component##*/}"␊ |
␉␉pushd "${1}/${packagename}/${component##*/}" >/dev/null␊ |
␉␉xar -x -f "${1%}/${component##*/}"␊ |
␉␉popd >/dev/null␊ |
␉done␊ |
␊ |
␉ditto --noextattr --noqtn "${pkgroot}/Icon.icns" "${1%/*}/${packagename// /}-${version}-r${revision}-Dummy.pkg"␊ |
␉ditto --noextattr --noqtn "${pkgroot}/Distribution" "${1}/${packagename}/Distribution"␊ |
␉ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"␊ |
#␉ditto --noextattr --noqtn "${pkgroot}/Icon.icns" "${1%}/${packagename}/.Icon"␊ |
␊ |
␉echo "Building Resources..."␊ |
␉find "${1}/${packagename}/Resources" -type d -name '.svn' -exec rm -R -f {} \; 2>/dev/null␊ |
␊ |
␉for (( i=0; i < ${#outline[*]} ; i++));␊ |
␉␉do␊ |
␉␉␉echo -e "${outline[$i]}" >> "${1}/${packagename}/Distribution"␊ |
␉␉done␊ |
␊ |
␉for (( i=0; i < ${#choices[*]} ; i++));␊ |
␉␉do␊ |
␉␉␉echo -e "${choices[$i]}" >> "${1}/${packagename}/Distribution"␊ |
␉␉done␊ |
␊ |
␉echo "</installer-gui-script>" >> "${1}/${packagename}/Distribution"␊ |
␊ |
␉perl -i -p -e "s/%CHAMELEONVERSION%/${version%%-*}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
␉perl -i -p -e "s/%CHAMELEONREVISION%/${revision}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
␊ |
# place for info about the kind of pkg standard or advanced or dummy(language test)␊ |
␉perl -i -p -e "s/%PKGTYPE%/Dummy pkg installer/g" `find "${1}/${packagename}/Resources" -type f`␊ |
# end place for info␊ |
␊ |
␉stage=${stage/RC/Release Candidate }␊ |
␉stage=${stage/FINAL/2.0 Final}␊ |
␉perl -i -p -e "s/%CHAMELEONSTAGE%/${stage}/g" `find "${1}/${packagename}/Resources" -type f`␊ |
␊ |
␉find "${1}/${packagename}" -name '.DS_Store' -delete␊ |
␉pushd "${1}/${packagename}" >/dev/null␊ |
␉xar -c -f "${1%/*}/${packagename// /}-${version}-r${revision}-Dummy.pkg" --compression none .␊ |
␉popd >/dev/null␊ |
␊ |
␊ |
␊ |
␉md5=$( md5 "${1%/*}/${packagename// /}-${version}-r${revision}-Dummy.pkg" | awk {'print $4'} )␊ |
␉echo "MD5 (${packagename// /}-${version}-r${revision}-Dummy.pkg) = ${md5}" > "${1%/*}/${packagename// /}-${version}-r${revision}-Dummy.pkg.md5"␊ |
␉␊ |
#␉Here is the place for "copy" a compiled version of text inside the welcome & conclusion file␉␊ |
# cp -R -f "${1}/${packagename}/Resources" ${1%/*}/Resources␊ |
#␉End place for copy Resouces␊ |
␊ |
␉echo "Finish! $packagename Install Package (Dummy) v${version%%-*} $stage r$revision was created"␊ |
␊ |
}␊ |
␊ |
main "${1}" "${2}" "${3}" "${4}" "${5}"␊␊ |