make.themes.project 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. #!/usr/bin/env 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-2010 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. test x$1 = x && echo "Error: version number not given" && exit 1;
  24. VERS=$1
  25. shift;
  26. SITE=http://www.claws-mail.org
  27. NAME=claws-mail-themes
  28. DDIR=$NAME-$VERS
  29. PAGE=themes.php
  30. LIST=themes.list
  31. WLOG=themes.wget.log
  32. function getListFromPage()
  33. {
  34. test -f ${PAGE} && rm -f ${PAGE};
  35. wget -q -a ${WLOG} ${SITE}/${PAGE}
  36. test ! -f ${PAGE} && echo "Error: couldn't get ${PAGE}." && exit 1;
  37. grep 'download.php?file=' ${PAGE} \
  38. | cut -f2 -d\" \
  39. > ${LIST}
  40. }
  41. function makeRoomForThemes()
  42. {
  43. test -d ${DDIR} \
  44. && rm -rf ${DDIR} \
  45. && echo "Removing previous destination";
  46. mkdir ${DDIR};
  47. }
  48. function downloadThemes()
  49. {
  50. for theme in `cat ${LIST} `;
  51. do tarf=`echo $theme | cut -f2 -d/ `;
  52. test $tarf = "png" \
  53. && tarf=`echo $theme | cut -f3 -d/ `;
  54. echo -n "Downloading... ";
  55. wget -q -a ${WLOG} -O ${DDIR}/$tarf ${SITE}/$theme
  56. test ! -f ${DDIR}/$tarf && echo "Error: couldn't get $tarf" && exit 1;
  57. pushd ${DDIR} > /dev/null
  58. tarops="";
  59. test ${tarf} = ${tarf/.tar.bz2/} && tarops="xzf" || tarops="xjf";
  60. echo -n "unpacking... " \
  61. && tar $tarops $tarf \
  62. && echo -n "deleting tarball... " \
  63. && rm -f $tarf \
  64. && echo "Ok ($tarf)";
  65. popd > /dev/null
  66. done;
  67. }
  68. function removeWhitespaces()
  69. {
  70. cd ${DDIR};
  71. for dir in *;
  72. do test -d "$dir" \
  73. && test ! "${dir}" = "${dir/ /_}" \
  74. && mv "${dir}" "${dir// /_}";
  75. done;
  76. cd "..";
  77. }
  78. function fixPermissions()
  79. {
  80. find ${DDIR} -type d -exec chmod 755 '{}' +
  81. find ${DDIR} -type f -exec chmod 644 '{}' +
  82. }
  83. function createProject()
  84. {
  85. touch ${DDIR}/${NAME}
  86. }
  87. function createThemeMakefileAm()
  88. {
  89. echo "Making $1";
  90. MA="/tmp/tmp.makefile.am";
  91. cd "$1"
  92. dir="$1";
  93. echo 'themedir = $(prefix)/share/claws-mail/themes/'${dir} > $MA
  94. echo "" >> $MA
  95. echo -n 'dist_theme_DATA =' >> $MA
  96. count_png=`ls -1 *.png 2> /dev/null | wc -l `
  97. count_xpm=`ls -1 *.xpm 2> /dev/null | wc -l `
  98. ext="xpm"
  99. count=$count_xpm
  100. if [ $count_png -gt $count_xpm ];
  101. then ext="png";
  102. count=$count_png;
  103. fi
  104. i=1;
  105. for px in `ls -1 *.${ext} `;
  106. do if [ $i -lt $count ];
  107. then echo " $px \\" >> $MA;
  108. else echo " $px" >> $MA;
  109. fi;
  110. i=$((1 + $i));
  111. done;
  112. echo "" >> $MA;
  113. count=`ls * | grep -v "\.${ext}$" | wc -l `;
  114. if [ $count -gt 0 ];
  115. then echo -n 'EXTRA_DIST =' >> $MA;
  116. i=1;
  117. for npx in `ls -1 * | grep -v "\.${ext}$" `;
  118. do if [ $i -lt $count ];
  119. then echo " $npx \\" >> $MA;
  120. else echo " $npx" >> $MA;
  121. fi;
  122. i=$((1 + $i));
  123. done;
  124. echo "" >> $MA;
  125. fi;
  126. mv $MA Makefile.am
  127. cd ".."
  128. }
  129. function createAutogenSh()
  130. {
  131. cat<<EOA > ${DDIR}/autogen.sh
  132. #!/bin/sh
  133. aclocal \
  134. && automake --add-missing --foreign --copy \
  135. && autoconf \
  136. && ./configure --enable-maintainer-mode $@
  137. EOA
  138. chmod +x ${DDIR}/autogen.sh
  139. echo "Created autogen.sh"
  140. }
  141. function createMakefileAm()
  142. {
  143. cd ${DDIR}
  144. MA=Makefile.am
  145. if [ -f INSTALL ]
  146. then echo "EXTRA_DIST = INSTALL "${NAME} > $MA
  147. else echo "EXTRA_DIST = "${NAME} > $MA
  148. fi
  149. echo "" >> $MA
  150. echo -n "SUBDIRS =" >> $MA
  151. for dir in *;
  152. do test -d "$dir" && echo -n " ${dir}" >> $MA;
  153. done;
  154. cd ".."
  155. echo "Created Makefile.am"
  156. }
  157. function createConfigureAc()
  158. {
  159. cd ${DDIR}
  160. CA=configure.ac
  161. echo 'AC_PREREQ(2.59d)' > $CA
  162. echo 'AC_INIT('${NAME}')' >> $CA
  163. echo 'AM_INIT_AUTOMAKE('${NAME}', '${VERS}')' >> $CA
  164. cat >> $CA <<EOC
  165. AM_MAINTAINER_MODE
  166. dnl Checks for programs.
  167. AC_PROG_INSTALL
  168. AC_OUTPUT([
  169. Makefile
  170. EOC
  171. # the list of Makefiles
  172. for dir in *;
  173. do test -d "$dir" \
  174. && echo "${dir}/Makefile" >> $CA \
  175. && createThemeMakefileAm "$dir";
  176. done;
  177. echo "])" >> $CA
  178. cd "..";
  179. echo "Created $CA";
  180. }
  181. function cleanMine()
  182. {
  183. find ${DDIR} -name Makefile.am -delete
  184. rm -f \
  185. ${DDIR}/autogen.sh \
  186. ${DDIR}/configure.ac \
  187. ${DDIR}/${NAME}
  188. }
  189. function cleanGenerated()
  190. {
  191. find ${DDIR} -name Makefile.in -delete
  192. find ${DDIR} -name Makefile -delete
  193. rm -rf ${DDIR}/autom4te.cache
  194. rm -f \
  195. ${DDIR}/aclocal.m4 \
  196. ${DDIR}/install-sh \
  197. ${DDIR}/missing \
  198. ${DDIR}/config.status \
  199. ${DDIR}/configure \
  200. ${DDIR}/config.log
  201. }
  202. case "$1" in
  203. --clean)
  204. cleanMine;
  205. echo "Cleaned.";
  206. ;;
  207. --clean-all)
  208. cleanMine;
  209. cleanGenerated;
  210. echo "Cleaned all.";
  211. ;;
  212. --download)
  213. getListFromPage;
  214. makeRoomForThemes;
  215. downloadThemes;
  216. echo "Downloaded.";
  217. ;;
  218. --autotoolize)
  219. removeWhitespaces;
  220. fixPermissions;
  221. createProject;
  222. createAutogenSh;
  223. createMakefileAm;
  224. createConfigureAc;
  225. echo "Autotoolized.";
  226. ;;
  227. --all)
  228. $0 $VERS --download
  229. $0 $VERS --autotoolize
  230. echo "Done.";
  231. ;;
  232. *)
  233. echo "Syntax: ";
  234. echo " $0 vers {--clean[-all]|--download|--autotoolize|--all}"
  235. ;;
  236. esac