#!/bin/sh
if [ "$1" = "" ] ; then
    echo "example: BuildOSXInstallerPkg [ dss | qtss_test | dss_test | dss_apple ] [ update ]"
    echo "[ dss ] is the public DarwinStreamingServer installer"
    echo "[ qtss_test ] is a test version of the Apple QuickTimeStreamingServer installer"
    echo "[ dss_test ] a test version of the Apple DarwinStreamingServer installer"
    echo "[ dss_apple ] is the private Apple DarwinStreamingServer installer"
    echo "[ update ] Don't clean just update the build before creating installer"
else 
   if [ `id -u` != 0 ]
   then
        echo "### You must be root or use sudo to build the installer. ###"
        exit 1
    fi

    if [ `uname` = "Darwin" ]; then
         if [ "$2" = "update" ] ; then
            echo "update"
         else
           rm -rf /tmp/StreamingServer.dst
           rm -rf ./build
         fi

        if [ "$1" = "dss" ] ; then
            ./UpdateDSSInstallerDocs
            echo "Build DarwinStreamingServer and installer"

            rm -rf ./DarwinStreamingServer.pkg
            ./Buildit dss install 
            /Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker -build -p `pwd`/DarwinStreamingServer.pkg -f /tmp/StreamingServer.dst/ -r pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources/ -i pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Info.plist
    
            #delete default untitled description, we will use the language version
            echo `date` "*remove default description*"
            rm ./DarwinStreamingServer.pkg/Contents/Resources/Description.plist

            #copy the english languge files to the installer
            cp -Rf pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources ./DarwinStreamingServer.pkg/Contents/
    
            #remove english error messages so installer uses the default localized strings.
            echo `date` "*remove english strings*"
            rm ./DarwinStreamingServer.pkg/Contents/Resources/English.lproj/VolumeCheck.strings
      
            #delete the CVS dirs
            echo `date` "*Look for and remove any CVS directories*"
            ./deleteCVSdirs ./DarwinStreamingServer.pkg 
    
            echo `date` "DarwinStreamingServer Package created at "`pwd`"/DarwinStreamingServer.pkg."
        fi

        if [ "$1" = "qtss_test" ] ; then    
            echo "Build QuickTimeStreamingServer installer"

            rm -rf ./QuickTimeStreamingServer.pkg
            ./Buildit qtss install   
            /Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker -build -p `pwd`/QuickTimeStreamingServer.pkg -f /tmp/StreamingServer.dst/ -r qtssPackageMetaData/qtssPackageMetaData/QuickTimeStreamingServer.pkg/Contents/Resources/ -i qtssPackageMetaData/qtssPackageMetaData/QuickTimeStreamingServer.pkg/Contents/Info.plist 
            
            #delete default untitled description, we will use the language version
            echo `date` "*remove default description*"
            rm ./QuickTimeStreamingServer.pkg/Contents/Resources/Description.plist
     
            #copy all the language files and the installer script files to the installer
            cp -rf qtssPackageMetaData/qtssPackageMetaData/QuickTimeStreamingServer.pkg/Contents/Resources/ ./QuickTimeStreamingServer.pkg/Contents/Resources/
    
            #delete the CVS dirs
            echo `date` "*Look for and remove any CVS directories*"
            ./deleteCVSdirs ./QuickTimeStreamingServer.pkg
    
            echo `date` "QuickTimeStreamingServer Package created at "`pwd`"/QuickTimeStreamingServer.pkg."
        fi

        if [ "$1" = "dss_test" ] ; then   
            ./UpdateDSSInstallerDocs

            echo "Build Apple DarwinStreamingServer test installer"

            rm -rf ./DarwinStreamingServer.pkg
            ./Buildit qtss install     
            /Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker -build -p `pwd`/DarwinStreamingServer.pkg -f /tmp/StreamingServer.dst/ -r pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources/ -i pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Info.plist 
            
            #delete default untitled description, we will use the language version
            echo `date` "*remove default description*"
            if [ -e "./DarwinStreamingServer.pkg/Contents/Resources/Description.plist" ]; then
                rm ./DarwinStreamingServer.pkg/Contents/Resources/Description.plist
            fi

            #copy the files to the installer
            cp -Rf ./dssPackageMetaData/dssPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources ./DarwinStreamingServer.pkg/Contents
       
            mv -f ./DarwinStreamingServer.pkg/Contents/Archive.pax.gz ./DarwinStreamingServer.pkg/Contents/Resources/DarwinStreamingServer.pax.gz 
            mv -f ./DarwinStreamingServer.pkg/Contents/Archive.bom ./DarwinStreamingServer.pkg/Contents/Resources/DarwinStreamingServer.bom 

            rm -f ./DarwinStreamingServer.pkg/Contents/Resources/DarwinStreamingServer.info
            rm -f ./DarwinStreamingServer.pkg/Contents/Info.plist
            rm -f ./DarwinStreamingServer.pkg/Contents/PkgInfo

            #delete the CVS dirs
            echo `date` "*Look for and remove any CVS directories*"
            ./deleteCVSdirs ./DarwinStreamingServer.pkg
    
            echo `date` "DarwinStreamingServer Package created at "`pwd`"/DarwinStreamingServer.pkg."
        fi

        if [ "$1" = "dss_apple" ] ; then   
            ./UpdateDSSInstallerDocs

            echo "Build Apple DarwinStreamingServer installer"

            rm -rf ./DarwinStreamingServer.pkg
            ./Buildit qtss install     
            /Developer/Applications/PackageMaker.app/Contents/MacOS/PackageMaker -build -p `pwd`/DarwinStreamingServer.pkg -f /tmp/StreamingServer.dst/ -r pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources/ -i pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Info.plist 
            
            rm ./DarwinStreamingServer.pkg/Contents/Resources/Description.plist

            #copy the english languge files to the installer
            cp -Rf pubPackageMetaData/pubPackageMetaData/DarwinStreamingServer.pkg/Contents/Resources ./DarwinStreamingServer.pkg/Contents/
           
            #delete default untitled description, we will use the language version
            echo `date` "*remove default description*"
            if [ -e "./DarwinStreamingServer.pkg/Contents/Resources/Description.plist" ]; then
                rm ./DarwinStreamingServer.pkg/Contents/Resources/Description.plist
            fi

            #delete the CVS dirs
            echo `date` "*Look for and remove any CVS directories*"
            ./deleteCVSdirs ./DarwinStreamingServer.pkg
    
            echo `date` "DarwinStreamingServer Package created at " `pwd` "/DarwinStreamingServer.pkg."
        fi

    fi
fi

