Andreas Krennmair:
[apps/madmutt.git] / contrib / muttng-rpmbuild.sh
1 #!/bin/sh
2 #
3 # ABSOLUTELY NO WARRANTY WITH THIS PACKAGE. USE IT AT YOUR OWN RISK.
4 #
5 # Download, re-config & build latest mutt-ng tarball as RPM & SRPM files
6 #
7 # Usage: muttng-rpmbuild.sh
8 #
9 # Copyright (C) 2005  muttng-rpmbuild.sh 1.10  Iain Lea  iain@bricbrac.de
10 #
11 #   This program is free software; you can redistribute it and/or 
12 #   modify it under the terms of the GNU General Public License as
13 #   published by the Free Software Foundation; either version 2 of
14 #   the License, or (at your option) any later version.
15
16 #   This program is distributed in the hope that it will be useful, 
17 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
18 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
19 #   See the GNU General Public License for more details.
20
21 #   You should have received a copy of the GNU GPL along with this
22 #   program; if not, write to the Free Software Foundation, Inc.,
23 #   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24 #
25 # Requirements:
26 #   ...
27 #
28 # Contributors:
29 #   ...
30 #
31 # Changelog:
32 #   1.10
33 #   - added cosmetic changes concerning sent mail
34 #   - added rm -rf $SRCDIR/muttng-*  and more cleanup on exit
35 #   1.00
36 #   - initial release
37 #
38 # Todo:
39 #   - add section of Changelog/SVN to sent mail if successful
40
41 # Local site specific variables. Change to suit your site!
42 ADDR=root
43 MAIL=mutt
44 ARCH=i386
45 TMPDIR=/tmp
46 DSTDIR=/var/www/iainlea.dyndns.org/software/muttng
47 BLDDIR=/usr/src/redhat
48 #
49 # Remote site specific variables. Should not need changing!
50 SITE=http://mutt-ng.berlios.de/snapshots
51 FILE=muttng-latest.tar.gz
52 #
53 # You should not need to change anything below this line!
54 SRCDIR=$BLDDIR/SOURCES
55 RPMSDIR=$BLDDIR/RPMS/$ARCH
56 SRPMDIR=$BLDDIR/SRPMS
57 SPEC=muttng.spec
58
59 # Sanity checks
60 if [ ! -d $TMPDIR ]; then
61         echo "Error: \$TMPDIR $TMPDIR - does not exist. Edit to match your site!"
62         exit 0
63 fi
64 if [ ! -d $DSTDIR ]; then
65         echo "Error: \$DSTDIR $DSTDIR - does not exist. Edit to match your site!"
66         exit 0
67 fi
68 if [ ! -d $SRCDIR ]; then
69         echo "Error: \$SRCDIR $SRCDIR - does not exist. Edit to match your site!"
70         exit 0
71 fi
72 if [ ! -d $RPMSDIR ]; then
73         echo "Error: \$RPMSDIR $RPMSDIR - does not exist. Edit to match your site!"
74         exit 0
75 fi
76 if [ ! -d $SRPMDIR ]; then
77         echo "Error: \$SRPMDIR $SRPMDIR - does not exist. Edit to match your site!"
78         exit 0
79 fi
80
81 cd $TMPDIR
82
83 echo "Backup:  $TMPDIR/$SPEC"
84 /bin/mv -f $TMPDIR/$SPEC $TMPDIR/$SPEC.bak >/dev/null 2>&1
85 /bin/rm -f $TMPDIR/$SPEC.in >/dev/null 2>&1
86
87 echo "Delete:  $TMPDIR/$FILE"
88 /bin/rm -f $TMPDIR/$FILE >/dev/null 2>&1
89
90 echo "Delete:  $TMPDIR/muttng-*/"
91 (find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
92
93 echo "Delete:  $SRCDIR/muttng-*.tar.gz"
94 (find $SRCDIR/muttng-*tar.gz -print | sort -r | xargs /bin/rm -f) >/dev/null 2>&1
95
96 echo "Delete:  $SRCDIR/muttng-*/"
97 # find $SRCDIR/muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf >/dev/null 2>&1
98 (cd $SRCDIR; find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
99
100 echo "FetchIt  $SITE/$FILE"
101 wget -O $FILE $SITE/$FILE >/dev/null 2>&1
102
103 echo "Extract  $FILE"
104 tar xzf $FILE
105
106 NAME=`find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | head -1`
107 echo "TarBall  $NAME"
108
109 VER=`echo $NAME | cut -d '-' -f2`
110 # echo "Version  $VER"
111
112 echo "Parsing  $NAME/contrib/$SPEC"
113 cp $NAME/contrib/$SPEC $SPEC.in
114 sed -e "s/^Version:.*$/Version: $VER/" < $SPEC.in > $SPEC
115 REL=`egrep "Release: " $SPEC | cut -d ' ' -f2`
116 egrep "Version: " $SPEC
117 egrep "Release: " $SPEC
118
119 echo "BuildIt  $SRCDIR/$NAME.tar.gz"
120 mv $FILE $SRCDIR/$NAME.tar.gz
121 # sleep 3
122 rpmbuild -ba $SPEC >$TMPDIR/$NAME.rpmbuild 2>&1
123
124 # echo "CheckIt  $RPMSDIR/muttng-$VER-$REL.i386.rpm"
125 if [ -e $RPMSDIR/muttng-$VER-$REL.i386.rpm ]
126 then
127         echo "BuiltOK  $RPMSDIR/muttng-$VER-$REL.i386.rpm"
128         cp $RPMSDIR/muttng-$VER-$REL.i386.rpm $DSTDIR
129         echo "$DSTDIR/muttng-$VER-$REL.i386.rpm" > $TMPDIR/$NAME.rpmbuild
130
131 #       echo "CheckIt  $SRPMDIR/muttng-$VER-$REL.src.rpm"
132         if [ -e $SRPMDIR/muttng-$VER-$REL.src.rpm ]
133         then
134                 echo "BuiltOK  $SRPMDIR/muttng-$VER-$REL.src.rpm"
135                 cp $SRPMDIR/muttng-$VER-$REL.src.rpm $DSTDIR
136                 echo "$DSTDIR/muttng-$VER-$REL.src.rpm" >> $TMPDIR/$NAME.rpmbuild
137         fi
138         
139         cp $SPEC $DSTDIR
140
141         echo "Mailing  $ADDR - BUILT"
142         echo >> $TMPDIR/$NAME.rpmbuild
143         head -15 $TMPDIR/$NAME/ChangeLog.mutt-ng >> $TMPDIR/$NAME.rpmbuild
144         echo "..." >> $TMPDIR/$NAME.rpmbuild
145         $MAIL -s "Mutt-NG: BUILT - $NAME" $ADDR < $TMPDIR/$NAME.rpmbuild
146 else
147         echo "Mailing  $ADDR - ERROR"
148         $MAIL -s "Mutt-NG: ERROR - $NAME" $ADDR < $TMPDIR/$NAME.rpmbuild
149 fi
150
151 # echo "Cleanup  $TMPDIR/muttng-*/ $TMPDIR/$NAME.rpmbuild"
152 /bin/rm -f $TMPDIR/$NAME.rpmbuild
153 (cd $TMPDIR; find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
154
155 exit 1