Dash:
[t2-trunk.git] / misc / archive / fmnewpackage.sh
blobd45e7e926dffb98d4154bb9cd085f8555cfcfbf8
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 #
6 # T2 SDE: misc/archive/fmnewpackage.sh
7 # Copyright (C) 2004 - 2007 The T2 SDE Project
8 # Copyright (C) 1998 - 2003 ROCK Linux Project
9 #
10 # More information can be found in the files COPYING and README.
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; version 2 of the License. A copy of the
15 # GNU General Public License can be found in the file COPYING.
16 # --- T2-COPYRIGHT-NOTE-END ---
18 # Written by Benjamin Schieder <blindcoder@scavenger.homeip.net>
20 # Modified by Juergen Sawinski <jsaw@gmx.net> to create
21 # a package based on freshmeat info.
23 # And Rene Rebe <rene@exactcode.de> to fix I/T sentences to begin with
24 # capitals as well as no trailing . in the I tag.
26 # newpackage.sh [-main] <rep>/<pkg> <freshmeat package name>
29 extract_xml_name() {
30 local tmp="`tr -d "\012" < $2 | grep $3 |
31 sed -e "s|.*<$3>\([^<]*\)<.*|\1|" -e 's| |\n|g'`"
32 eval "$1=\"\$tmp\""
35 get_download() {
36 local location
37 for arg; do
38 if curl -s -I -f "$arg" -o "header.log"; then
39 location="`sed -n 's/\r// ; s/Location: *//p' header.log`"
40 download_file="`basename $location`"
41 download_url="`dirname $location`/"
42 rm -f header.log
43 return
45 done
46 rm -f header.log
49 read_fm_config() {
50 local fmname=$1
51 curl_options="" #--disable-epsv -#
52 if curl -s -f $resume $curl_options "http://freshmeat.net/projects-xml/$fmname/$fmname.xml" -o "$fmname.xml"; then
53 extract_xml_name project $fmname.xml projectname_full
54 extract_xml_name title $fmname.xml desc_short
55 extract_xml_name desc $fmname.xml desc_full
56 extract_xml_name urlh $fmname.xml url_homepage
57 extract_xml_name license $fmname.xml license
58 extract_xml_name version $fmname.xml latest_release_version
60 extract_xml_name url_tbz $fmname.xml url_bz2
61 extract_xml_name url_tgz $fmname.xml url_tgz
62 extract_xml_name url_zip $fmname.xml url_zip
63 extract_xml_name url_cvs $fmname.xml url_cvs
65 url="$(curl -I $urlh 2>/dev/null | grep "^Location:" | sed -e 's,^Location: \(.*\)$,\1,' | tr -d '\015' )"
66 get_download $url_tbz $url_tgz $url_zip #@FIXME $url_cvs
68 # grep trove categories for status IDs
69 for trove_id in `grep '<trove_id>' $fmname.xml | sed 's,.*<trove_id>\(.*\)</trove_id>,\1,g'` ; do
70 case $trove_id in
71 9) status="Alpha"
73 10) status="Beta"
75 11,12) status="Stable"
77 # there is no default
78 esac
79 done
81 # download package fm-page and grep for the author
82 html="http://freshmeat.net/projects/$fmname/"
83 curl -I -s "$html" -o "header.log"
84 html_new="`grep Location: header.log | sed 's,Location:[ ]\([.0-9A-Za-z:/%?_= -]*\).*,\1,'`"
85 [ ! -z "$html_new" ] && html="$html_new"
86 unset html_new
87 rm -f header.log
88 curl -s "$html" -o "$fmname.html"
89 dev_name="`grep 'contact developer' "$fmname.html" | sed 's,^[[:blank:]]*\(.*\)[[:blank:]]<a.*$,\1,' | sed 's, *$,,g'`"
90 dev_mail="`grep 'contact developer' "$fmname.html" | sed 's,^.*<a href=\"mailto:\(.*\)\">.*$,\1,'`"
92 dev_mail=`echo $dev_mail |
93 sed -e 's/ *__at__ */@/g' -e 's/ *__dot__ */./g' -e 's/ *__dash__ */-/g' \
94 -e 's/ *|at| */@/g' -e 's/ *|dot| */./g' -e 's/ *|dash| */-/g' \
95 -e 's/ *\[at\] */@/g' -e 's/ *\[dot\] */./g' -e 's/ *\[dash\] */-/g' \
96 -e 's/ *\/at\/ */@/g' -e 's/ *\/dot\/ */./g' -e 's/ *\/dash\/ */-/g' \
97 -e 's/ *(at) */@/g' -e 's/ *(dot) */./g' -e 's/ *(dash) */-/g' \
98 -e 's/ \+at \+/@/g' -e 's/ \+dot \+/./g' -e 's/ \+dash \+/-/g' `
100 rm -f subst $fmname.html dev_mail
102 [ "$dev_name" ] || dev_name="TODO: Name"
103 if [ "$dev_mail" ]; then
104 dev_mail="<$dev_mail>"
105 else
106 dev_name="<TODO>"
109 #cleanup license
110 case "$license" in
111 *GPL*Library*|*Lesser*GPL*)
112 license=LGPL
114 *GPL*Documentation*)
115 license=FDL
117 *GPL*)
118 license=GPL
120 *Mozilla*Public*)
121 license=MPL
123 *MIT*)
124 license=MIT
126 *BSD*)
127 license=BSD
129 *Apache*)
130 license=APL
132 *Artistic*)
133 license=Artistic
135 "Public Domain")
136 license=PublicDomain
138 esac
139 rm -f $fmname.xml
140 else
141 return 1
145 if [ "$1" == "-main" ] ; then
146 create_main=1
147 shift
150 if [ $# -lt 2 -o $# -gt 2 ] ; then
151 cat <<-EEE
152 Usage:
153 $0 <option> package/repository/packagename freshmeat-package-name
155 Where <option> may be:
156 -main Create a package.conf file with main-function
159 exit 1
163 dir=${1#package/} ; shift
164 package=${dir##*/}
165 if [ "$package" = "$dir" ]; then
166 echo "failed"
167 echo -e "\t$dir must be <rep>/<pkg>!\n"
168 exit
171 rep="$( echo package/*/$package | cut -d'/' -f 2 )"
172 if [ "$rep" != "*" ]; then
173 echo "failed"
174 echo -e "\tpackage $package belongs to $rep!\n"
175 exit
178 if [ -e package/$dir ] ; then
179 echo "failed"
180 echo -e "\tpackage/$dir already exists!\n"
181 exit
183 rep=${dir/\/$package/}
185 maintainer='The T2 Project <t2@t2-project.org>'
186 rc="ROCK-COPYRIGHT"
187 download_file=
188 download_url=
190 if ! read_fm_config $1; then
191 echo "Error or wrong freshmeat package name"
192 exit 1
195 echo -n "Creating package/$dir ... "
196 if mkdir -p package/$dir ; then
197 echo "ok"
198 else
199 echo "failed"
200 exit
203 cd package/$dir
205 echo -n "Creating $package.desc ... "
207 title="`echo "$title" | sed 's/^\(.\)/\U\1/ ; s/\.$//'`"
208 cat >>$package.desc <<EOF
209 [I] ${title:-TODO: Title}
213 desc="`echo "$desc" | sed '1s/^\(.\)/\U\1/ ; s/\. *\(.\)/. \U\1/g'`"
214 while read l; do
215 echo "[T] $l" >>$package.desc
216 done < <(echo ${desc:-TODO: Description} | fmt --width 75)
218 cat >>$package.desc <<EOF
220 [U] ${url:-TODO: URL}
222 [A] $dev_name $dev_mail
223 [M] ${maintainer:-TODO: Maintainer}
225 [C] TODO: Category
227 [L] ${license:-TODO: License}
228 [S] ${status:-TODO: Status}
229 [V] ${version:-TODO: Version}
230 [P] X -----5---9 800.000
233 if [ "$download_file" ]; then
234 cat >>$package.desc <<-EOF
236 [D] 0 $download_file $download_url
240 echo "ok"
241 echo -n "Creating $package.conf ... "
243 if [ "$create_main" == "1" ] ; then
244 cat >>$package.conf <<-EOF
245 ${package}_main() {
246 : TODO
249 custmain="${package}_main"
253 echo "ok"
255 echo "Remember to fill in the TODO's:"
256 cd - > /dev/null
257 grep TODO package/$dir/$package.*
258 echo