* lhw changed Url http -> https
[t2sde.git] / misc / archive / fmnewpackage.sh
blobce14a21186f88748570c974da466252d880b95b0
1 #!/bin/bash
3 # --- T2-COPYRIGHT-NOTE-BEGIN ---
4 # T2 SDE: misc/archive/fmnewpackage.sh
5 # Copyright (C) 2004 - 2022 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # This Copyright note is generated by scripts/Create-CopyPatch,
9 # more information can be found in the files COPYING and README.
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 2.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 # Written by Benjamin Schieder <blindcoder@scavenger.homeip.net>
17 # Modified by Juergen Sawinski <jsaw@gmx.net> to create
18 # a package based on freshmeat info.
20 # And Rene Rebe <rene@exactcode.de> to fix I/T sentences to begin with
21 # capitals as well as no trailing . in the I tag.
23 # newpackage.sh [-main] <rep>/<pkg> <freshmeat package name>
26 extract_xml_name() {
27 local tmp="`tr -d "\012" < $2 | grep $3 |
28 sed -e "s|.*<$3>\([^<]*\)<.*|\1|" -e 's| |\n|g'`"
29 eval "$1=\"\$tmp\""
32 get_download() {
33 local location
34 for arg; do
35 if curl -s -I -f "$arg" -o "header.log"; then
36 location="`sed -n 's/\r// ; s/Location: *//p' header.log`"
37 download_file="`basename $location`"
38 download_url="`dirname $location`/"
39 rm -f header.log
40 return
42 done
43 rm -f header.log
46 read_fm_config() {
47 local fmname=$1
48 curl_options="" #--disable-epsv -#
49 if curl -s -f $resume $curl_options "http://freshmeat.net/projects-xml/$fmname/$fmname.xml" -o "$fmname.xml"; then
50 extract_xml_name project $fmname.xml projectname_full
51 extract_xml_name title $fmname.xml desc_short
52 extract_xml_name desc $fmname.xml desc_full
53 extract_xml_name urlh $fmname.xml url_homepage
54 extract_xml_name license $fmname.xml license
55 extract_xml_name version $fmname.xml latest_release_version
57 extract_xml_name url_tbz $fmname.xml url_bz2
58 extract_xml_name url_tgz $fmname.xml url_tgz
59 extract_xml_name url_zip $fmname.xml url_zip
60 extract_xml_name url_cvs $fmname.xml url_cvs
62 url="$(curl -I $urlh 2>/dev/null | grep "^Location:" | sed -e 's,^Location: \(.*\)$,\1,' | tr -d '\015' )"
63 get_download $url_tbz $url_tgz $url_zip #@FIXME $url_cvs
65 # grep trove categories for status IDs
66 for trove_id in `grep '<trove_id>' $fmname.xml | sed 's,.*<trove_id>\(.*\)</trove_id>,\1,g'` ; do
67 case $trove_id in
68 9) status="Alpha"
70 10) status="Beta"
72 11,12) status="Stable"
74 # there is no default
75 esac
76 done
78 # download package fm-page and grep for the author
79 html="http://freshmeat.net/projects/$fmname/"
80 curl -I -s "$html" -o "header.log"
81 html_new="`grep Location: header.log | sed 's,Location:[ ]\([.0-9A-Za-z:/%?_= -]*\).*,\1,'`"
82 [ ! -z "$html_new" ] && html="$html_new"
83 unset html_new
84 rm -f header.log
85 curl -s "$html" -o "$fmname.html"
86 dev_name="`grep 'contact developer' "$fmname.html" | sed 's,^[[:blank:]]*\(.*\)[[:blank:]]<a.*$,\1,' | sed 's, *$,,g'`"
87 dev_mail="`grep 'contact developer' "$fmname.html" | sed 's,^.*<a href=\"mailto:\(.*\)\">.*$,\1,'`"
89 dev_mail=`echo $dev_mail |
90 sed -e 's/ *__at__ */@/g' -e 's/ *__dot__ */./g' -e 's/ *__dash__ */-/g' \
91 -e 's/ *|at| */@/g' -e 's/ *|dot| */./g' -e 's/ *|dash| */-/g' \
92 -e 's/ *\[at\] */@/g' -e 's/ *\[dot\] */./g' -e 's/ *\[dash\] */-/g' \
93 -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' `
97 rm -f subst $fmname.html dev_mail
99 [ "$dev_name" ] || dev_name="TODO: Name"
100 if [ "$dev_mail" ]; then
101 dev_mail="<$dev_mail>"
102 else
103 dev_name="<TODO>"
106 #cleanup license
107 case "$license" in
108 *GPL*Library*|*Lesser*GPL*)
109 license=LGPL
111 *GPL*Documentation*)
112 license=FDL
114 *GPL*)
115 license=GPL
117 *Mozilla*Public*)
118 license=MPL
120 *MIT*)
121 license=MIT
123 *BSD*)
124 license=BSD
126 *Apache*)
127 license=APL
129 *Artistic*)
130 license=Artistic
132 "Public Domain")
133 license=PublicDomain
135 esac
136 rm -f $fmname.xml
137 else
138 return 1
142 if [ "$1" == "-main" ] ; then
143 create_main=1
144 shift
147 if [ $# -lt 2 -o $# -gt 2 ] ; then
148 cat <<-EEE
149 Usage:
150 $0 <option> package/repository/packagename freshmeat-package-name
152 Where <option> may be:
153 -main Create a package.conf file with main-function
156 exit 1
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
168 rep="$( echo package/*/$package | cut -d'/' -f 2 )"
169 if [ "$rep" != "*" ]; then
170 echo "failed"
171 echo -e "\tpackage $package belongs to $rep!\n"
172 exit
175 if [ -e package/$dir ] ; then
176 echo "failed"
177 echo -e "\tpackage/$dir already exists!\n"
178 exit
180 rep=${dir/\/$package/}
182 maintainer='The T2 Project <t2@t2-project.org>'
183 download_file=
184 download_url=
186 if ! read_fm_config $1; then
187 echo "Error or wrong freshmeat package name"
188 exit 1
191 echo -n "Creating package/$dir ... "
192 if mkdir -p package/$dir ; then
193 echo "ok"
194 else
195 echo "failed"
196 exit
199 cd package/$dir
201 echo -n "Creating $package.desc ... "
203 title="`echo "$title" | sed 's/^\(.\)/\U\1/ ; s/\.$//'`"
204 cat >>$package.desc <<EOF
205 [I] ${title:-TODO: Title}
209 desc="`echo "$desc" | sed '1s/^\(.\)/\U\1/ ; s/\. *\(.\)/. \U\1/g'`"
210 while read l; do
211 echo "[T] $l" >>$package.desc
212 done < <(echo ${desc:-TODO: Description} | fmt --width 75)
214 cat >>$package.desc <<EOF
216 [U] ${url:-TODO: URL}
218 [A] $dev_name $dev_mail
219 [M] ${maintainer:-TODO: Maintainer}
221 [C] TODO: Category
223 [L] ${license:-TODO: License}
224 [S] ${status:-TODO: Status}
225 [V] ${version:-TODO: Version}
226 [P] X -----5---9 800.000
229 if [ "$download_file" ]; then
230 cat >>$package.desc <<-EOF
232 [D] 0 $download_file $download_url
236 echo "ok"
237 echo -n "Creating $package.conf ... "
239 if [ "$create_main" == "1" ] ; then
240 cat >>$package.conf <<-EOF
241 ${package}_main() {
242 : TODO
245 custmain="${package}_main"
249 echo "ok"
251 echo "Remember to fill in the TODO's:"
252 cd - > /dev/null
253 grep TODO package/$dir/$package.*
254 echo