#!/bin/sh -e


# Install script for the Darwin Streaming Server
# source release

if [ $1 = "-f" ]; then
	FLATTEN=1
	INSTALLROOT=$2
else
	FLATTEN=0
	INSTALLROOT=$1
fi

echo Installing source build of Darwin Streaming Server

if [ -z $INSTALLROOT ]; then
	echo "usage: DSS_MakeRoot [-f] rootdirname"
	echo " -f: flatten directory hierarchy"
	exit 1
fi

if [ -d $INSTALLROOT ];
then :
else
	echo "creating directory $INSTALLROOT"
	mkdir -p $INSTALLROOT
fi

if [ $FLATTEN != 1 ]; then
	# Install each file into it's appropriate location relative to "$INSTALLROOT"

	echo creating "$INSTALLROOT/usr/local/sbin" directory
	mkdir -p $INSTALLROOT/usr/local/sbin

	echo copying "DarwinStreamingServer" to "$INSTALLROOT/usr/local/sbin/DarwinStreamingServer"
	cp DarwinStreamingServer $INSTALLROOT/usr/local/sbin/
	
	echo creating "$INSTALLROOT/usr/local/bin" directory
	mkdir -p $INSTALLROOT/usr/local/bin

	echo copying "PlaylistBroadcaster" to "$INSTALLROOT/usr/local/bin/PlaylistBroadcaster"
	cp PlaylistBroadcaster.tproj/PlaylistBroadcaster $INSTALLROOT/usr/local/bin/
	
	echo copying "MP3Broadcaster" to "$INSTALLROOT/usr/local/bin/MP3Broadcaster"
	cp MP3Broadcaster/MP3Broadcaster $INSTALLROOT/usr/local/bin/
	
	echo copying "qtpasswd" to "$INSTALLROOT/usr/local/bin/qtpasswd"
	cp qtpasswd.tproj/qtpasswd $INSTALLROOT/usr/local/bin/
	
	echo creating "$INSTALLROOT/usr/local/sbin/StreamingServerModules" directory
	mkdir $INSTALLROOT/usr/local/sbin/StreamingServerModules

	echo creating "$INSTALLROOT/etc/streaming" directory
	mkdir -p $INSTALLROOT/etc/streaming
	
	echo copying "streamingserver.xml-POSIX" to "$INSTALLROOT/etc/streaming/streamingserver.xml"
	cp -i streamingserver.xml-POSIX $INSTALLROOT/etc/streaming/streamingserver.xml
	echo copying "streamingserver.xml-POSIX" to "$INSTALLROOT/etc/streaming/streamingserver.xml-sample"
	cp -i streamingserver.xml-POSIX $INSTALLROOT/etc/streaming/streamingserver.xml-sample
	
	echo copying "relayconfig.xml-Sample" to "$INSTALLROOT/etc/streaming/relayconfig.xml-Sample"
	cp -i relayconfig.xml-Sample $INSTALLROOT/etc/streaming/

	echo copying "qtusers" to "$INSTALLROOT/etc/streaming/qtusers"
	cp -i qtusers $INSTALLROOT/etc/streaming/
	
	echo copying "qtgroups" to "$INSTALLROOT/etc/streaming/qtgroups"
	cp -i qtgroups $INSTALLROOT/etc/streaming/

	echo creating "$INSTALLROOT/var/streaming/logs" directory
	mkdir -p $INSTALLROOT/var/streaming/logs
	
	echo copying "Documentation/AboutDarwinStreamingSvr.pdf" into "$INSTALLROOT/var/streaming/readme.pdf"
	cp Documentation/AboutDarwinStreamingSvr.pdf $INSTALLROOT/var/streaming/readme.pdf
	
	echo copying "Documentation/3rdPartyAcknowledgements.rtf" into "$INSTALLROOT/var/streaming/3rdPartyAcknowledgements.rtf"
	cp Documentation/3rdPartyAcknowledgements.rtf $INSTALLROOT/var/streaming/3rdPartyAcknowledgements.rtf
	
	echo creating "$INSTALLROOT/usr/local/movies" directory
	mkdir -p $INSTALLROOT/usr/local/movies
	
        echo copying "sample_100kbit.mov" into "$INSTALLROOT/usr/local/movies"
        cp sample_100kbit.mov $INSTALLROOT/usr/local/movies/

        echo copying "sample_300kbit.mov" into "$INSTALLROOT/usr/local/movies"
        cp sample_300kbit.mov $INSTALLROOT/usr/local/movies/

        echo copying "sample_100kbit.mp4" into "$INSTALLROOT/usr/local/movies"
        cp sample_100kbit.mp4 $INSTALLROOT/usr/local/movies/

        echo copying "sample_300kbit.mp4" into "$INSTALLROOT/usr/local/movies"
        cp sample_300kbit.mp4 $INSTALLROOT/usr/local/movies/

        echo copying "sample.mp3" into "$INSTALLROOT/usr/local/movies"
        cp sample.mp3 $INSTALLROOT/usr/local/movies/

    if [-d SpamPro.tproj ]; then
	echo copying "StreamingLoadTool" to "$INSTALLROOT/usr/local/bin/StreamingLoadTool"
	cp SpamPro.tproj/StreamingLoadTool $INSTALLROOT/usr/local/bin/
	
	echo copying "streamingloadtool.conf" to "$INSTALLROOT/etc/streaming/streamingloadtool.conf"
	cp SpamPro.tproj/streamingloadtool.conf $INSTALLROOT/etc/streaming/streamingloadtool.conf
	else
                echo "Warning: there is no SpamPro.tproj folder"
    fi
        
	#WebAdmin install

	echo copying "streamingadminserver.pl" into "$INSTALLROOT/usr/local/sbin/"
	cp WebAdmin/src/streamingadminserver.pl $INSTALLROOT/usr/local/sbin/streamingadminserver.pl

	#echo copying "streamingadminserver.pem" into "$INSTALLROOT/etc/streaming/"
	#cp WebAdmin/streamingadminserver.pem $INSTALLROOT/etc/streaming/streamingadminserver.pem
	
	echo creating "$INSTALLROOT/var/streaming/AdminHtml" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml
	
	echo copying Admin HTML to "$INSTALLROOT/var/streaming/AdminHtml" directory
	cp WebAdmin/WebAdminHtml/*.pl $INSTALLROOT/var/streaming/AdminHtml/
	cp WebAdmin/WebAdminHtml/*.cgi $INSTALLROOT/var/streaming/AdminHtml/
	cp WebAdmin/WebAdminHtml/*.html $INSTALLROOT/var/streaming/AdminHtml/
    
	echo creating "$INSTALLROOT/var/streaming/AdminHtml/images/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/images/
	cp WebAdmin/WebAdminHtml/images/*.gif $INSTALLROOT/var/streaming/AdminHtml/images/
	
	echo creating "$INSTALLROOT/var/streaming/AdminHtml/includes/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/includes/
	cp WebAdmin/WebAdminHtml/includes/*.js $INSTALLROOT/var/streaming/AdminHtml/includes/
	
	echo creating "$INSTALLROOT/var/streaming/AdminHtml/html_en/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/html_en/
	cp WebAdmin/WebAdminHtml/html_en/messages $INSTALLROOT/var/streaming/AdminHtml/html_en/
	cp WebAdmin/WebAdminHtml/html_en/genres $INSTALLROOT/var/streaming/AdminHtml/html_en/
	
	echo creating "$INSTALLROOT/var/streaming/AdminHtml/html_de/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/html_de/
	cp WebAdmin/WebAdminHtml/html_de/messages $INSTALLROOT/var/streaming/AdminHtml/html_de/
	cp WebAdmin/WebAdminHtml/html_de/genres $INSTALLROOT/var/streaming/AdminHtml/html_de/

	echo creating "$INSTALLROOT/var/streaming/AdminHtml/html_fr/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/html_fr/
	cp WebAdmin/WebAdminHtml/html_fr/messages $INSTALLROOT/var/streaming/AdminHtml/html_fr/
	cp WebAdmin/WebAdminHtml/html_fr/genres $INSTALLROOT/var/streaming/AdminHtml/html_fr/

	echo creating "$INSTALLROOT/var/streaming/AdminHtml/html_ja/" directory
	mkdir -p $INSTALLROOT/var/streaming/AdminHtml/html_ja/
	cp WebAdmin/WebAdminHtml/html_ja/messages $INSTALLROOT/var/streaming/AdminHtml/html_ja/
	cp WebAdmin/WebAdminHtml/html_ja/genres $INSTALLROOT/var/streaming/AdminHtml/html_ja/
	
else
	# Build a "flat" directory containing an "Install" script

	echo copying "Install" to "$INSTALLROOT"
	cp Install $INSTALLROOT/Install
	
	echo copying "DarwinStreamingServer" to "$INSTALLROOT/DarwinStreamingServer"
	cp DarwinStreamingServer $INSTALLROOT/
	
	echo copying "PlaylistBroadcaster" to "$INSTALLROOT/PlaylistBroadcaster"
	cp PlaylistBroadcaster.tproj/PlaylistBroadcaster $INSTALLROOT/
	
	echo copying "MP3Broadcaster" to "$INSTALLROOT/MP3Broadcaster"
	cp MP3Broadcaster/MP3Broadcaster $INSTALLROOT/
	
	echo copying "qtpasswd" to "$INSTALLROOT/qtpasswd"
	cp qtpasswd.tproj/qtpasswd $INSTALLROOT/

	echo creating "$INSTALLROOT/StreamingServerModules" directory
	mkdir -p $INSTALLROOT/StreamingServerModules
	
	echo copying "streamingserver.xml-POSIX" to "$INSTALLROOT/streamingserver.xml"
	cp streamingserver.xml-POSIX $INSTALLROOT/streamingserver.xml
	
	echo copying "streamingserver.xml-POSIX" to "$INSTALLROOT/streamingserver.xml-sample"
	cp streamingserver.xml-POSIX $INSTALLROOT/streamingserver.xml-sample
	
	echo copying "relayconfig.xml-Sample" to "$INSTALLROOT/relayconfig.xml-Sample"
	cp relayconfig.xml-Sample $INSTALLROOT/

	echo copying "qtusers" to "$INSTALLROOT/qtusers"
    cp qtusers $INSTALLROOT/
	
	echo copying "qtgroups" to "$INSTALLROOT/qtgroups"
    cp qtgroups $INSTALLROOT/

	echo copying "Documentation/AboutDarwinStreamingSvr.pdf" into "readme.pdf"
	cp Documentation/AboutDarwinStreamingSvr.pdf $INSTALLROOT/readme.pdf
	
 	echo copying "Documentation/3rdPartyAcknowledgements.rtf" into "$INSTALLROOT/3rdPartyAcknowledgements.rtf"
	cp Documentation/3rdPartyAcknowledgements.rtf $INSTALLROOT/3rdPartyAcknowledgements.rtf
	
       echo copying "sample_100kbit.mov" into "$INSTALLROOT/sample_100kbit.mov"
        cp sample_100kbit.mov $INSTALLROOT/

        echo copying "sample_300kbit.mov" into "$INSTALLROOT/sample_300kbit.mov"
        cp sample_300kbit.mov $INSTALLROOT/

        echo copying "sample_100kbit.mp4" into "$INSTALLROOT/sample_100kbit.mp4"
        cp sample_100kbit.mp4 $INSTALLROOT/

        echo copying "sample_300kbit.mp4" into "$INSTALLROOT/sample_300kbit.mp4"
        cp sample_300kbit.mp4 $INSTALLROOT/

        echo copying "sample.mp3" into "$INSTALLROOT/sample.mp3"
        cp sample.mp3 $INSTALLROOT/

    if [ -d SpamPro.tproj ]; then
	echo copying "StreamingLoadTool" to "$INSTALLROOT/StreamingLoadTool"
	cp SpamPro.tproj/StreamingLoadTool $INSTALLROOT/
	
	echo copying "streamingloadtool.conf" to "$INSTALLROOT/streamingloadtool.conf"
	cp SpamPro.tproj/streamingloadtool.conf $INSTALLROOT/
	else
                echo "Warning: there is no SpamPro.tproj folder"
    fi
        
	#WebAdmin install
	
	# copy the perlpath.pl script to the top level so that Install script can run it
	echo copying "perlpath.pl" into "$INSTALLROOT/"
	cp WebAdmin/perlpath.pl $INSTALLROOT/perlpath.pl

	echo copying "streamingadminserver.pl" into "$INSTALLROOT/"
	cp WebAdmin/src/streamingadminserver.pl $INSTALLROOT/streamingadminserver.pl

	#echo copying "streamingadminserver.pem" into "$INSTALLROOT/"
	#cp WebAdmin/streamingadminserver.pem $INSTALLROOT/streamingadminserver.pem
	
	echo creating "$INSTALLROOT/AdminHtml" directory
	mkdir -p $INSTALLROOT/AdminHtml
	
	echo copying Admin HTML to "$INSTALLROOT/AdminHtml" directory
	cp WebAdmin/WebAdminHtml/*.pl $INSTALLROOT/AdminHtml/
	cp WebAdmin/WebAdminHtml/*.cgi $INSTALLROOT/AdminHtml/
	cp WebAdmin/WebAdminHtml/*.html $INSTALLROOT/AdminHtml/

	echo creating "$INSTALLROOT/AdminHtml/images/" directory
	mkdir -p $INSTALLROOT/AdminHtml/images/
	cp WebAdmin/WebAdminHtml/images/*.gif $INSTALLROOT/AdminHtml/images/
	
	echo creating "$INSTALLROOT/AdminHtml/includes/" directory
	mkdir -p $INSTALLROOT/AdminHtml/includes/
	cp WebAdmin/WebAdminHtml/includes/*.js $INSTALLROOT/AdminHtml/includes/
	
	echo creating "$INSTALLROOT/AdminHtml/html_en/" directory
	mkdir -p $INSTALLROOT/AdminHtml/html_en/
	cp WebAdmin/WebAdminHtml/html_en/messages $INSTALLROOT/AdminHtml/html_en/
	cp WebAdmin/WebAdminHtml/html_en/genres $INSTALLROOT/AdminHtml/html_en/
	
	echo creating "$INSTALLROOT/AdminHtml/html_de/" directory
	mkdir -p $INSTALLROOT/AdminHtml/html_de/
	cp WebAdmin/WebAdminHtml/html_de/messages $INSTALLROOT/AdminHtml/html_de/
	cp WebAdmin/WebAdminHtml/html_de/genres $INSTALLROOT/AdminHtml/html_de/

	echo creating "$INSTALLROOT/AdminHtml/html_fr/" directory
	mkdir -p $INSTALLROOT/AdminHtml/html_fr/
	cp WebAdmin/WebAdminHtml/html_fr/messages $INSTALLROOT/AdminHtml/html_fr/
	cp WebAdmin/WebAdminHtml/html_fr/genres $INSTALLROOT/AdminHtml/html_fr/

	echo creating "$INSTALLROOT/AdminHtml/html_ja/" directory
	mkdir -p $INSTALLROOT/AdminHtml/html_ja/
	cp WebAdmin/WebAdminHtml/html_ja/messages $INSTALLROOT/AdminHtml/html_ja/
	cp WebAdmin/WebAdminHtml/html_ja/genres $INSTALLROOT/AdminHtml/html_ja/

fi



echo
echo Done.
