plug leaks
[claws.git] / tools / make.themes.project
blob038bad76048f41484fd32c2baa2eeff378b85bbd
1 #!/usr/bin/env bash
3 # Generate the source directory for claws-mail-themes package
4 # from the theme tarballs in http://www.claws-mail.org/themes.php
6 # Copyright (c) 2006-2010 Ricardo Mones <ricardo@mones.org>
7 # Paul Mangan <paul@claws-mail.org>
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.
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.
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.
24 test x$1 = x && echo "Error: version number not given" && exit 1;
26 VERS=$1
27 shift;
28 SITE=http://www.claws-mail.org
29 NAME=claws-mail-themes
30 DDIR=$NAME-$VERS
31 PAGE=themes.php
32 LIST=themes.list
33 WLOG=themes.wget.log
35 function getListFromPage()
37 test -f ${PAGE} && rm -f ${PAGE};
38 wget -q -a ${WLOG} ${SITE}/${PAGE}
39 test ! -f ${PAGE} && echo "Error: couldn't get ${PAGE}." && exit 1;
41 grep 'download.php?file=' ${PAGE} \
42 | cut -f2 -d\" \
43 > ${LIST}
46 function makeRoomForThemes()
48 test -d ${DDIR} \
49 && rm -rf ${DDIR} \
50 && echo "Removing previous destination";
51 mkdir ${DDIR};
54 function downloadThemes()
56 for theme in `cat ${LIST} `;
57 do tarf=`echo $theme | cut -f2 -d/ `;
58 test $tarf = "png" \
59 && tarf=`echo $theme | cut -f3 -d/ `;
60 echo -n "Downloading... ";
61 wget -q -a ${WLOG} -O ${DDIR}/$tarf ${SITE}/$theme
62 test ! -f ${DDIR}/$tarf && echo "Error: couldn't get $tarf" && exit 1;
63 pushd ${DDIR} > /dev/null
64 tarops="";
65 test ${tarf} = ${tarf/.tar.bz2/} && tarops="xzf" || tarops="xjf";
66 echo -n "unpacking... " \
67 && tar $tarops $tarf \
68 && echo -n "deleting tarball... " \
69 && rm -f $tarf \
70 && echo "Ok ($tarf)";
71 popd > /dev/null
72 done;
75 function removeWhitespaces()
77 cd ${DDIR};
78 for dir in *;
79 do test -d "$dir" \
80 && test ! "${dir}" = "${dir/ /_}" \
81 && mv "${dir}" "${dir// /_}";
82 done;
83 cd "..";
86 function fixPermissions()
88 find ${DDIR} -type d -exec chmod 755 '{}' +
89 find ${DDIR} -type f -exec chmod 644 '{}' +
92 function createProject()
94 touch ${DDIR}/${NAME}
97 function createThemeMakefileAm()
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 count_png=`ls -1 *.png 2> /dev/null | wc -l `
107 count_xpm=`ls -1 *.xpm 2> /dev/null | wc -l `
108 ext="xpm"
109 count=$count_xpm
110 if [ $count_png -gt $count_xpm ];
111 then ext="png";
112 count=$count_png;
114 i=1;
115 for px in `ls -1 *.${ext} `;
116 do if [ $i -lt $count ];
117 then echo " $px \\" >> $MA;
118 else echo " $px" >> $MA;
119 fi;
120 i=$((1 + $i));
121 done;
122 echo "" >> $MA;
123 count=`ls * | grep -v "\.${ext}$" | wc -l `;
124 if [ $count -gt 0 ];
125 then echo -n 'EXTRA_DIST =' >> $MA;
126 i=1;
127 for npx in `ls -1 * | grep -v "\.${ext}$" `;
128 do if [ $i -lt $count ];
129 then echo " $npx \\" >> $MA;
130 else echo " $npx" >> $MA;
132 i=$((1 + $i));
133 done;
134 echo "" >> $MA;
136 mv $MA Makefile.am
137 cd ".."
140 function createAutogenSh()
142 cat<<EOA > ${DDIR}/autogen.sh
143 #!/bin/sh
145 aclocal \
146 && automake --add-missing --foreign --copy \
147 && autoconf \
148 && ./configure --enable-maintainer-mode $@
150 chmod +x ${DDIR}/autogen.sh
151 echo "Created autogen.sh"
154 function createMakefileAm()
156 cd ${DDIR}
157 MA=Makefile.am
158 if [ -f INSTALL ]
159 then echo "EXTRA_DIST = INSTALL "${NAME} > $MA
160 else echo "EXTRA_DIST = "${NAME} > $MA
162 echo "" >> $MA
163 echo -n "SUBDIRS =" >> $MA
164 for dir in *;
165 do test -d "$dir" && echo -n " ${dir}" >> $MA;
166 done;
167 cd ".."
168 echo "Created Makefile.am"
171 function createConfigureAc()
173 cd ${DDIR}
174 CA=configure.ac
175 echo 'AC_PREREQ(2.59d)' > $CA
176 echo 'AC_INIT('${NAME}')' >> $CA
177 echo 'AM_INIT_AUTOMAKE('${NAME}', '${VERS}')' >> $CA
178 cat >> $CA <<EOC
180 AM_MAINTAINER_MODE
182 dnl Checks for programs.
183 AC_PROG_INSTALL
185 AC_OUTPUT([
186 Makefile
188 # the list of Makefiles
189 for dir in *;
190 do test -d "$dir" \
191 && echo "${dir}/Makefile" >> $CA \
192 && createThemeMakefileAm "$dir";
193 done;
194 echo "])" >> $CA
195 cd "..";
196 echo "Created $CA";
199 function cleanMine()
201 find ${DDIR} -name Makefile.am -delete
202 rm -f \
203 ${DDIR}/autogen.sh \
204 ${DDIR}/configure.ac \
205 ${DDIR}/${NAME}
208 function cleanGenerated()
210 find ${DDIR} -name Makefile.in -delete
211 find ${DDIR} -name Makefile -delete
212 rm -rf ${DDIR}/autom4te.cache
213 rm -f \
214 ${DDIR}/aclocal.m4 \
215 ${DDIR}/install-sh \
216 ${DDIR}/missing \
217 ${DDIR}/config.status \
218 ${DDIR}/configure \
219 ${DDIR}/config.log
222 case "$1" in
223 --clean)
224 cleanMine;
225 echo "Cleaned.";
227 --clean-all)
228 cleanMine;
229 cleanGenerated;
230 echo "Cleaned all.";
232 --download)
233 getListFromPage;
234 makeRoomForThemes;
235 downloadThemes;
236 echo "Downloaded.";
238 --autotoolize)
239 removeWhitespaces;
240 fixPermissions;
241 createProject;
242 createAutogenSh;
243 createMakefileAm;
244 createConfigureAc;
245 echo "Autotoolized.";
247 --all)
248 $0 $VERS --download
249 $0 $VERS --autotoolize
250 echo "Done.";
253 echo "Syntax: ";
254 echo " $0 vers {--clean[-all]|--download|--autotoolize|--all}"
256 esac