#!/bin/bash
#
# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/scripts/Create-SrcTar
# ROCK Linux is Copyright (C) 1998 - 2004 Clifford Wolf
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---

if [ "$1" == -help ] ; then
	echo
	echo "Usage: ./scripts/Create-SrcTar"
	echo
	echo " Create a .tar.bz2 file containing the ROCK Linux sources. This script is"
	echo " used by the ROCK Linux core developers when releasing snapshots or releases."
	echo ; exit 
fi

eval "`grep -A 10 '\[BEGIN\]' scripts/parse-config | grep -B 10 '\[END\]'`"

echo -n 'Creating source tar ... '

# Create temp source base dir
#
src="`mktemp -d -p $PWD src.srctar.XXXXXXXXXX`"
base=${base:-${PWD}}
rm -rf $src/rock-src-$rockver
mkdir -p $src/rock-src-$rockver
#
for x in scripts target misc package architecture Documentation
do
	ln -s ../../$x $src/rock-src-$rockver/$x
done

# Create tar file
#
cd $src
tar --use-compress-program=bzip2 --owner root --group root \
    --exclude .svn --exclude CVS -cf ${1:-${base}/rock-src-$rockver.tar.bz2} rock-src-$rockver/*/*
# Done.
#
cd $base
rm -rf $src/
du -sh ${1:-rock-src-$rockver.tar.bz2} | tr '\t' ' '