Dash:
[t2-trunk.git] / misc / target / functions.in
blob3b31679ef125b4181fb4becc47a350c59fcebf52
1 #!/bin/bash
2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by scripts/Create-CopyPatch.
4 #
5 # T2 SDE: misc/target/functions.in
6 # Copyright (C) 2004 - 2021 The T2 SDE Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # copy, with special files
17 # from to file-list
18 copy_with_list_from_file ()
20 ( cd $1 ; tar cSp --no-recursion --files-from=$3 ) |
21 ( cd $2 ; tar xvSP ) |
22 ( x=`wc -l` ; echo "$x files transfered." )
25 # copy out of T2 source without .svn files
26 # from to
27 copy_from_source ()
29 list=`mktemp`
30 # the sed is a work around for a find issue, outputting empty rows
31 # in some versions ...
32 find $1 -name '.svn' -prune -o -printf "%P\n" | sed '/^$/d' > $list
33 cat $list
34 copy_with_list_from_file $1 $2 $list
35 rm -f $list
39 # copy out of T2 source without .svn files and does honor special files to
40 # apply patches, change owner:group or permissions
41 # from to
42 copy_and_parse_from_source ()
44 # the sed is a work around for a find issue, outputting empty rows
45 # in some versions ...
46 find $1 -name '.svn' -prune -o -printf "%P\n" | sed '/^$/d' | sort |
47 while read file; do
49 if [ -h $1/$file ]; then
50 #echo "Symlink: $file"
51 cp -afv $1/$file $2/$file
52 elif [ -d $1/$file ]; then
53 #echo "Dir: $file"
54 mkdir -p $2/$file
55 else
56 cmd=`sed 2q $1/$file`
57 if [[ $cmd = \#\![a-y]* ]]; then
58 cmd=${cmd#\#\!};
59 code=${cmd%% *}
60 #echo "Code $code Command: $cmd File: $file"
61 args=`echo $cmd | wc -w`
62 dirname=${file%/*}
63 basename=${file##*/}
65 pushd $2/$dirname > /dev/null #; set -x
66 case $code in
67 ln|cp)
68 if [ $args -le 3 ]; then
69 eval $cmd $basename
70 else
71 eval $cmd
72 fi ;;
73 chmod|chown|rm)
74 if [ $args -le 2 ]; then
75 eval $cmd $basename
76 else
77 eval $cmd
78 fi ;;
79 patch) patch -f < $1/$file
81 *) echo "Code: $code unknown" ; exit 1 ;;
82 esac #; set +x ;
83 popd > /dev/null
84 elif [[ $cmd = \#\!* ]]; then
85 #echo Script $file
86 cp -afv $1/$file $2/$file
87 chmod +x $2/$file
88 else
89 #echo File $file
90 cp -afv $1/$file $2/$file
93 done
96 # link indentical files to save space
97 link_identical_files()
100 while read ck fn; do
101 if [ "$oldck" = "$ck" -a -s $fn ] ; then
102 echo "\"$fn -> $oldfn\""
103 rm $fn ; ln $oldfn $fn
104 else
105 oldck=$ck ; oldfn=$fn
107 done < <( find -type f | xargs md5sum | sort )
108 ) | ( x=`wc -l` ; echo "$x links created." )