annotate tools/patch-tool-mxe @ 2592:6748072ffec9

Patch tool: replace elifs with case. Also handles errors.
author Ryan Pavlik <rpavlik@iastate.edu>
date Mon, 07 May 2012 12:40:30 -0500
parents 18ccf1818b74
children 2f3353b7a313
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2358
14b3f5ea78ae Cleanup coding style via "make cleanup-style"
Volker Grabsch <vog@notjusthosting.com>
parents: 2353
diff changeset
1 #!/usr/bin/env bash
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
2
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
3 # Tool for converting between MXE patch files and git repos
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
4 # Imports and exports patch files in "git format-patch" format.
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
5
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
6 cmd=$1
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
7 pkg=$2
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
8
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
9 # MXE directory
2590
35e225e1b841 patch-tool: use relative directories
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2589
diff changeset
10 mxedir=$(cd $(dirname $0) && cd .. && pwd)
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
11
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
12 # directory for unpacked tarballs/git repos
2590
35e225e1b841 patch-tool: use relative directories
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2589
diff changeset
13 gitsdir=${mxedir}/gits
35e225e1b841 patch-tool: use relative directories
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2589
diff changeset
14
2591
18ccf1818b74 patch tool: Ensure the gits directory exists
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2590
diff changeset
15 mkdir -p ${gitsdir}
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
16
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
17
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
18 # John Doe <John Doe@acme.org>
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
19 author=`git var GIT_AUTHOR_IDENT | sed 's/^\(.* [<].*[>]\).*$/\1/'`
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
20
2589
0f4ffb24a0ec patch tool: fix so it gets the version from index.html now
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2358
diff changeset
21 pkg_version=$(sed -n "s/^.* id=\"${pkg}-version\">\([^<]*\)<.*$/\1/p" "${mxedir}/index.html")
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
22
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
23 pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/`
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
24
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
25 pkg_subdir=`grep '^$(PKG)_SUBDIR' $mxedir/src/$pkg.mk | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
26 sed 's/.*:= \(.*\)/\1/' | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
27 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
28 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
29 sed s/'$(PKG)'/$pkg/;`
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
30
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
31 pkg_file=`grep '^$(PKG)_FILE' $mxedir/src/$pkg.mk | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
32 sed 's/.*:= \(.*\)/\1/' | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
33 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
34 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
35 sed s/'$($(PKG)_SUBDIR)'/$pkg_subdir/ | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
36 sed s/'$(PKG)'/$pkg/;`
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
37
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
38 #echo $pkg
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
39 #echo $pkg_version
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
40 #echo $pkg_subdir
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
41 #echo $pkg_file
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
42
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
43 # init
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
44 function init_git {
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
45 cd $gitsdir
2334
0ac3f45e790f Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents: 2333
diff changeset
46 echo $pkg_file | grep "\.tar\.gz" >> /dev/null && tar xf $mxedir/pkg/$pkg_file
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
47 echo $pkg_file | grep "\.tar\.bz2" >> /dev/null && tar xf $mxedir/pkg/$pkg_file
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
48 echo $pkg_file | grep "\.tar\.xz" >> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf -
2334
0ac3f45e790f Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents: 2333
diff changeset
49 echo $pkg_file | grep "\.zip" >> /dev/null && unzip $mxedir/pkg/$pkg_file >> /dev/null
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
50 cd $gitsdir/$pkg_subdir && \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
51 (git init; git add -A; git commit -m "init") > /dev/null
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
52 git tag dist
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
53 }
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
54
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
55 function export_patch {
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
56 cd $gitsdir/$pkg_subdir && \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
57 (
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
58 echo 'This file is part of MXE.'
2353
99516e73b368 Move doc/index.html -> index.html
Volker Grabsch <vog@notjusthosting.com>
parents: 2334
diff changeset
59 echo 'See index.html for further information.'
2333
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
60 echo ''
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
61 echo 'Contains ad hoc patches for cross building.'
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
62 echo ''
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
63 git format-patch -p --stdout dist..HEAD | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
64 sed 's/^From: .*/From: MXE/g;'
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
65 ) > $mxedir/src/$pkg-1-fixes.patch
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
66 }
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
67
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
68 function import_patch {
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
69 cd $gitsdir/$pkg_subdir && \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
70 cat $mxedir/src/$pkg-1-fixes.patch | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
71 sed '/^From/,$ !d' | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
72 sed s/'^From: .*'/"From: $author"/'g;' | \
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
73 git am --keep-cr
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
74 }
f653602a0500 Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff changeset
75
2592
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
76 case "$cmd" in
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
77 init)
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
78 init_git $pkg
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
79 ;;
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
80 import)
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
81 import_patch $pkg
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
82 ;;
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
83 export)
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
84 export_patch $pkg
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
85 ;;
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
86 *)
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
87 echo "Unrecognized command '${cmd}'" >&2
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
88 cat <<EOS
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
89 Usage: $0 COMMAND PACKAGENAME
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
90 where COMMAND is one of:
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
91 init - create a git directory for the package with the raw source
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
92 import - apply the "pkgname-1-fixes.patch" patch commits
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
93 export - create/replace the "pkgname-1-fixes.patch" patch with a patch of all commits since init.
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
94 EOS
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
95 exit 1
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
96 ;;
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
97 esac
6748072ffec9 Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents: 2591
diff changeset
98