#!/bin/bash
###############################################################################
# * Copyright (c) 2015, Stephanie Turner
# * All rights reserved.
# *
# * Redistribution and use in source and binary forms, with or without
# * modification, are permitted provided that the following conditions are met:
# *
# * Redistributions of source code must retain the above copyright notice,
# * this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# * this list of conditions and the following disclaimer in the documentation
# * and/or other materials provided with the distribution.
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# * POSSIBILITY OF SUCH DAMAGE.
###############################################################################
###############################################################################
# startcdn
#
# This file is a util to start a DVCS with the contents of the zipFile
#
# Usage: startcdn.sh <zipFile>
#
###############################################################################
# assumes all of the scripts are installed in the same directory
scripts_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$scripts_dir/"p4cdnUtils.sh
###############################################################################
# function startLocalDVCS <zip file>
#
# start the local dvcs and load the zip file
###############################################################################
function startLocalDVCS ()
{
echo "Starting the new DVCS...."
new_dvcs_dir=$1
zipfile=$2
stream=$3
logfile=$4
webserver=$5
archive_trigger_script_src=$6
echo "cleaning up existing dvcs"
if [ -d $new_dvcs_dir ]; then
rm -rf $new_dvcs_dir
fi
echo "Making the new dvcs ...."
mkdir $new_dvcs_dir
cd $new_dvcs_dir
p4 init -C0 -n -c $stream
echo "new_dvcs_dir: " $new_dvcs_dir
installTrigger $archive_trigger_script_src $new_dvcs_dir
echo "Unzipping $zipfile into the new DVCS...."
p4 unzip -A -i $zipfile
echo "Syncing workspace...."
#p4 sync
}
###############################################################################
# start executing
#
# Usage
#
# startLocalX.sh <dvcs_dirpath>
# <zipfile>
# <checkDepots>
# <stream>
# <archive_trigger>
# <webserver>
###############################################################################
echo "Starting local DVCS ...."
echo $* 1>&2
startLocalDVCS $1 $2 $3 $4 $5 $6