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.
36 # If newTree and oldTree are located in /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."
53 if test "x$a" = "x"; then
62 cat << 'EOF' |
sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
63 -e "s#NTREE#$NTREE#" > $1
66 # Patch package to upgrade OTREE to NTREE
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"
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]"
88 if [ "$foo" = "n" ]; then
95 echo "Obsoleted Files:"
98 echo "echo \"Removing ../$i\"" >> $TMP/delfiles
99 if [ -d $OTREE/$i ]; then
100 echo "rm -rf ../$i" >> $TMP/delfiles
102 echo "rm ../$i" >> $TMP/delfiles
106 chmod +x
$TMP/delfiles
110 #########################
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
124 src
=`echo $i|sed -e "s#..#$NTREE#"`
125 file=`echo $i|sed -e "s#../##"`
130 (dir
=`pwd`;cd $NTREE;tar cf
$dir/$TMP/files
/$dst.
tar $file)
132 echo "$dst=\"$file\"" >> $TMP/newfiles
133 dindex
=`expr $dindex + 1`
136 cp $src $TMP/files
/$dst
137 echo "$dst=\"$file\"" >> $TMP/newfiles
138 index
=`expr $index + 1`
141 echo "filecount=$index" >> $TMP/newfiles
142 echo "dircount=$dindex" >> $TMP/newfiles
144 cat << 'EOF' |
sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
145 -e "s#NTREE#$NTREE#" >> $TMP/newfiles
148 #create new directories
151 while [ $index -lt $dircount ]; do
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`
163 while [ $index -lt $filecount ]; do
165 eval origname
=\$
"$fname"
166 echo "Copying file ../$origname"
167 cp files
/$fname ..
/$origname
168 index
=`expr $index + 1`
174 chmod +x
$TMP/newfiles
177 #####################
179 check_binary_changes
() {
180 files
=`grep "Binary files" $TMP/bindiff|cut -d\ -f5`
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"
190 echo "Binary files changed:"
192 fname
="changed$index"
193 oname
=`echo $i|sed -e "s#$NTREE##" -e "s#^/##"`
194 cp $i $TMP/files
/$fname
196 echo "$fname=\"$oname\"" >> $TMP/updbinfiles
197 index
=`expr $index + 1`
199 echo "filecount=$index" >> $TMP/updbinfiles
202 cat << 'EOF' |
sed -e "s#TMP#$TMP#" -e "s#OTREE#$OTREE#"\
203 -e "s#NTREE#$NTREE#" >> $TMP/updbinfiles
206 while [ $index -lt $filecount ]; do
207 fname
="changed$index"
208 eval origname
=\$
"$fname"
209 echo "Replacing file ../$origname"
211 cp files
/$fname ..
/$origname
212 index
=`expr $index + 1`
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/##"`
228 # remove excluded files
231 for j
in $no_diff; do
232 if test "$i" = "$j"; then
244 # diff remaining files
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
251 cat $TMP/tmp
>> $TMP/bindiff
257 ################# main
260 echo $1|
sed -e 's#/$##'
263 OTREE
=`stripslash $1`
264 NTREE
=`stripslash $2`
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#" \
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.
303 if test "$USER" = root
; then
304 echo "Do not run this script as the root user"
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."
314 echo "################################"
315 echo "Removing Obsolete Files"
316 echo "################################"
319 echo "################################"
320 echo "Copying New Files"
321 echo "################################"
324 echo "################################"
325 echo "Replacing modified binary files"
326 echo "################################"
329 echo "################################"
330 echo "Patching modified text files"
331 echo "################################"
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#" \
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
):
349 #....................
351 #....................
352 cat << 'EOF' > $TMP/cleanup
357 find ..
-name \
*.orig
-exec rm {} \
;
359 chmod +x
$TMP/cleanup
360 #....................
363 # this must be the first function called
377 echo "Do you want to add something to the README file? <y/n> [n]"
379 if [ "$foo" = "y" ]; then
385 tar czf
$OUTPUT.
tar.gz
$TMP
389 echo "Patch pack $OUTPUT.tar.gz successfully created."