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