Window placement fix
[wmaker-crm.git] / mkpatch
blobbd87294b22b8450d6865afd763c762d3badc0823
1 #!/bin/sh
3 # mkpatch 1.1
5 # Creates a more-or-less self-contained patch package.
7 # Copyright (c) Alfredo K. Kojima
10 # Syntax: mkpatch old_tree new_tree patch_name
12 # If a file named mkp.stuff is found in the current directory, it
13 # will be used to extract special handling cases. Each directive must
14 # be placed in a line of the file and the arguments must be separated
15 # by a single space. The currently supported directives are:
17 # DONTDIFF <file_path>
18 # Do not use diff in the specified file, replacing the file instead.
19 # The path must exclude the top directory and the path must be
20 # valid from both trees.
21 # It will handle special cases of files that diff thinks are text
22 # files, but actually are not, like XPM files created by stupid,
23 # brain damaged, moron XV.
25 # Example mkp.stuff file:
26 # DONTDIFF icons/somthing.xpm
27 # DONTDIFF icons/smthingelse.xpm
30 # The resulting patch pack will be relatively big (if compared to things
31 # produced by xdelta and others), but it will be self-contained and
32 # hopefully smaller than the whole source tree.
34 # You MUST run mkpatch from a directory above old_tree and new_tree.
35 # Example:
36 # If newTree and oldTree are located in /tmp
37 # cd /tmp
38 # mkpatch oldTree newTree old_to_new
40 # File names cannot contain the character # or spaces
44 if test ! $# = 3 ; then
45 echo "$0:read the script for the syntax."
46 exit 1
51 istext() {
52 a=`file $1|grep text`
53 if test "x$a" = "x"; then
54 return 0
55 else
56 return 1
61 put_header() {
62 cat << 'EOF' |sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
63 -e "s#NTREE#$NTREE#" > $1
64 #!/bin/sh
66 # Patch package to upgrade OTREE to NTREE
68 EOF
69 if [ $# -gt 1 ]; then
70 echo $2 >> $1
72 echo "unalias rm" >> $1
76 ##########################
78 check_removed_files() {
80 files=`grep "Only in $OTREE" $TMP/tdiff|sed -e "s#Only in $OTREE##" -e "s#: #/#" -e "s#//#/#"`
82 put_header $TMP/delfiles "# Remove obsolete files"
83 #..................
84 cat << EOF >> $TMP/delfiles
85 echo "Files that are not needed anymore will be removed now."
86 echo "Do you wish to proceed? <y/n> [y]"
87 read foo
88 if [ "$foo" = "n" ]; then
89 exit 0
92 EOF
93 #...................
95 echo "Obsoleted Files:"
96 for i in $files; do
97 echo $OTREE/$i
98 echo "echo \"Removing ../$i\"" >> $TMP/delfiles
99 if [ -d $OTREE/$i ]; then
100 echo "rm -rf ../$i" >> $TMP/delfiles
101 else
102 echo "rm ../$i" >> $TMP/delfiles
104 done
106 chmod +x $TMP/delfiles
110 #########################
112 check_new_files() {
113 files=`grep "Only in $NTREE" $TMP/tdiff|sed -e "s#Only in $NTREE#../#" -e "s#: #/#" -e "s#//#/#"`
115 put_header $TMP/newfiles "# Copy new files"
116 echo "# Table of internal file names to real file names" >> $TMP/newfiles
118 index=0
119 dindex=0
120 mkdir $TMP/files
121 echo "New Files:"
122 for i in $files; do
123 name=`basename $i`
124 src=`echo $i|sed -e "s#..#$NTREE#"`
125 file=`echo $i|sed -e "s#../##"`
126 echo $src
127 if [ -d $src ]; then
128 dst="dir$dindex"
130 (dir=`pwd`;cd $NTREE;tar cf $dir/$TMP/files/$dst.tar $file)
132 echo "$dst=\"$file\"" >> $TMP/newfiles
133 dindex=`expr $dindex + 1`
134 else
135 dst="file$index"
136 cp $src $TMP/files/$dst
137 echo "$dst=\"$file\"" >> $TMP/newfiles
138 index=`expr $index + 1`
140 done
141 echo "filecount=$index" >> $TMP/newfiles
142 echo "dircount=$dindex" >> $TMP/newfiles
143 #..........
144 cat << 'EOF' |sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
145 -e "s#NTREE#$NTREE#" >> $TMP/newfiles
148 #create new directories
149 index=0
150 mkdir tmpdir
151 while [ $index -lt $dircount ]; do
152 fname="dir$index"
153 eval origname=\$"$fname"
154 echo "Recreating directory ../$origname"
155 (cd tmpdir; tar xf ../files/$fname.tar)
156 mv tmpdir/$origname ../$origname
157 index=`expr $index + 1`
158 done
159 rm -fr tmpdir
161 #copy files
162 index=0
163 while [ $index -lt $filecount ]; do
164 fname="file$index"
165 eval origname=\$"$fname"
166 echo "Copying file ../$origname"
167 cp files/$fname ../$origname
168 index=`expr $index + 1`
169 done
172 #..........
174 chmod +x $TMP/newfiles
177 #####################
179 check_binary_changes() {
180 files=`grep "Binary files" $TMP/bindiff|cut -d\ -f5`
181 files=`echo $files`
183 put_header $TMP/updbinfiles "# Replace changed binary files"
184 echo "# Table of internal file names to real file names" >> $TMP/updbinfiles
186 for i in $no_diff; do
187 files="$files $NTREE/$i"
188 done
189 index=0
190 echo "Binary files changed:"
191 for i in $files; do
192 fname="changed$index"
193 oname=`echo $i|sed -e "s#$NTREE##" -e "s#^/##"`
194 cp $i $TMP/files/$fname
195 echo $i
196 echo "$fname=\"$oname\"" >> $TMP/updbinfiles
197 index=`expr $index + 1`
198 done
199 echo "filecount=$index" >> $TMP/updbinfiles
201 #..........
202 cat << 'EOF' |sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
203 -e "s#NTREE#$NTREE#" >> $TMP/updbinfiles
205 index=0
206 while [ $index -lt $filecount ]; do
207 fname="changed$index"
208 eval origname=\$"$fname"
209 echo "Replacing file ../$origname"
210 rm ../$origname
211 cp files/$fname ../$origname
212 index=`expr $index + 1`
213 done
216 #..........
217 chmod +x $TMP/updbinfiles
221 #####################
222 check_text_changes() {
223 echo "diff'ing trees..."
224 diff -rq $OTREE $NTREE > $TMP/tdiff
225 tmp=`egrep "^Files" $TMP/tdiff|cut -d\ -f2|sed -e "s#$OTREE/##"`
227 files=""
228 # remove excluded files
229 for i in $tmp; do
230 ok=1
231 for j in $no_diff; do
232 if test "$i" = "$j"; then
233 ok=0
234 break
236 done
237 if [ $ok = 1 ]; then
238 files="$files $i"
240 done
242 touch $TMP/diff
243 touch $TMP/bindiff
244 # diff remaining files
245 for f in $files; do
246 diff -rc $OTREE/$f $NTREE/$f >> $TMP/tmp
247 foo=`egrep "^Binary" $TMP/tmp`
248 if test "x$foo" = "x"; then
249 cat $TMP/tmp >> $TMP/diff
250 else
251 cat $TMP/tmp >> $TMP/bindiff
253 rm -fr $TMP/tmp
254 done
257 ################# main
259 stripslash() {
260 echo $1|sed -e 's#/$##'
263 OTREE=`stripslash $1`
264 NTREE=`stripslash $2`
265 OUTPUT=$3
267 TMP=$OUTPUT.patchd
269 rm -fr $TMP
270 mkdir $TMP
273 if [ -f mkp.stuff ]; then
274 echo "Using mkp.stuff file..."
276 no_diff=`grep DONTDIFF mkp.stuff|cut -d\ -f2`
277 no_diff=`echo $no_diff`
282 #....................
283 cat << 'EOF' |sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#" -e "s#NTREE#$NTREE#" \
284 > $TMP/runme
285 #!/bin/sh
287 # Patch package to upgrade OTREE to NTREE
289 # Automatically generated by mkpatch
291 # Move the TMP directory to inside NTREE
292 # and run this script.
295 TARGET_TREE=OTREE
297 savedir=`pwd`
298 cd ..
299 dir=`pwd`
300 dir=`basename $dir`
301 cd $savedir
303 if test "$USER" = root; then
304 echo "Do not run this script as the root user"
305 exit 1
308 if test "$dir" != "$TARGET_TREE"; then
309 echo "You must move the \"TMP\" directory to inside the "
310 echo "\"$TARGET_TREE\" directory before running this script."
311 exit 1
314 echo "################################"
315 echo "Removing Obsolete Files"
316 echo "################################"
317 ./delfiles
318 echo
319 echo "################################"
320 echo "Copying New Files"
321 echo "################################"
322 ./newfiles
323 echo
324 echo "################################"
325 echo "Replacing modified binary files"
326 echo "################################"
327 ./updbinfiles
328 echo
329 echo "################################"
330 echo "Patching modified text files"
331 echo "################################"
332 cd ..
333 patch -p1 -s < $savedir/diff
335 echo "Patching finished."
338 #....................
339 cat << 'EOF' |sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#" -e "s#NTREE#$NTREE#" \
340 > $TMP/README
342 This patch package will upgrade OTREE to NTREE.
343 You must unpack it inside the OTREE directory or it will not work.
344 This patch can only be applied over a clean OTREE distribution.
345 To apply, just type (followed by a Return, of course):
346 ./runme
349 #....................
351 #....................
352 cat << 'EOF' > $TMP/cleanup
353 #!/bin/sh
355 # Remove .orig files
357 find .. -name \*.orig -exec rm {} \;
359 chmod +x $TMP/cleanup
360 #....................
363 # this must be the first function called
364 check_text_changes
366 check_removed_files
368 check_new_files
370 check_binary_changes
372 rm -f $TMP/tdiff
373 rm -f $TMP/bindiff
375 chmod +x $TMP/runme
377 echo "Do you want to add something to the README file? <y/n> [n]"
378 read foo
379 if [ "$foo" = "y" ]; then
380 vi $TMP/README
383 rm -f $OUTPUT.tar.gz
385 tar czf $OUTPUT.tar.gz $TMP
387 rm -fr $TMP
389 echo "Patch pack $OUTPUT.tar.gz successfully created."