curl: updated to 7.19.0 and enabled ldaps now.
[pkgfs.git] / mktmpl.sh
blob786626b8448b9ffc6c3327f3af475d673e294f1b
1 #!/bin/sh
3 #-
4 # Copyright (c) 2008 Juan Romero Pardines.
5 # All rights reserved.
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 # Shell script to automate the creation of new templates for pkgfs.
29 # Only writes basic stuff into the template, if you need advanced stuff
30 # you'll have to do that manually.
32 # At least it will fetch the distfile and compute the checksum, plus
33 # other stuff for free... so it's not that bad, heh.
35 # Supports GNU configure, configure and perl module templates for now.
37 : ${ftp_cmd:=/usr/bin/ftp -a}
38 : ${awk_cmd:=/usr/bin/awk}
39 : ${cksum_cmd:=/usr/bin/cksum -a rmd160}
40 : ${sed_cmd:=/usr/bin/sed}
41 : ${db_cmd:=/usr/bin/db -q}
42 : ${config_file:=/usr/local/etc/pkgfs.conf}
43 : ${chmod_cmd:=/bin/chmod}
44 : ${mkdir_cmd:=/bin/mkdir}
46 deps=
47 user_deps=
49 write_new_template()
51 local tmpldir="$PKGFS_DISTRIBUTIONDIR/templates"
52 local depsdir="$PKGFS_DISTRIBUTIONDIR/dependencies"
53 local distdir="$PKGFS_SRCDISTDIR"
54 local checksum=
55 local dfile=
56 local tmplname=
58 [ ! -d $distdir ] && $mkdir_cmd -p $distdir
59 [ ! -d $tmpldir -o ! -d $depsdir ] && exit 1
61 save_pwd=$(pwd -P 2>/dev/null)
62 echo "=> Fetching distfile from $url"
63 cd $distdir && $ftp_cmd $url
64 [ "$?" -ne 0 ] && echo "Error fetching file, aborting." && exit 1
66 dfile=$(basename $url)
67 checksum=$($cksum_cmd $dfile|$awk_cmd '{print $4}')
68 [ -z "$checksum" ] && echo "Checksum empty, aborting." && exit 1
70 cd $save_pwd
72 pkg="$pkgname-$version"
73 pkg_sufx=${dfile##$pkg}
75 if [ "$build_style" = "g" ]; then
76 build_style=gnu_configure
77 elif [ "$build_style" = "p" ]; then
78 build_style=perl_module
79 tmplname="perl-"
80 else
81 build_style=configure
84 if [ -f "$tmpldir/$pkgname.tmpl" ]; then
85 echo "There's an existing template with the same name, do you"
86 echo -n "want to overwrite it? (y)es or (n)o: "
87 read overwrite
88 if [ "$overwrite" = "n" ]; then
89 echo "not overwriting... bye."
90 exit 1
91 elif [ -z "$overwrite" ]; then
92 echo "no answer?... will overwrite"
96 ( \
97 echo "# Template build file for '$tmplname$pkgname'."; \
98 echo "pkgname=$tmplname$pkgname"; \
99 echo "version=$version"; \
100 if [ -n "$perl_module" ]; then \
101 echo "distfiles=\"$pkg\""; \
102 fi; \
103 echo "extract_sufx=\"$pkg_sufx\""; \
104 echo "url=${url%%/$dfile}"; \
105 echo "build_style=$build_style"; \
106 if [ -n "$dep_gmake" ]; then \
107 echo "make_cmd=\"\$PKGFS_MASTERDIR/bin/gmake\""; \
108 fi; \
109 if [ -n "$pcfiles" ]; then \
110 echo "pkgconfig_override=\"$pcfiles\""; \
111 fi; \
112 echo "short_desc=\"$short_desc\""; \
113 echo "maintainer=\"$maintainer\""; \
114 echo "checksum=$checksum"; \
115 echo "long_desc=\"...\""; \
116 ) > $tmpldir/$tmplname$pkgname.tmpl
118 if [ ! -r "$tmpldir/$tmplname$pkgname.tmpl" ]; then
119 echo "Couldn't write template, aborting."
120 exit 1
123 $chmod_cmd 755 $tmpldir/$tmplname$pkgname.tmpl
125 if [ -n "$deps" ]; then
126 [ -n "$pcfiles" ] && deps="pkg-config-0.23 $deps"
127 [ -n "$perl_module" ] && deps="perl-5.10.0 $deps"
129 for i in ${user_deps}; do
130 deps="$i $deps"
131 done
133 $db_cmd -R -P 512 -w btree $depsdir/build-depends.db $pkgname \
134 "$deps" 2>&1 >/dev/null
135 [ "$?" -ne 0 ] && \
136 echo "Errong writing dependencies db file." && exit 1
139 echo
140 echo "=> Template created at: $tmpldir/$tmplname$pkgname.tmpl"
141 echo
142 echo "If you need more changes, do them manually. You can also look"
143 echo "at $tmpldir/example.tmpl to know what variables can be used and"
144 echo "to learn about their meanings. Don't forget to set \$long_desc!"
145 echo
146 echo "Happy hacking!"
149 read_parameters()
151 if [ ! -f "$config_file" ]; then
152 echo "-- Configuration file cannot be read --"
153 exit 1
156 . $config_file
158 echo -n "Enter name of this package: "
159 read pkgname
161 [ -z "$pkgname" ] && echo "-- Empty value --" && exit 1
163 echo -n "Enter version number of this package: "
164 read version
166 [ -z "$version" ] && echo "-- Empty value --" && exit 1
168 echo "What's the build style for this template?"
169 echo -n "(g)nu_configure, (c)onfigure, (p)erl_module: "
170 read build_style
171 echo
173 if [ -z "$build_style" ]; then
174 echo " -- Empty value --"
175 exit 1
176 elif [ "$build_style" = "g" ]; then
177 gnu_configure=yes
178 elif [ "$build_style" = "c" ]; then
179 configure=yes
180 elif [ "$build_style" = "p" ]; then
181 perl_module=yes
182 else
183 echo " -- Invalid answer --"
184 exit 1
187 echo -n "Requires GNU libtool this package? (y) or (n): "
188 read dep_libtool
189 [ "$dep_libtool" = "y" ] && deps="libtool-2.2.6a $deps"
191 echo -n "Requires GNU make this package? (y) or (n): "
192 read dep_gmake
193 echo
194 [ "$dep_gmake" = "y" ] && deps="gmake-3.81 $deps"
196 echo "Please enter exact dependencies required for this template."
197 echo "They must be separated by whitespaces, e.g: foo-1.0 blah-2.0."
198 echo
199 echo "If it's a perl module or uses libtool/gmake, the dependency"
200 echo "will be added automatically so don't add them here again!"
201 echo -n "> "
202 read user_deps
203 echo
205 echo "Will this package install pkg-config files?"
206 echo "If true, enter the names of the files with the .pc extension"
207 echo "and separated with whitespaces between them, e.g: foo.pc blah.pc."
208 echo
209 echo "Alternatively press the enter key to ignore this question."
210 echo -n "> "
211 read pcfiles
212 echo
214 echo "Enter full URL to download the distfile: "
215 echo -n "> "
216 read url
217 echo
218 [ -z "$url" ] && echo " -- Empty value --" && exit 1
220 echo "Enter short description (max 72 characters):"
221 echo -n "> "
222 read short_desc
223 echo
225 echo "Enter maintainer for this package, e.g: Anon <ymous.org>:"
226 echo "Alternatively press enter to ignore this question."
227 echo -n "> "
228 read maintainer
229 echo
231 write_new_template
235 # If user specified a full path to pkgfs.conf, use it. Otherwise look
236 # at default location, and as last resort current dir.
238 if [ -n "$1" ]; then
239 config_file="$1"
242 if [ ! -f "$config_file" ]; then
243 config_file="$(pwd -P 2>/dev/null)/pkgfs.conf"
244 if [ ! -f "$config_file" ]; then
245 echo "$(basename $0): cannot find configuration file"
246 echo "Please speficify it, e.g: $(basename $0) /path/to/pkgfs.conf"
247 exit 1
251 read_parameters
252 exit $?