font-adobe-utopia-type1: don't forget to run mkfont* stuff.
[pkgfs.git] / mktmpl.sh
blob831ca6f3b8d1955c5654e040a554a8487fb0b4ad
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 required_deps=
48 write_new_template()
50 local tmpldir="$PKGFS_DISTRIBUTIONDIR/templates"
51 local depsdir="$PKGFS_DISTRIBUTIONDIR/dependencies"
52 local distdir="$PKGFS_SRCDISTDIR"
53 local checksum=
54 local dfile=
55 local tmplname=
57 [ ! -d $distdir ] && $mkdir_cmd -p $distdir
58 [ ! -d $tmpldir -o ! -d $depsdir ] && exit 1
60 save_pwd=$(pwd -P 2>/dev/null)
61 echo "=> Fetching distfile from $url"
62 cd $distdir && $ftp_cmd $url
63 [ "$?" -ne 0 ] && echo "Error fetching file, aborting." && exit 1
65 dfile=$(basename $url)
66 checksum=$($cksum_cmd $dfile|$awk_cmd '{print $4}')
67 [ -z "$checksum" ] && echo "Checksum empty, aborting." && exit 1
69 cd $save_pwd
71 pkg="$pkgname-$version"
72 pkg_sufx=${dfile##$pkg}
74 if [ "$build_style" = "g" ]; then
75 build_style=gnu_configure
76 elif [ "$build_style" = "p" ]; then
77 build_style=perl_module
78 tmplname="perl-"
79 else
80 build_style=configure
83 if [ -f "$tmpldir/$pkgname.tmpl" ]; then
84 echo "There's an existing template with the same name, do you"
85 echo -n "want to overwrite it? (y)es or (n)o: "
86 read overwrite
87 if [ "$overwrite" = "n" ]; then
88 echo "not overwriting... bye."
89 exit 1
90 elif [ -z "$overwrite" ]; then
91 echo "no answer?... will overwrite"
95 ( \
96 echo "# Template build file for '$tmplname$pkgname'."; \
97 echo "pkgname=$tmplname$pkgname"; \
98 echo "version=$version"; \
99 if [ -n "$perl_module" ]; then \
100 echo "distfiles=\"$pkg\""; \
101 fi; \
102 echo "extract_sufx=\"$pkg_sufx\""; \
103 echo "url=${url%%/$dfile}"; \
104 echo "build_style=$build_style"; \
105 if [ -n "$dep_gmake" ]; then \
106 echo "make_cmd=\"\$PKGFS_MASTERDIR/bin/gmake\""; \
107 fi; \
108 if [ -n "$pcfiles" ]; then \
109 echo "pkgconfig_override=\"$pcfiles\""; \
110 fi; \
111 echo "short_desc=\"$short_desc\""; \
112 echo "maintainer=\"$maintainer\""; \
113 echo "checksum=$checksum"; \
114 echo "long_desc=\"...\""; \
115 ) > $tmpldir/$tmplname$pkgname.tmpl
117 if [ ! -r "$tmpldir/$tmplname$pkgname.tmpl" ]; then
118 echo "Couldn't write template, aborting."
119 exit 1
122 $chmod_cmd 755 $tmpldir/$tmplname$pkgname.tmpl
124 if [ -n "$deps" ]; then
125 for i in $required_deps; do
126 deps="$i $deps"
127 done
128 [ -n "$pcfiles" ] && deps="pkg-config-0.23 $deps"
129 [ -n "$perl_module" ] && deps="perl-5.10.0 $deps"
131 $db_cmd -R -P 512 -w btree $depsdir/build-depends.db $pkgname \
132 "$deps" 2>&1 >/dev/null
133 [ "$?" -ne 0 ] && \
134 echo "Errong writing dependencies db file." && exit 1
137 echo
138 echo "=> Template created at: $tmpldir/$tmplname$pkgname.tmpl"
139 echo
140 echo "If you need more changes, do them manually. You can also look"
141 echo "at $tmpldir/example.tmpl to know what variables can be used and"
142 echo "to learn about their meanings. Don't forget to set \$long_desc!"
143 echo
144 echo "Happy hacking!"
147 read_parameters()
149 if [ ! -f "$config_file" ]; then
150 echo "-- Configuration file cannot be read --"
151 exit 1
154 . $config_file
156 echo -n "Enter name of this package: "
157 read pkgname
159 [ -z "$pkgname" ] && echo "-- Empty value --" && exit 1
161 echo -n "Enter version number of this package: "
162 read version
164 [ -z "$version" ] && echo "-- Empty value --" && exit 1
166 echo "What's the build style for this template?"
167 echo -n "(g)nu_configure, (c)onfigure, (p)erl_module: "
168 read build_style
169 echo
171 if [ -z "$build_style" ]; then
172 echo " -- Empty value --"
173 exit 1
174 elif [ "$build_style" = "g" ]; then
175 gnu_configure=yes
176 elif [ "$build_style" = "c" ]; then
177 configure=yes
178 elif [ "$build_style" = "p" ]; then
179 perl_module=yes
180 else
181 echo " -- Invalid answer --"
182 exit 1
185 echo -n "Requires GNU libtool this package? (y) or (n): "
186 read dep_libtool
187 [ "$dep_libtool" = "y" ] && \
188 required_deps="libtool-2.2.6a $required_deps"
190 echo -n "Requires GNU make this package? (y) or (n): "
191 read dep_gmake
192 echo
193 [ "$dep_gmake" = "y" ] && \
194 required_deps="gmake-3.81 $required_deps"
195 [ "$dep_gmake" = "n" ] && dep_gmake=
197 echo "Please enter exact dependencies required for this template."
198 echo "They must be separated by whitespaces, e.g: foo-1.0 blah-2.0."
199 echo
200 echo "If it's a perl module or uses libtool/gmake, the dependency"
201 echo "will be added automatically so don't add them here again!"
202 echo -n "> "
203 read deps
204 echo
205 [ -z "$deps" ] && echo "No dependencies, continuing..."
207 echo "Will this package install pkg-config files?"
208 echo "If true, enter the names of the files with the .pc extension"
209 echo "and separated with whitespaces between them, e.g: foo.pc blah.pc."
210 echo
211 echo "Alternatively press the enter key to ignore this question."
212 echo -n "> "
213 read pcfiles
214 echo
216 echo "Enter full URL to download the distfile: "
217 echo -n "> "
218 read url
219 echo
220 [ -z "$url" ] && echo " -- Empty value --" && exit 1
222 echo "Enter short description (max 72 characters):"
223 echo -n "> "
224 read short_desc
225 echo
227 echo "Enter maintainer for this package, e.g: Anon <ymous.org>:"
228 echo "Alternatively press enter to ignore this question."
229 echo -n "> "
230 read maintainer
231 echo
233 write_new_template
237 # If user specified a full path to pkgfs.conf, use it. Otherwise look
238 # at default location, and as last resort current dir.
240 if [ -n "$1" ]; then
241 config_file="$1"
244 if [ ! -f "$config_file" ]; then
245 config_file="$(pwd -P 2>/dev/null)/pkgfs.conf"
246 if [ ! -f "$config_file" ]; then
247 echo "$(basename $0): cannot find configuration file"
248 echo "Please speficify it, e.g: $(basename $0) /path/to/pkgfs.conf"
249 exit 1
253 read_parameters
254 exit $?