#!/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 (Standard) v${version%%-*} $stage r$revision $builddate"
outline[$((outlinecount++))]="${indent[$xmlindent]}"
# Start
# build Chameleon package
outline[$((outlinecount++))]="${indent[$xmlindent]}\t"
choices[$((choicescount++))]="\n\n"
((xmlindent++))
# build core package
mkdir -p ${1}/Core/Root/usr/sbin
mkdir -p ${1}/Core/Root/usr/standalone/i386
cp -f ${1%/*}/i386/boot ${1}/Core/Root/usr/standalone/i386
cp -f ${1%/*}/i386/boot0 ${1}/Core/Root/usr/standalone/i386
cp -f ${1%/*}/i386/boot0hfs ${1}/Core/Root/usr/standalone/i386
cp -f ${1%/*}/i386/boot1h ${1}/Core/Root/usr/standalone/i386
cp -f ${pkgroot}/fdisk ${1}/Core/Root/usr/sbin
cp -f ${pkgroot}/fdisk440 ${1}/Core/Root/usr/sbin
fixperms "${1}/Core/Root/"
local coresize=$( du -hkc "${1}/Core/Root" | tail -n1 | awk {'print $1'} )
echo "Building core package"
buildpackage "${1}/Core" "/binaries" "0" "start_visible=\"false\" start_selected=\"true\""
# End build core package
# build standard package
mkdir -p ${1}/Standard/Root
mkdir -p ${1}/Standard/Scripts
cp -f ${pkgroot}/Scripts/Standard/postinstall ${1}/Standard/Scripts
ditto --arch i386 `which SetFile` ${1}/Standard/Scripts/Tools/SetFile
echo "Building boot0 package"
buildpackage "${1}/Standard" "/binaries" "${coresize}" "start_enabled=\"true\" start_selected=\"true\" selected=\"exclusive(choices['Standardhfs']) && exclusive(choices['noboot'])\""
# End build standard package
# build standard package with boot0hfs
mkdir -p ${1}/Standardhfs/Root
mkdir -p ${1}/Standardhfs/Scripts
cp -f ${pkgroot}/Scripts/Standardhfs/postinstall ${1}/Standardhfs/Scripts
ditto --arch i386 `which SetFile` ${1}/Standardhfs/Scripts/Tools/SetFile
echo "Building boot0hfs package"
buildpackage "${1}/Standardhfs" "/binaries" "${coresize}" "start_enabled=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['noboot'])\""
# End build standard package with boot0hfs
# build reset choice package
mkdir -p ${1}/noboot/Root
# echo "Building reset choice package"
buildpackage "${1}/noboot" "/binaries" "" "start_visible=\"true\" start_selected=\"false\" selected=\"exclusive(choices['Standard']) && exclusive(choices['Standardhfs'])\""
# End build reset choice package
((xmlindent--))
outline[$((outlinecount++))]="${indent[$xmlindent]}\t" # End Chameleon pakage
# build theme packages
outline[$((outlinecount++))]="${indent[$xmlindent]}\t"
choices[$((choicescount++))]="\n\n"
((xmlindent++))
packagesidentity="org.chameleon.theme"
artwork="${1%/*}"
# Embed
mkdir -p ${1}/Embed/Root
ditto --noextattr --noqtn ${artwork%/*}/artwork/themes/embed ${1}/Embed/Root/Embed
find ${1}/Embed/ -name '.DS_Store' -or -name '.svn' -exec rm -R {} \+
find ${1}/Embed/ -type f -exec chmod 644 {} \+
buildpackage "${1}/Embed" "/Extra/Themes" "" "start_selected=\"false\""
# Legacy
mkdir -p ${1}/Embed/Root
ditto --noextattr --noqtn ${artwork%/*}/artwork/themes/legacy ${1}/Legacy/Root/Legacy
find ${1}/Legacy/ -name '.DS_Store' -or -name '.svn' -exec rm -R {} \+
find ${1}/Legacy/ -type f -exec chmod 644 {} \+
buildpackage "${1}/Legacy" "/Extra/Themes" "" "start_selected=\"false\""
# Default
mkdir -p ${1}/Default/Root
ditto --noextattr --noqtn ${artwork%/*}/artwork/themes/default ${1}/Default/Root/Default
find ${1}/Default/ -name '.DS_Store' -or -name '.svn' -exec rm -R {} \+
find ${1}/Default/ -type f -exec chmod 644 {} \+
buildpackage "${1}/Default" "/Extra/Themes" "" "start_selected=\"false\""
echo "Building themes package"
((xmlindent--))
outline[$((outlinecount++))]="${indent[$xmlindent]}\t" # End build theme packages
# build package for Documentation
mkdir -p "${1}/Documentation/Root"
cp -f ${pkgroot}/doc/BootHelp.txt ${1}/Documentation/Root
cp -f ${pkgroot}/doc/README ${1}/Documentation/Root
cp -f ${pkgroot}/doc/Users_Guide0.5.pdf ${1}/Documentation/Root
echo "Building Documentation package"
buildpackage "${1}/Documentation" "/Documentation/Chameleon" "" "start_visible=\"false\" start_selected=\"true\""
# End build package for Documentation
# build package for bdmesg
mkdir -p "${1}/bdmesg/Root"
ditto --noextattr --noqtn "${1%/*}/i386/bdmesg" "${1}/bdmesg/Root"
echo "Building bdmesg package"
buildpackage "${1}/bdmesg" "/usr/sbin" "" "start_visible=\"false\" start_selected=\"true\""
# End build package for bdmesg
# build post install package
mkdir -p ${1}/Post/Root
mkdir -p ${1}/Post/Scripts
cp -f ${pkgroot}/Scripts/Post/postinstall ${1}/Post/Scripts
ditto --arch i386 `which SetFile` ${1}/Post/Scripts/Tools/SetFile
buildpackage "${1}/Post" "/binaries" "" "start_visible=\"false\" start_selected=\"true\""
echo "Building post package"
# End post install package
outline[$((outlinecount++))]="${indent[$xmlindent]}" # 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="\n\n"
header+="\t\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\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\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+=""
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"
if [ "${4}" ]; then
local choiceoptions="${indent[$xmlindent]}${4}\n"
fi
choices[$((choicescount++))]="\n\t#${packagename// /}.pkg\n\n"
rm -R -f "${1}"
fi
}
makedistribution ()
{
rm -f "${1%/*}/${packagename// /}"-Standard.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}/Distribution" "${1}/${packagename}/Distribution"
ditto --noextattr --noqtn "${pkgroot}/Resources" "${1}/${packagename}/Resources"
ditto --noextattr --noqtn "${pkgroot}/Chameleon.icns" "${1%/*}/${packagename// /}-${version}-r${revision}-Standard.pkg"
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 "" >> "${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`
#
perl -i -p -e "s/%PKGTYPE%/Standard/g" `find "${1}/${packagename}/Resources" -type f`
#
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}-Standard.pkg" --compression none .
popd >/dev/null
md5=$( md5 "${1%/*}/${packagename// /}-${version}-r${revision}-Standard.pkg" | awk {'print $4'} )
echo "MD5 (${packagename// /}-${version}-r${revision}-Standard.pkg) = ${md5}" > "${1%/*}/${packagename// /}-${version}-r${revision}-Standard.pkg.md5"
cp -R -f "${1}/${packagename}/Resources" ${1%/*}/Resources
echo "Finish! $packagename Install Package (Standard) v${version%%-*} $stage r$revision was created"
}
main "${1}" "${2}" "${3}" "${4}" "${5}"