Use good m_ functions, because it smell like a flower, version 2.
[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.20  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.20
33 #   - changed website to download from to www.muttng.org
34 #   1.10
35 #   - added cosmetic changes concerning sent mail
36 #   - added rm -rf $SRCDIR/muttng-*  and more cleanup on exit
37 #   1.00
38 #   - initial release
39 #
40 # Todo:
41 #   - add section of Changelog/SVN to sent mail if successful
42
43 # Local site specific variables. Change to suit your site!
44 ADDR=iain@bricbrac.de
45 MAIL=mutt
46 ARCH=i386
47 TMPDIR=/tmp
48 DSTDIR=/var/www/iainlea.dyndns.org/software/muttng
49 BLDDIR=/usr/src/redhat
50 #
51 # Remote site specific variables. Should not need changing!
52 SITE=http://nion.modprobe.de/mutt-ng/snapshots/
53 FILE=muttng-latest.tar.gz
54 #
55 # You should not need to change anything below this line!
56 SRCDIR=$BLDDIR/SOURCES
57 RPMSDIR=$BLDDIR/RPMS/$ARCH
58 SRPMDIR=$BLDDIR/SRPMS
59 SPEC=muttng.spec
60
61 # Sanity checks
62 if [ ! -d $TMPDIR ]; then
63         echo "Error: \$TMPDIR $TMPDIR - does not exist. Edit to match your site!"
64         exit 0
65 fi
66 if [ ! -d $DSTDIR ]; then
67         echo "Error: \$DSTDIR $DSTDIR - does not exist. Edit to match your site!"
68         exit 0
69 fi
70 if [ ! -d $SRCDIR ]; then
71         echo "Error: \$SRCDIR $SRCDIR - does not exist. Edit to match your site!"
72         exit 0
73 fi
74 if [ ! -d $RPMSDIR ]; then
75         echo "Error: \$RPMSDIR $RPMSDIR - does not exist. Edit to match your site!"
76         exit 0
77 fi
78 if [ ! -d $SRPMDIR ]; then
79         echo "Error: \$SRPMDIR $SRPMDIR - does not exist. Edit to match your site!"
80         exit 0
81 fi
82
83 cd $TMPDIR
84
85 echo "Backup:  $TMPDIR/$SPEC"
86 /bin/mv -f $TMPDIR/$SPEC $TMPDIR/$SPEC.bak >/dev/null 2>&1
87 /bin/rm -f $TMPDIR/$SPEC.in >/dev/null 2>&1
88
89 echo "Delete:  $TMPDIR/$FILE"
90 /bin/rm -f $TMPDIR/$FILE >/dev/null 2>&1
91
92 echo "Delete:  $TMPDIR/muttng-*/"
93 (find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
94
95 echo "Delete:  $SRCDIR/muttng-*.tar.gz"
96 (find $SRCDIR/muttng-*tar.gz -print | sort -r | xargs /bin/rm -f) >/dev/null 2>&1
97
98 echo "Delete:  $SRCDIR/muttng-*/"
99 # find $SRCDIR/muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf >/dev/null 2>&1
100 (cd $SRCDIR; find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
101
102 echo "FetchIt  $SITE/$FILE"
103 wget -O $FILE $SITE/$FILE >/dev/null 2>&1
104
105 echo "Extract  $FILE"
106 tar xzf $FILE
107
108 NAME=`find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | head -1`
109 echo "TarBall  $NAME"
110
111 VER=`echo $NAME | cut -d '-' -f2`
112 # echo "Version  $VER"
113
114 echo "Parsing  $NAME/contrib/$SPEC"
115 cp $NAME/contrib/$SPEC $SPEC.in
116 sed -e "s/^Version:.*$/Version: $VER/" < $SPEC.in > $SPEC
117 REL=`egrep "Release: " $SPEC | cut -d ' ' -f2`
118 egrep "Version: " $SPEC
119 egrep "Release: " $SPEC
120
121 echo "BuildIt  $SRCDIR/$NAME.tar.gz"
122 mv $FILE $SRCDIR/$NAME.tar.gz
123 # sleep 3
124 rpmbuild -ba $SPEC >$TMPDIR/$NAME.rpmbuild 2>&1
125
126 # echo "CheckIt  $RPMSDIR/muttng-$VER-$REL.i386.rpm"
127 if [ -e $RPMSDIR/muttng-$VER-$REL.i386.rpm ]
128 then
129         echo "BuiltOK  $RPMSDIR/muttng-$VER-$REL.i386.rpm"
130         cp $RPMSDIR/muttng-$VER-$REL.i386.rpm $DSTDIR
131         echo "$DSTDIR/muttng-$VER-$REL.i386.rpm" > $TMPDIR/$NAME.rpmbuild
132
133 #       echo "CheckIt  $SRPMDIR/muttng-$VER-$REL.src.rpm"
134         if [ -e $SRPMDIR/muttng-$VER-$REL.src.rpm ]
135         then
136                 echo "BuiltOK  $SRPMDIR/muttng-$VER-$REL.src.rpm"
137                 cp $SRPMDIR/muttng-$VER-$REL.src.rpm $DSTDIR
138                 echo "$DSTDIR/muttng-$VER-$REL.src.rpm" >> $TMPDIR/$NAME.rpmbuild
139         fi
140         
141         cp $SPEC $DSTDIR
142
143         echo "Mailing  $ADDR - BUILT"
144         echo >> $TMPDIR/$NAME.rpmbuild
145         head -15 $TMPDIR/$NAME/ChangeLog.mutt-ng >> $TMPDIR/$NAME.rpmbuild
146         echo "..." >> $TMPDIR/$NAME.rpmbuild
147         $MAIL -s "Mutt-NG: BUILT - $NAME" $ADDR < $TMPDIR/$NAME.rpmbuild
148 else
149         echo "Mailing  $ADDR - ERROR"
150         $MAIL -s "Mutt-NG: ERROR - $NAME" $ADDR < $TMPDIR/$NAME.rpmbuild
151 fi
152
153 # echo "Cleanup  $TMPDIR/muttng-*/ $TMPDIR/$NAME.rpmbuild"
154 /bin/rm -f $TMPDIR/$NAME.rpmbuild
155 (cd $TMPDIR; find ./muttng-* -type d -print | sort -r | cut -d '/' -f2 | uniq | xargs /bin/rm -rf) >/dev/null 2>&1
156
157 exit 1