2007-10-13 [colin] 3.0.2cvs69
[claws.git] / tools / make.themes.project
1 #!/bin/bash
2 #
3 # Generate the source directory for claws-mail-themes package
4 # from the theme tarballs in http://claws-mail.org/themes.php
5 #
6 # Copyright (c) 2006-2007 Ricardo Mones <ricardo@mones.org>
7 #                         Paul Mangan <paul@claws-mail.org>
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22
23
24 function printHelp()
25 {
26   echo "Syntax: ";
27   echo "  $0 version {--clean[-all]|--download|--autotoolize|--all}"
28 }
29
30 test x$1 = x && echo "Error: version number not given" && printHelp && exit 1;
31
32 VERS=$1
33 shift;
34 SITE=http://claws-mail.org
35 NAME=claws-mail-themes
36 NOTES=RELEASE_NOTES
37 DDIR=$NAME-$VERS
38 PAGE=themes.php
39 LIST=themes.list
40 WLOG=themes.wget.log
41
42 function getListFromPage()
43 {
44   test -f ${PAGE} && rm -f ${PAGE};
45   wget -q -a ${WLOG} ${SITE}/${PAGE}
46   test ! -f ${PAGE} && echo "Error: couldn't get ${PAGE}." && exit 1;
47
48   grep 'download.php?file=' ${PAGE} \
49        | cut -f2 -d\" \
50        > ${LIST}
51 }
52
53 function makeRoomForThemes()
54 {
55   test -d ${DDIR} \
56     && rm -rf ${DDIR} \
57     && echo "Removing previous destination";
58   mkdir ${DDIR};
59 }
60
61 function downloadThemes()
62 {
63   for theme in `cat ${LIST} `;
64   do tarf=`echo $theme | cut -f2 -d/ `;
65      echo -n "Downloading... ";
66      wget -q -a ${WLOG} -P ${DDIR} ${SITE}/$theme
67      test ! -f ${DDIR}/$tarf && echo "Error: couldn't get $tarf" && exit 1;
68      pushd ${DDIR} > /dev/null
69      tarops="";
70      test ${tarf} = ${tarf/.tar.bz2/} && tarops="xzf" || tarops="xjf";
71      echo -n "unpacking... " \
72           && tar $tarops $tarf \
73           && echo -n "deleting tarball... " \
74           && rm -f $tarf \
75           && echo "Ok ($tarf)";
76      popd > /dev/null
77   done;
78 }
79
80 function removeWhitespaces()
81 {
82   cd ${DDIR};
83   for dir in *;
84   do test -d "$dir" \
85        && test ! "${dir}" = "${dir/ /_}" \
86        && mv "${dir}" "${dir// /_}"; 
87   done;
88   cd "..";
89 }
90
91 function createProject()
92 {
93   touch ${DDIR}/${NAME} ${DDIR}/${NOTES}
94   find ${DDIR} -type f -exec chmod -x '{}' +
95 }
96
97 function createThemeMakefileAm()
98 {
99   echo "Making $1";
100   MA="/tmp/tmp.makefile.am";
101   cd "$1"
102   dir="$1";
103   echo 'themedir = $(prefix)/share/claws-mail/themes/'${dir} > $MA
104   echo "" >> $MA
105   echo -n 'dist_theme_DATA =' >> $MA 
106   test -f .claws_themeinfo \
107     && echo " .claws_themeinfo \\" >> $MA;
108   count=`ls *.xpm | wc -l `;
109   i=1;
110   for px in `ls -1 *.xpm `; 
111   do if [ $i -lt $count ]; 
112      then echo " $px \\" >> $MA; 
113      else echo " $px" >> $MA; 
114      fi; 
115      i=$((1 + $i)); 
116   done;
117   echo "" >> $MA;
118   count=`ls * | grep -v '\.xpm$' | wc -l `;
119   if [ $count -gt 0 ];
120   then echo -n 'EXTRA_DIST =' >> $MA;
121        i=1;
122        for npx in `ls -1 * | grep -v '\.xpm$' `;
123        do if [ $i -lt $count ];
124           then echo " $npx \\" >> $MA;
125           else echo " $npx" >> $MA;
126           fi;
127           i=$((1 + $i));
128        done;
129        echo "" >> $MA;
130   fi;
131   mv $MA Makefile.am
132   cd ".."
133 }
134
135 function createAutogenSh()
136 {
137   cat<<EOA > ${DDIR}/autogen.sh
138 #!/bin/sh
139
140 aclocal \
141   && automake --add-missing --foreign --copy \
142   && autoconf \
143   && ./configure --enable-maintainer-mode $@
144 EOA
145   chmod +x ${DDIR}/autogen.sh
146   echo "Created autogen.sh"
147 }
148
149 function createMakefileAm()
150 {
151   cd ${DDIR}
152   MA=Makefile.am
153   echo "AUTOMAKE_OPTIONS = dist-bzip2" > $MA
154   echo "" >> $MA
155   echo "EXTRA_DIST = INSTALL "${NOTES} ${NAME} >> $MA
156   echo "" >> $MA
157   echo -n "SUBDIRS =" >> $MA
158   for dir in *;
159   do test -d "$dir" && echo -n " ${dir}" >> $MA;
160   done;
161   echo "" >> $MA
162   cd ".."
163   echo "Created Makefile.am"
164 }
165
166 function createConfigureAc()
167 {
168   cd ${DDIR}
169   CA=configure.ac
170   echo 'AC_PREREQ(2.59d)' > $CA
171   echo 'AC_INIT('${NAME}')' >> $CA
172   echo 'AM_INIT_AUTOMAKE('${NAME}', '${VERS}')' >> $CA
173   cat >> $CA <<EOC
174
175 AM_MAINTAINER_MODE
176
177 dnl Checks for programs.
178 AC_PROG_INSTALL
179
180 AC_OUTPUT([
181 Makefile
182 EOC
183   # the list of Makefiles
184   for dir in *;
185   do test -d "$dir" \
186        && echo "${dir}/Makefile" >> $CA \
187        && createThemeMakefileAm "$dir";
188   done;
189   echo "])" >> $CA
190   cd "..";
191   echo "Created $CA";
192 }
193
194 function cleanMine()
195 {
196   find ${DDIR} -name Makefile.am -delete
197   rm -f \
198      ${DDIR}/autogen.sh \
199      ${DDIR}/configure.ac \
200      ${DDIR}/${NAME}
201 }
202
203 function cleanGenerated()
204 {
205   find ${DDIR} -name Makefile.in -delete
206   find ${DDIR} -name Makefile -delete
207   rm -rf ${DDIR}/autom4te.cache
208   rm -f \
209      ${DDIR}/aclocal.m4 \
210      ${DDIR}/install-sh \
211      ${DDIR}/missing \
212      ${DDIR}/config.status \
213      ${DDIR}/configure \
214      ${DDIR}/config.log
215 }
216
217 case "$1" in
218   --clean)
219       cleanMine;      
220       echo "Cleaned.";
221     ;;
222   --clean-all)
223       cleanMine;
224       cleanGenerated;
225       echo "Cleaned all.";
226     ;;
227   --download)
228       getListFromPage;
229       makeRoomForThemes;
230       downloadThemes;
231       echo "Downloaded.";
232     ;;
233   --autotoolize)
234       removeWhitespaces;
235       createProject;
236       createAutogenSh;
237       createMakefileAm;
238       createConfigureAc;
239       echo "Autotoolized.";
240     ;;
241   --all)
242     $0 $VERS --download
243     $0 $VERS --autotoolize
244     echo "Done.";
245     ;;
246   *)
247       printHelp;
248     ;;
249 esac
250