#!/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.
###############################################################################
###############################################################################
# p4cdn.sh
#
# This is the starting point for a set of prototype scripts that uses DVCS to
# help manage the read only storage and distribution of assets from a
# Content Delivery Network instead of the normal mounted local archive.
#
# The basic workflow for the distributor
#
# clone from the origin into a DVCS
# prep DVCS archives and meta for distribution to end users
# seed the CDN with read only archive files
# create a zipfile of meta/archive for distribution
# ship the zipfile to end users to load into their own DVCS
#
# The basic workflow for the end user
# Download the zipfile
# Load zipfile into dvcs
#
# Goals and advantages of using this methodology for distribution:
#
# Load balancing
# This workflow can take advantage of the smart load balancing built into
# content delivery networks like AWS or # Akamai.
#
# It delivers only the files that the user needs. This can theoretically save
# money on bandwidth usage.
#
# Streamlines release and upgrade workflow since Perforce Helix tracks
# integrations, edits and merges. This makes it less disruptive for producers
# and consumers.
#
# Although security was not the highest priority for this prototype,
# it should be able to connect into both CDN/filesystem and Perforce
# security and auditing features.
#
###############################################################################
# assumes all of the scripts are installed in the same directory
scripts_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source "$scripts_dir/"p4cdnUtils.sh
setup_CDN=0
refresh_clone=0
refresh_archive=0
refresh_zip=0
refresh_webserver=0
install_remote=0
install_trigger=0
while [[ "$#" > 0 ]]; do
case "$1" in
-setupCDN)
setup_CDN=1
shift
cloned_dvcs_dir=$1
shift
origin_user=$1
shift
origin_port=$1
shift
origin_remote=$1
shift
archive_trigger_script=$1
shift
cdn_archive_dir=$1
shift
zipfile=$1
shift
remoteSpec=$1
shift
;;
-clone)
refresh_clone=1
shift
cloned_dvcs_dir=$1
shift
origin_user=$1
shift
origin_port=$1
shift
origin_remote=$1
shift
;;
-archive)
refresh_archive=1
shift
cloned_dvcs_dir=$1
shift
cdn_archive_dir=$1
shift
;;
-zip)
refresh_zip=1
shift
zip_dir=$1
shift
zipfile=$1
shift
remoteSpec=$1
shift
;;
-installTrigger)
install_trigger=1
shift
archive_trigger_script=$1
shift
dvcs_dir=$1
shift
;;
-installRemote)
install_remote=1
shift
dvcs_dir=$1
shift
remoteSpec=$1
shift
;;
-startWeb)
refresh_webserver=1
shift
;;
-h|*)
echo "-archive : "
echo "-clone : "
echo "-zip : "
echo "-startWeb : "
shift
exit
;;
esac
done
if [[ $setup_CDN -ne 0 ]] ; then
refreshClone $cloned_dvcs_dir $origin_user $origin_port $origin_remote
addtestFiles.sh $cloned_dvcs_dir
cd $cloned_dvcs_dir
installRemoteSpec $cloned_dvcs_dir $remoteSpec
installTrigger $archive_trigger_script $cloned_dvcs_dir
archiveFiles $cloned_dvcs_dir $cdn_archive_dir
makeZip $cloned_dvcs_dir $zipfile $remoteSpec
startWebserver
fi
if [[ $refresh_clone -ne 0 ]] ; then
refreshClone $cloned_dvcs_dir $origin_user $origin_port $origin_remote
fi
if [[ $install_remote -ne 0 ]] ; then
installRemoteSpec $dvcs_dir $remoteSpec
fi
if [[ $install_trigger -ne 0 ]] ; then
installTrigger $archive_trigger_script $dvcs_dir
fi
if [[ $refresh_archive -ne 0 ]] ; then
echo "the archive args..."
echo $cloned_dvcs_dir
echo $cdn_archive_dir
archiveFiles $cloned_dvcs_dir $cdn_archive_dir
fi
if [[ $refresh_webserver -ne 0 ]] ; then
startWebserver
fi
if [[ $refresh_zip -ne 0 ]] ; then
makeZip $zip_dir $zipfile $remoteSpec
fi