scripting: add zone support
[profile/ivi/pulseaudio-module-murphy-ivi.git] / obs-export.sh
1 #!/bin/bash
2
3 # This needs a bit more work, mostly on the "discplined engineering" front.
4 # IOW, instead of this UPSTREAM_BASE hack it would be better to have 3
5 # branches:
6 #   1) pristine upstream: for tracking upstream progress/retrogression
7 #   2) patched upstream: pristine upstream with outr patches applied
8 #   3) working local: patches upstream + a set of scripts (like this) to
9 #      do everyday stuff like making new releases, exporting stuff to
10 #      OBS, etc...
11
12
13 PKG="$(basename `pwd`)"
14 UPSTREAM_BASE="upstream"
15 VERSION="`date +'%Y%m%d'`"
16 HEAD="HEAD"
17 MODE=gerrit
18 RELEASE=no
19 AUTHOR="Policy Team <policy.team@intel.com>"
20
21 while [ "${1#-}" != "$1" -a -n "$1" ]; do
22     case $1 in
23         --name|-n)
24             PKG="$2"
25             shift 2
26             ;;
27         --version|-v)
28             VERSION="$2"
29             shift 2
30             ;;
31         --base|-B|-b)
32             UPSTREAM_BASE="$2"
33             shift 2
34             ;;
35         --head|-H)
36             HEAD="$2"
37             shift 2
38           ;;
39         --obs|-o)
40             MODE="obs"
41             shift 1
42           ;;
43         --help|-h)
44            echo "usage: $0 [options], where the possible options are"
45            echo "  -n <name>           name of your package"
46            echo "  -v <version>        version to in rpm/SPEC file"
47            echo "  -B <upstream-base>  name or SHA1 of baseline"
48            echo "  -H <taget-head>     name or SHA1 of release HEAD"
49            echo "  --obs               include tarball for OBS"
50            echo ""
51            echo "<name> is the name of the package, <version> is the version"
52            echo "you want to export to OBS, and <upstream-base> is the name of"
53            echo "the upstream git branch or the SHA1 you want to generate your"
54            echo "release from and base your patches on top of. On OBS mode the"
55            echo "output will be generated in a directory called obs-$VERSION."
56            echo "Otherwise in gerrit mode, the output will be generated in a"
57            echo "directory called packaging."
58            echo ""
59            echo "E.g.:"
60            echo "  $0 -n pulseaudio -v 2.0 -B pulseaudio-2.0 -H tizen"
61            echo ""
62            echo "This will produce a gerrit export with version 2.0 against the"
63            echo "SHA1 pulseaudio-2.0, producing patches up till tizen and"
64            echo "place the result in a directory called packaging."
65            exit 0
66            ;;
67         --debug|-d)
68            set -x
69            ;;
70         --big-hammer|--release|-r)
71            RELEASE=yes
72            shift 1
73            ;;
74         --author|-a)
75            AUTHOR="$2"
76            shift 2
77            ;;
78         *) echo "usage: $0 [-n <name>][-v <version>][--obs]"
79            echo "          [-b <upstream-base>] [-H <head>"
80            exit 1
81            ;;
82     esac
83 done
84
85 case $MODE in
86     gerrit)
87         TARBALL=""
88         DIR=packaging
89         ;;
90     obs)
91         TARBALL=$PKG-$VERSION.tar
92         DIR="obs-$VERSION"
93         ;;
94     *)
95         echo "invalid mode: $MODE"
96         exit 1
97         ;;
98 esac
99
100 echo "Package name: $PKG"
101 echo "Package version: $VERSION"
102 echo "Package baseline: $UPSTREAM_BASE"
103 echo "Package head: $HEAD"
104 echo "Output directory: $DIR"
105
106 rm -fr $DIR
107 mkdir $DIR
108
109 if [ -n "$TARBALL" ]; then
110     echo "Generating tarball..."
111         git archive --format=tar --prefix=$PKG-$VERSION/ $UPSTREAM_BASE \
112             > $DIR/$TARBALL && \
113         gzip $DIR/$TARBALL
114 fi
115
116 echo "Generating patches, creating spec file..."
117 cd $DIR && \
118     git format-patch -n $UPSTREAM_BASE..$HEAD && \
119     cat ../$PKG.spec.in | sed "s/@VERSION@/$VERSION/g" > $PKG.spec.in && \
120 cd - >& /dev/null
121
122 cd $DIR
123 patchlist="`ls *.patch`"
124 cat $PKG.spec.in | while read -r line; do
125     case $line in
126         @DECLARE_PATCHES@)
127             i=0
128             for patch in $patchlist; do
129                 echo "Patch$i: $patch"
130                 let i=$i+1
131             done
132             ;;
133         @APPLY_PATCHES@)
134             i=0
135             for patch in $patchlist; do
136                 echo "%patch$i -p1"
137                 let i=$i+1
138             done
139             ;;
140         *)
141             echo "$line"
142             ;;
143     esac
144 done > $PKG.spec
145 cd - >& /dev/null
146
147 rm -f $DIR/$PKG.spec.in
148
149 if [ "$MODE" = "gerrit" -a "$RELEASE" = "yes" ]; then
150     stamp="$(date -u +%Y%m%d.%H%M%S)"
151     branch="gerrit-release-$stamp"
152     tag="submit/trunk/$stamp"
153     chlog=packaging/$PKG.changes
154
155     echo "Preparing release branch $branch with tag $tag..."
156
157     git branch $branch $UPSTREAM_BASE && \
158         git checkout $branch && \
159         git add packaging && \
160         git commit -m "release: added packaging for gerrit." packaging && \
161         echo "* $(date '+%a %b %d %H:%M:%S %Z %Y') $AUTHOR - $VERSION" \
162             > $chlog && \
163         echo "- release: releasing $VERSION..." >> $chlog && \
164             git add $chlog &&
165         echo "" && \
166         echo "Okay, branch $branch is prepared for release." && \
167         echo "To proceed with the release, please" && \
168         echo "" && \
169         echo "  1) vi $chlog (and add a real changelog entry)" && \
170         echo "  2) git commit -m \"release: updated changelog.\" $chlog" && \
171         echo "  3) git tag -a -m \"release: tagged release.\" $tag HEAD" && \
172         echo "  4) git push --force tzgerrit HEAD^:refs/heads/master" && \
173         echo "  5) git push tzgerrit HEAD:refs/for/master $tag"
174
175     if [ "$?" = "0" ]; then
176         echo "Done."
177     else
178         echo "Failed to prepare release..."
179         git branch -D $branch
180         exit 1
181     fi
182 fi