#!/bin/sh

# Copyright (C) 2008-2010 Twilight Coders
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. 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.
# 3. The name of the author may not be used to endorse or promote
#    products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR `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 AUTHOR 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.

# Simplifies the process of adding the CodeIgniter framework to any
# project set up to use it. For instance, your project should
# consist of only the files you've modified, and then you add in
# the rest of the CodeIgniter framework so that it doesn't disrupt
# your svn (or other version control). Can also be used for
# deploying your application.

if [ -z "$1" ] && [ -z "$2" ]; then
	echo "usage: /path/to/project/ /path/to/codeigniter-x.x.x/";
	exit;
fi

project=$1;
codeigniter=$2;
tempdir="project.codeigniter.work";
mkdir -p $tempdir;

# Make sure no .svn files are in here.
tar cf - -C "$codeigniter" --exclude=.svn . | tar xf - -C "$tempdir";

# There are some default views and controllers in the CodeIgniter base project. Delete these.
(cd $tempdir; rm -rf system/application/views; rm -rf system/application/controllers);

# Tar up project, without .svn and ._ files and expand into tempdir
(cd $project && tar cf - --exclude='\.svn' --exclude='\._*' .) | (cd $tempdir && tar xpf -)

# Tar up the tempdir (project now injected with CodeIgniter), without .svn and ._ files and expand back into project directory
(cd $tempdir && tar cf - --exclude='\.svn' --exclude='\._*' .) | (cd $project && tar xpf -)

# Clean up; get rid of tempdir
rm -rf $tempdir;


