mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
8.1 KiB

  1. #!/bin/bash
  2. #
  3. # Written by Benjamin Schieder <blindcoder@scavenger.homeip.net>
  4. # Modified by Juergen Sawinski <jsaw@gmx.net> to create
  5. # a package based on freshmeat info
  6. #
  7. # Use:
  8. # newpackage.sh [-main] <rep>/<pkg> <freshmeat package name>
  9. #
  10. # will create <pkg>.desc and <pkg>.conf. .desc will contain the [D] and [COPY]
  11. # already filled in. The other tags are mentioned with TODO.
  12. #
  13. # .conf will contain an empty <pkg>_main() { } and custmain="<pkg>_main"
  14. # if -main is specified.
  15. #
  16. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  17. #
  18. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  19. # Please add additional copyright information _after_ the line containing
  20. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  21. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  22. #
  23. # ROCK Linux: rock-src/misc/archive/fmnewpackage.sh
  24. # ROCK Linux is Copyright (C) 1998 - 2006 Clifford Wolf
  25. #
  26. # This program is free software; you can redistribute it and/or modify
  27. # it under the terms of the GNU General Public License as published by
  28. # the Free Software Foundation; either version 2 of the License, or
  29. # (at your option) any later version. A copy of the GNU General Public
  30. # License can be found at Documentation/COPYING.
  31. #
  32. # Many people helped and are helping developing ROCK Linux. Please
  33. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  34. # file for details.
  35. #
  36. # --- ROCK-COPYRIGHT-NOTE-END ---
  37. #
  38. extract_xml_name() {
  39. local tmp="`tr -d "\012" < $2 | grep $3 | sed "s,.*<$3>\([^<]*\)<.*,\1," | sed 's, ,\n[T] ,g' | sed 's,^\[T\] $,,'`"
  40. eval "$1=\"\$tmp\""
  41. }
  42. get_download() {
  43. local location
  44. download_file=""
  45. download_url=""
  46. for arg; do
  47. if curl -s -I -f "$arg" -o "header.log"; then
  48. location="`grep Location: header.log | sed -e 's,Location:[ ]\([.0-9A-Za-z:/% -]*\).*,\1,' -e 's,prdownloads.sourceforge.net,dl.sourceforge.net,'`"
  49. download_file="`basename $location`"
  50. download_url="`dirname $location`/"
  51. rm -f header.log
  52. return
  53. fi
  54. done
  55. rm -f header.log
  56. }
  57. read_fm_config() {
  58. local fmname=$1
  59. curl_options="" #--disable-epsv -#
  60. if curl -s -f $resume $curl_options "http://freshmeat.net/projects-xml/$fmname/$fmname.xml" -o "$fmname.xml"; then
  61. extract_xml_name project $fmname.xml projectname_full
  62. extract_xml_name title $fmname.xml desc_short
  63. extract_xml_name desc $fmname.xml desc_full
  64. extract_xml_name urlh $fmname.xml url_homepage
  65. extract_xml_name license $fmname.xml license
  66. extract_xml_name version $fmname.xml latest_release_version
  67. extract_xml_name url_tbz $fmname.xml url_bz2
  68. extract_xml_name url_tgz $fmname.xml url_tgz
  69. extract_xml_name url_zip $fmname.xml url_zip
  70. extract_xml_name url_cvs $fmname.xml url_cvs
  71. url="$(curl -I $urlh 2>/dev/null | grep "^Location:" | sed -e 's,^Location: \(.*\)$,\1,' | tr -d '\015' )"
  72. get_download $url_tbz $url_tgz $url_zip #@FIXME $url_cvs
  73. # grep trove categories for status IDs
  74. for trove_id in `grep '<trove_id>' $fmname.xml | sed 's,.*<trove_id>\(.*\)</trove_id>,\1,g'` ; do
  75. case $trove_id in
  76. 9) status="Alpha"
  77. ;;
  78. 10) status="Beta"
  79. ;;
  80. 11,12) status="Stable"
  81. ;;
  82. # there is no default
  83. esac
  84. done
  85. # download package fm-page and grep for the author
  86. html="http://freshmeat.net/projects/$fmname/"
  87. curl -I -s "$html" -o "header.log"
  88. html_new="`grep Location: header.log | sed 's,Location:[ ]\([.0-9A-Za-z:/%?_= -]*\).*,\1,'`"
  89. [ ! -z "$html_new" ] && html="$html_new"
  90. unset html_new
  91. rm -f header.log
  92. curl -s "$html" -o "$fmname.html"
  93. found=0
  94. while read line ; do
  95. if [ ${found} -eq 1 ] ; then
  96. dev_name="`echo ${line} | sed 's,^ *,,g' | cut -f1,2 -d' '`"
  97. fi
  98. if [ "${line//Author:/}" != "${line}" ] ; then
  99. found=1
  100. else
  101. found=0
  102. fi
  103. done < ${fmname}.html
  104. dev_mail="`grep 'contact developer' "$fmname.html" | sed 's,^.*mailto:\(.*\)".*$,\1,'`"
  105. echo '__at__ @' >subst
  106. echo '__dot__ .' >>subst
  107. echo '|at| @' >>subst
  108. echo '|dot| .' >>subst
  109. echo '[at] @' >>subst
  110. echo '[dot] .' >>subst
  111. echo '(at) @' >>subst
  112. echo '(dot) .' >>subst
  113. while read from to ; do
  114. dev_mail=${dev_mail// ${from} /${to}}
  115. done < subst
  116. rm -f subst $fmname.html
  117. if [ -z "$dev_mail" -o -z "$dev_name" ] ; then
  118. dev_name="TODO: "
  119. dev_mail="Author"
  120. fi
  121. #cleanup license
  122. case "$license" in
  123. *GPL*Library*)
  124. license=LGPL
  125. ;;
  126. *GPL*Documentation*)
  127. license=FDL
  128. ;;
  129. *GPL*)
  130. license=GPL
  131. ;;
  132. *Mozilla*Public*)
  133. license=MPL
  134. ;;
  135. *MIT*)
  136. license=MIT
  137. ;;
  138. *BSD*)
  139. license=BSD
  140. ;;
  141. esac
  142. rm -f $fmname.xml
  143. else
  144. return 1
  145. fi
  146. }
  147. if [ "$1" == "-main" ] ; then
  148. create_main=1
  149. shift
  150. fi
  151. if [ $# -lt 2 -o $# -gt 2 ] ; then
  152. cat <<-EEE
  153. Usage:
  154. $0 <option> package/repository/packagename freshmeat-package-name
  155. Where <option> may be:
  156. -main Create a package.conf file with main-function
  157. EEE
  158. exit 1
  159. fi
  160. dir=${1#package/} ; shift
  161. package=${dir##*/}
  162. if [ "$package" = "$dir" ]; then
  163. echo "failed"
  164. echo -e "\t$dir must be <rep>/<pkg>!\n"
  165. exit
  166. fi
  167. rep="$( echo package/*/$package | cut -d'/' -f 2 )"
  168. if [ "$rep" != "*" ]; then
  169. echo "failed"
  170. echo -e "\tpackage $package belongs to $rep!\n"
  171. exit
  172. fi
  173. rep=${dir/\/$package/}
  174. maintainer="$( grep -h -m 1 "\[M\]" package/$rep/*/*.desc | head -n 1 | cut -d' ' -f2- )"
  175. echo -n "Creating package/$dir ... "
  176. if [ -e package/$dir ] ; then
  177. echo "failed"
  178. echo -e "\tpackage/$dir already exists!\n"
  179. exit
  180. fi
  181. if mkdir -p package/$dir ; then
  182. echo "ok"
  183. else
  184. echo "failed"
  185. exit
  186. fi
  187. cd package/$dir
  188. rc="ROCK-COPYRIGHT"
  189. if ! read_fm_config $1; then
  190. echo "Error or wrong freshmeat package name"
  191. exit 1
  192. fi
  193. echo -n "Creating $package.desc ... "
  194. cat >>$package.desc <<EEE
  195. [COPY] --- ${rc}-NOTE-BEGIN ---
  196. [COPY]
  197. [COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  198. [COPY] Please add additional copyright information _after_ the line containing
  199. [COPY] the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  200. [COPY] the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  201. [COPY]
  202. [COPY] ROCK Linux: rock-src/package/$dir/$package.desc
  203. [COPY] ROCK Linux is Copyright (C) 1998 - `date +%Y` Clifford Wolf
  204. [COPY]
  205. [COPY] This program is free software; you can redistribute it and/or modify
  206. [COPY] it under the terms of the GNU General Public License as published by
  207. [COPY] the Free Software Foundation; either version 2 of the License, or
  208. [COPY] (at your option) any later version. A copy of the GNU General Public
  209. [COPY] License can be found at Documentation/COPYING.
  210. [COPY]
  211. [COPY] Many people helped and are helping developing ROCK Linux. Please
  212. [COPY] have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  213. [COPY] file for details.
  214. [COPY]
  215. [COPY] --- ${rc}-NOTE-END ---
  216. [I] ${title:-TODO: Title}
  217. [T] ${desc:-TODO: Description}
  218. [U] ${url:-TODO: URL}
  219. [A] $dev_name <$dev_mail>
  220. [M] ${maintainer:-TODO: Maintainer}
  221. [C] TODO: Category
  222. [L] ${license:-TODO: License}
  223. [S] ${status:-TODO: Status}
  224. [V] ${version:-TODO: Version}
  225. [P] X -----5---9 800.000
  226. [D] 0 $download_file $download_url
  227. EEE
  228. echo "ok"
  229. echo -n "Creating $package.conf ... "
  230. if [ "$create_main" == "1" ] ; then
  231. cat >>$package.conf <<-EEE
  232. # --- ${rc}-NOTE-BEGIN ---
  233. #
  234. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  235. # Please add additional copyright information _after_ the line containing
  236. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  237. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  238. #
  239. # ROCK Linux: rock-src/package/$dir/$package.conf
  240. # ROCK Linux is Copyright (C) 1998 - `date +%Y` Clifford Wolf
  241. #
  242. # This program is free software; you can redistribute it and/or modify
  243. # it under the terms of the GNU General Public License as published by
  244. # the Free Software Foundation; either version 2 of the License, or
  245. # (at your option) any later version. A copy of the GNU General Public
  246. # License can be found at Documentation/COPYING.
  247. #
  248. # Many people helped and are helping developing ROCK Linux. Please
  249. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  250. # file for details.
  251. #
  252. # --- ${rc}-NOTE-END ---
  253. EEE
  254. cat >>$package.conf <<-EEE
  255. ${package}_main() { #TODO
  256. }
  257. custmain="${package}_main"
  258. EEE
  259. fi
  260. echo "ok"
  261. echo "Remember to fill in the TODO's:"
  262. cd -
  263. grep TODO package/$dir/$package.*
  264. echo