Blame MakeTools/expand_ofed.sh

Packit 857059
#!/bin/bash
Packit 857059
# BEGIN_ICS_COPYRIGHT8 ****************************************
Packit 857059
# 
Packit 857059
# Copyright (c) 2015, Intel Corporation
Packit 857059
# 
Packit 857059
# Redistribution and use in source and binary forms, with or without
Packit 857059
# modification, are permitted provided that the following conditions are met:
Packit 857059
# 
Packit 857059
#     * Redistributions of source code must retain the above copyright notice,
Packit 857059
#       this list of conditions and the following disclaimer.
Packit 857059
#     * Redistributions in binary form must reproduce the above copyright
Packit 857059
#       notice, this list of conditions and the following disclaimer in the
Packit 857059
#       documentation and/or other materials provided with the distribution.
Packit 857059
#     * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
#       may be used to endorse or promote products derived from this software
Packit 857059
#       without specific prior written permission.
Packit 857059
# 
Packit 857059
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
# 
Packit 857059
# END_ICS_COPYRIGHT8   ****************************************
Packit 857059
##
Packit 857059
## expand_ofed
Packit 857059
## -----------
Packit 857059
## expand an OFED tgz in preparation for source control in OFED vendor branch
Packit 857059
##
Packit 857059
## Usage:
Packit 857059
##	expand_ofed [-d dest_dir] [-c compare_dir] ofed.tgz
Packit 857059
##
Packit 857059
## Arguments:
Packit 857059
##	-d - destination for expansion, default is ./SOURCE_TREE
Packit 857059
##	-c - optional expanded ofed to compare to
Packit 857059
##  ofed.tgz - ofed tgz to expand
Packit 857059
## Environment:
Packit 857059
Packit 857059
tempdir=/usr/tmp/expand$$
Packit 857059
Packit 857059
# handle various places we could find our tools
Packit 857059
if [ -e ./expand_source.sh ]
Packit 857059
then
Packit 857059
	expand_source=$PWD/expand_source.sh
Packit 857059
#elif [ -e $TL_DIR/MakeTools/expand_source.sh ]
Packit 857059
#then
Packit 857059
#	expand_source=$TL_DIR/MakeTools/expand_source.sh
Packit 857059
else
Packit 857059
	expand_source=expand_source
Packit 857059
fi
Packit 857059
if ! type $expand_source
Packit 857059
then
Packit 857059
	exit 1
Packit 857059
fi
Packit 857059
Packit 857059
Usage()
Packit 857059
{
Packit 857059
	echo "Usage: expand_ofed [-d dest_dir] [-c compare_dir] ofed.tgz" >&2
Packit 857059
	echo "    -d - destination for expansion, default is ./SOURCE_TREE" >&2
Packit 857059
	echo "    -c - optional expanded ofed to compare to" >&2
Packit 857059
	echo "    ofed.tgz - ofed tgz to expand" >&2
Packit 857059
	exit 2
Packit 857059
}
Packit 857059
Packit 857059
# convert $1 to an absolute path
Packit 857059
fix_dir()
Packit 857059
{
Packit 857059
	local dir
Packit 857059
	if [ x$(echo $1|cut -c1) != x"/" ]
Packit 857059
	then
Packit 857059
		dir="$PWD/$1"
Packit 857059
	else
Packit 857059
		dir="$1"
Packit 857059
	fi
Packit 857059
	# drop trailing /
Packit 857059
	if [ "$dir" != "/" ]
Packit 857059
	then
Packit 857059
		echo "$dir"|sed -e 's|/*$||'
Packit 857059
	else
Packit 857059
		echo "$dir"
Packit 857059
	fi
Packit 857059
}
Packit 857059
Packit 857059
dest_dir=$PWD/SOURCE_TREE
Packit 857059
compare_dir=
Packit 857059
while getopts d:c: param
Packit 857059
do
Packit 857059
	case $param in
Packit 857059
	d)	dest_dir="$OPTARG";;
Packit 857059
	c)	compare_dir="$OPTARG";;
Packit 857059
	*)	Usage;;
Packit 857059
	esac
Packit 857059
done
Packit 857059
shift $(($OPTIND -1))
Packit 857059
if [ $# -ne 1 ]
Packit 857059
then
Packit 857059
	Usage
Packit 857059
fi
Packit 857059
ofed_tgz=$1
Packit 857059
Packit 857059
if [ ! -f $ofed_tgz ]
Packit 857059
then
Packit 857059
	echo "expand_ofed: Can't find: $ofed_tgz" >&2
Packit 857059
	exit 1
Packit 857059
fi
Packit 857059
dest_dir=$(fix_dir $dest_dir)
Packit 857059
ofed_tgz=$(fix_dir $ofed_tgz)
Packit 857059
Packit 857059
mkdir -p $dest_dir
Packit 857059
Packit 857059
# assume tarfile creates one dir
Packit 857059
ofed_dir=$(tar tfz $ofed_tgz|sed -e 's/\/.*//'|sort -u)
Packit 857059
if [ x"$ofed_dir" = x ]
Packit 857059
then
Packit 857059
	echo "expand_ofed: Can't figure out top dir of $ofed_tgz" >&2
Packit 857059
	exit 1
Packit 857059
fi
Packit 857059
Packit 857059
mkdir -p $tempdir
Packit 857059
tar xvfz $ofed_tgz -C $tempdir
Packit 857059
if [ $? -ne 0 -o ! -d $tempdir/$ofed_dir ]
Packit 857059
then
Packit 857059
	echo "expand_ofed: unable to untar $ofed_tgz" >&2
Packit 857059
	exit 1
Packit 857059
fi
Packit 857059
$expand_source -a -s $tempdir/$ofed_dir -d $dest_dir
Packit 857059
if [ $? -ne 0 ]
Packit 857059
then
Packit 857059
	echo "expand_ofed: expand_source failed" >&2
Packit 857059
	exit 1
Packit 857059
fi
Packit 857059
rm -rf $tempdir
Packit 857059
Packit 857059
if [ x"$compare_dir" != x ]
Packit 857059
then
Packit 857059
Packit 857059
	echo "Comparing $compare_dir and $dest_dir..."
Packit 857059
	compare_dir=$(fix_dir $compare_dir)
Packit 857059
	diff -r --exclude CVS $compare_dir $dest_dir > ./diffs
Packit 857059
Packit 857059
	# list of new files in drop relative to $compare_dir drop
Packit 857059
	grep "^Only in $dest_dir[:/]" < ./diffs|sed -e 's/^Only in //' -e 's/: /\//' -e "s|$dest_dir|.|" > ./added_files
Packit 857059
Packit 857059
	# list of files moved/removed in drop relative to $compare_dir drop
Packit 857059
	grep "^Only in $compare_dir[:/]" < ./diffs|grep -v ': CVS'|sed -e 's/^Only in //' -e 's/: /\//' -e "s|$compare_dir|.|" > ./removed_files
Packit 857059
Packit 857059
	# summary
Packit 857059
	echo "New files in this drop is in ./added_files: $(wc -l < ./added_files) files"
Packit 857059
	echo "Files removed in this drop is in ./removed_files: $(wc -l < ./removed_files) files"
Packit 857059
	echo "All diffs are in ./diffs: $(wc -l < ./diffs) lines"
Packit 857059
fi
Packit 857059
Packit 857059
exit 0