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