duplicate_apps.sh 1.87 KB
Newer Older
Sylvain Thery's avatar
Sylvain Thery committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/bin/bash

if test $# -lt 2; then
	echo $0 application_directory_source application_directory_destination
	exit 2
fi

if test -d $2; then
	echo Directory $2 already exist
	exit 3
fi

if test ! -d $1; then
	echo Directory $1 does not exist
	exit 4
fi


echo "copying ..."
cp -r $1 $2
echo "cleanin ..."

cd $2
find . -name "CMakeFiles" -exec rm -rf {} \;  2> /dev/null
find . -name "cmake_install.cmake" -exec rm -f {} \; 2> /dev/null
find . -name "CMakeCache.txt" -exec rm -f {} \; 2> /dev/null
find . -name "Makefile" -exec rm -f {} \; 2> /dev/null
cd bin
rm -rf *
cd ..


app1=`basename $1`
app2=`basename $2`
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60



app1_maj=`echo $app1 | awk '
BEGIN { upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        lower = "abcdefghijklmnopqrstuvwxyz"
}
{
	FIRSTCHAR = substr($1, 1, 1)
	if (CHAR = index(lower, FIRSTCHAR))
		$1 = substr(upper, CHAR, 1) substr($1, 2)
	print $0
}' `


app2_maj=`echo $app2 | awk '
BEGIN { upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        lower = "abcdefghijklmnopqrstuvwxyz"
}
{
	FIRSTCHAR = substr($1, 1, 1)
	if (CHAR = index(lower, FIRSTCHAR))
		$1 = substr(upper, CHAR, 1) substr($1, 2)
	print $0
}' `

Sylvain Thery's avatar
Sylvain Thery committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
echo remplace $app1 by $app2 in CMakeLists.txt ...
find . -name "CMakeLists.txt" -exec sed -i s/$app1/$app2/g {} \;

echo "renaming files:"
list_of_files=`find . -name $app1\*`

for f in $list_of_files; do
	nf=`echo $f | sed s/$app1/$app2/`
	echo  "   "$f -\> $nf
	mv $f $nf
	# search into files for inclusion
	bf=`basename $f`
	bnf=`basename $nf`
	list2=`fgrep -wl $bf *`
#	if test -n """$list2"""; then
#		echo "    files to modify (includes)" $list2
		for xx in $list2; do
			sed -i s/$bf/$bnf/g $xx
		done
#	fi
done

echo Modify contents ...
84 85 86
find . -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -exec sed -i s/${app1_maj}/${app2_maj}/g {} \;
find . -name "*.cpp" -exec sed -i s/${app1_maj}/${app2_maj}/g {} \;
find . -name "*.h" -exec sed -i s/${app1_maj}/${app2_maj}/g {} \;
Sylvain Thery's avatar
Sylvain Thery committed
87 88 89 90

	
echo finished