Commit | Line | Data |
---|---|---|
9ac667e6 SR |
1 | #!/bin/bash |
2 | # | |
3 | # pkgutils | |
4 | # | |
5 | # Copyright (c) 2000-2005 Per Liden | |
6fe55c25 | 6 | # Copyright (c) 2006-2007 by CRUX team (http://crux.nu) |
9ac667e6 SR |
7 | # |
8 | # This program is free software; you can redistribute it and/or modify | |
9 | # it under the terms of the GNU General Public License as published by | |
10 | # the Free Software Foundation; either version 2 of the License, or | |
11 | # (at your option) any later version. | |
12 | # | |
13 | # This program is distributed in the hope that it will be useful, | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
19 | # along with this program; if not, write to the Free Software | |
20 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
21 | # USA. | |
22 | # | |
23 | ||
24 | info() { | |
25 | echo "=======> $1" | |
26 | } | |
27 | ||
28 | warning() { | |
e55714dd | 29 | info "WARNING: $1" >&2 |
9ac667e6 SR |
30 | } |
31 | ||
32 | error() { | |
e55714dd | 33 | info "ERROR: $1" >&2 |
9ac667e6 SR |
34 | } |
35 | ||
36 | get_filename() { | |
7b3f9929 JD |
37 | if [[ $1 =~ ^(http|https|ftp|file)://.*/(.+) ]]; then |
38 | echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}" | |
39 | else | |
40 | echo $1 | |
9ac667e6 | 41 | fi |
9ac667e6 SR |
42 | } |
43 | ||
2dee8e17 MH |
44 | get_basename() { |
45 | local FILE="`echo $1 | sed 's|^.*://.*/||g'`" | |
46 | echo $FILE | |
47 | } | |
48 | ||
9ac667e6 SR |
49 | check_pkgfile() { |
50 | if [ ! "$name" ]; then | |
51 | error "Variable 'name' not specified in $PKGMK_PKGFILE." | |
52 | exit 1 | |
53 | elif [ ! "$version" ]; then | |
54 | error "Variable 'version' not specified in $PKGMK_PKGFILE." | |
55 | exit 1 | |
56 | elif [ ! "$release" ]; then | |
57 | error "Variable 'release' not specified in $PKGMK_PKGFILE." | |
58 | exit 1 | |
59 | elif [ "`type -t build`" != "function" ]; then | |
60 | error "Function 'build' not specified in $PKGMK_PKGFILE." | |
61 | exit 1 | |
62 | fi | |
63 | } | |
64 | ||
65 | check_directory() { | |
66 | if [ ! -d $1 ]; then | |
67 | error "Directory '$1' does not exist." | |
68 | exit 1 | |
69 | elif [ ! -w $1 ]; then | |
70 | error "Directory '$1' not writable." | |
71 | exit 1 | |
72 | elif [ ! -x $1 ] || [ ! -r $1 ]; then | |
73 | error "Directory '$1' not readable." | |
74 | exit 1 | |
75 | fi | |
76 | } | |
77 | ||
de428c29 JD |
78 | check_file() { |
79 | if [ -e $1 ] && [ ! -w $1 ]; then | |
80 | error "File '$1' is not writable." | |
81 | exit 1 | |
82 | fi | |
83 | } | |
84 | ||
9ac667e6 SR |
85 | download_file() { |
86 | info "Downloading '$1'." | |
87 | ||
88 | if [ ! "`type -p wget`" ]; then | |
89 | error "Command 'wget' not found." | |
90 | exit 1 | |
91 | fi | |
92 | ||
93 | LOCAL_FILENAME=`get_filename $1` | |
94 | LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial" | |
2dee8e17 MH |
95 | DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \ |
96 | --directory-prefix=$PKGMK_SOURCE_DIR \ | |
765b5014 | 97 | --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate" |
9ac667e6 SR |
98 | |
99 | if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then | |
100 | info "Partial download found, trying to resume" | |
101 | RESUME_CMD="-c" | |
102 | fi | |
103 | ||
2dee8e17 MH |
104 | error=1 |
105 | ||
106 | BASENAME=`get_basename $1` | |
107 | for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do | |
108 | REPO="`echo $REPO | sed 's|/$||'`" | |
51c534c2 | 109 | wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME |
9ac667e6 | 110 | error=$? |
2dee8e17 | 111 | if [ $error == 0 ]; then |
9ac667e6 SR |
112 | break |
113 | fi | |
114 | done | |
2dee8e17 MH |
115 | |
116 | if [ $error != 0 ]; then | |
117 | while true; do | |
51c534c2 | 118 | wget $RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1 |
2dee8e17 MH |
119 | error=$? |
120 | if [ $error != 0 ] && [ "$RESUME_CMD" ]; then | |
121 | info "Partial download failed, restarting" | |
122 | rm -f "$LOCAL_FILENAME_PARTIAL" | |
123 | RESUME_CMD="" | |
124 | else | |
125 | break | |
126 | fi | |
127 | done | |
128 | fi | |
9ac667e6 SR |
129 | |
130 | if [ $error != 0 ]; then | |
131 | error "Downloading '$1' failed." | |
132 | exit 1 | |
133 | fi | |
134 | ||
135 | mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME" | |
136 | } | |
137 | ||
138 | download_source() { | |
139 | local FILE LOCAL_FILENAME | |
140 | ||
141 | for FILE in ${source[@]}; do | |
142 | LOCAL_FILENAME=`get_filename $FILE` | |
143 | if [ ! -e $LOCAL_FILENAME ]; then | |
144 | if [ "$LOCAL_FILENAME" = "$FILE" ]; then | |
145 | error "Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)." | |
146 | exit 1 | |
147 | else | |
148 | if [ "$PKGMK_DOWNLOAD" = "yes" ]; then | |
149 | download_file $FILE | |
150 | else | |
151 | error "Source file '$LOCAL_FILENAME' not found (use option -d to download)." | |
152 | exit 1 | |
153 | fi | |
154 | fi | |
155 | fi | |
156 | done | |
157 | } | |
158 | ||
159 | unpack_source() { | |
160 | local FILE LOCAL_FILENAME COMMAND | |
161 | ||
162 | for FILE in ${source[@]}; do | |
163 | LOCAL_FILENAME=`get_filename $FILE` | |
164 | case $LOCAL_FILENAME in | |
5228efc2 | 165 | *.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm) |
698c42e2 | 166 | COMMAND="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;; |
9ac667e6 SR |
167 | *) |
168 | COMMAND="cp $LOCAL_FILENAME $SRC" ;; | |
169 | esac | |
170 | ||
171 | echo "$COMMAND" | |
172 | ||
173 | $COMMAND | |
174 | ||
175 | if [ $? != 0 ]; then | |
176 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
177 | rm -rf $PKGMK_WORK_DIR | |
178 | fi | |
179 | error "Building '$TARGET' failed." | |
180 | exit 1 | |
181 | fi | |
182 | done | |
183 | } | |
184 | ||
185 | make_md5sum() { | |
186 | local FILE LOCAL_FILENAMES | |
187 | ||
188 | if [ "$source" ]; then | |
189 | for FILE in ${source[@]}; do | |
190 | LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`" | |
191 | done | |
192 | ||
193 | md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2 | |
194 | fi | |
195 | } | |
196 | ||
197 | make_footprint() { | |
198 | pkginfo --footprint $TARGET | \ | |
199 | sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \ | |
200 | sort -k 3 | |
201 | } | |
202 | ||
203 | check_md5sum() { | |
204 | local FILE="$PKGMK_WORK_DIR/.tmp" | |
205 | ||
206 | cd $PKGMK_ROOT | |
207 | ||
208 | if [ -f $PKGMK_MD5SUM ]; then | |
209 | make_md5sum > $FILE.md5sum | |
210 | sort -k 2 $PKGMK_MD5SUM > $FILE.md5sum.orig | |
211 | diff -w -t -U 0 $FILE.md5sum.orig $FILE.md5sum | \ | |
212 | sed '/^@@/d' | \ | |
213 | sed '/^+++/d' | \ | |
214 | sed '/^---/d' | \ | |
215 | sed 's/^+/NEW /g' | \ | |
216 | sed 's/^-/MISSING /g' > $FILE.md5sum.diff | |
217 | if [ -s $FILE.md5sum.diff ]; then | |
218 | error "Md5sum mismatch found:" | |
e55714dd | 219 | cat $FILE.md5sum.diff >&2 |
9ac667e6 SR |
220 | |
221 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
222 | rm -rf $PKGMK_WORK_DIR | |
223 | fi | |
224 | ||
225 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then | |
226 | error "Md5sum not ok." | |
227 | exit 1 | |
228 | fi | |
229 | ||
230 | error "Building '$TARGET' failed." | |
231 | exit 1 | |
232 | fi | |
233 | else | |
234 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then | |
235 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
236 | rm -rf $PKGMK_WORK_DIR | |
237 | fi | |
238 | info "Md5sum not found." | |
239 | exit 1 | |
240 | fi | |
241 | ||
242 | warning "Md5sum not found, creating new." | |
243 | make_md5sum > $PKGMK_MD5SUM | |
244 | fi | |
245 | ||
246 | if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then | |
247 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
248 | rm -rf $PKGMK_WORK_DIR | |
249 | fi | |
250 | info "Md5sum ok." | |
251 | exit 0 | |
252 | fi | |
253 | } | |
254 | ||
255 | strip_files() { | |
256 | local FILE FILTER | |
257 | ||
258 | cd $PKG | |
259 | ||
260 | if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then | |
261 | FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP" | |
262 | else | |
263 | FILTER="cat" | |
264 | fi | |
265 | ||
266 | find . -type f -printf "%P\n" | $FILTER | while read FILE; do | |
b0bbde50 SR |
267 | case $(file -b "$FILE") in |
268 | *ELF*executable*not\ stripped) | |
9ac667e6 | 269 | strip --strip-all "$FILE" |
b0bbde50 SR |
270 | ;; |
271 | *ELF*shared\ object*not\ stripped) | |
9ac667e6 | 272 | strip --strip-unneeded "$FILE" |
b0bbde50 SR |
273 | ;; |
274 | current\ ar\ archive) | |
9ac667e6 | 275 | strip --strip-debug "$FILE" |
b0bbde50 | 276 | esac |
9ac667e6 SR |
277 | done |
278 | } | |
279 | ||
280 | compress_manpages() { | |
281 | local FILE DIR TARGET | |
282 | ||
283 | cd $PKG | |
284 | ||
285 | find . -type f -path "*/man/man*/*" | while read FILE; do | |
286 | if [ "$FILE" = "${FILE%%.gz}" ]; then | |
287 | gzip -9 "$FILE" | |
288 | fi | |
289 | done | |
290 | ||
291 | find . -type l -path "*/man/man*/*" | while read FILE; do | |
292 | TARGET=`readlink -n "$FILE"` | |
293 | TARGET="${TARGET##*/}" | |
294 | TARGET="${TARGET%%.gz}.gz" | |
295 | rm -f "$FILE" | |
296 | FILE="${FILE%%.gz}.gz" | |
297 | DIR=`dirname "$FILE"` | |
298 | ||
299 | if [ -e "$DIR/$TARGET" ]; then | |
300 | ln -sf "$TARGET" "$FILE" | |
301 | fi | |
302 | done | |
303 | } | |
304 | ||
305 | check_footprint() { | |
306 | local FILE="$PKGMK_WORK_DIR/.tmp" | |
307 | ||
308 | cd $PKGMK_ROOT | |
309 | ||
310 | if [ -f $TARGET ]; then | |
311 | make_footprint > $FILE.footprint | |
312 | if [ -f $PKGMK_FOOTPRINT ]; then | |
313 | sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig | |
314 | diff -w -t -U 0 $FILE.footprint.orig $FILE.footprint | \ | |
315 | sed '/^@@/d' | \ | |
316 | sed '/^+++/d' | \ | |
317 | sed '/^---/d' | \ | |
318 | sed 's/^+/NEW /g' | \ | |
319 | sed 's/^-/MISSING /g' > $FILE.footprint.diff | |
320 | if [ -s $FILE.footprint.diff ]; then | |
163aacb1 JW |
321 | if [ "$PKGMK_IGNORE_NEW" = "yes" ] && \ |
322 | [ -z "$(egrep -l ^MISSING $FILE.footprint.diff)" ] ; then | |
323 | info "New files found:" | |
324 | else | |
325 | error "Footprint mismatch found:" | |
326 | BUILD_SUCCESSFUL="no" | |
327 | fi | |
e55714dd | 328 | cat $FILE.footprint.diff >&2 |
9ac667e6 SR |
329 | fi |
330 | else | |
331 | warning "Footprint not found, creating new." | |
332 | mv $FILE.footprint $PKGMK_FOOTPRINT | |
333 | fi | |
334 | else | |
335 | error "Package '$TARGET' was not found." | |
336 | BUILD_SUCCESSFUL="no" | |
337 | fi | |
338 | } | |
339 | ||
92dbaab6 | 340 | make_work_dir() { |
9ac667e6 SR |
341 | export PKG="$PKGMK_WORK_DIR/pkg" |
342 | export SRC="$PKGMK_WORK_DIR/src" | |
343 | umask 022 | |
344 | ||
345 | cd $PKGMK_ROOT | |
92dbaab6 | 346 | remove_work_dir |
9ac667e6 | 347 | mkdir -p $SRC $PKG |
92dbaab6 | 348 | |
9ac667e6 SR |
349 | if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then |
350 | check_md5sum | |
351 | fi | |
92dbaab6 JW |
352 | } |
353 | ||
354 | remove_work_dir() { | |
355 | rm -rf $PKGMK_WORK_DIR | |
356 | } | |
357 | ||
358 | ||
359 | build_package() { | |
360 | local BUILD_SUCCESSFUL="no" | |
37c478ef | 361 | local COMPRESSION |
92dbaab6 | 362 | |
de428c29 | 363 | check_file "$TARGET" |
92dbaab6 | 364 | make_work_dir |
9ac667e6 SR |
365 | |
366 | if [ "$UID" != "0" ]; then | |
367 | warning "Packages should be built as root." | |
368 | fi | |
369 | ||
370 | info "Building '$TARGET'." | |
371 | ||
372 | unpack_source | |
373 | ||
374 | cd $SRC | |
375 | (set -e -x ; build) | |
376 | ||
377 | if [ $? = 0 ]; then | |
378 | if [ "$PKGMK_NO_STRIP" = "no" ]; then | |
379 | strip_files | |
380 | fi | |
381 | ||
382 | compress_manpages | |
383 | ||
384 | cd $PKG | |
385 | info "Build result:" | |
37c478ef JD |
386 | |
387 | case $PKGMK_COMPRESSION_MODE in | |
388 | gz) COMPRESSION="-z" ;; | |
389 | bz2) COMPRESSION="-j" ;; | |
390 | xz) COMPRESSION="-J" ;; | |
391 | esac | |
392 | bsdtar -c $COMPRESSION -f $TARGET * && bsdtar -t -v -f $TARGET | |
393 | ||
9ac667e6 SR |
394 | if [ $? = 0 ]; then |
395 | BUILD_SUCCESSFUL="yes" | |
396 | ||
397 | if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then | |
398 | warning "Footprint ignored." | |
399 | else | |
400 | check_footprint | |
401 | fi | |
402 | fi | |
403 | fi | |
404 | ||
405 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
92dbaab6 | 406 | remove_work_dir |
9ac667e6 SR |
407 | fi |
408 | ||
409 | if [ "$BUILD_SUCCESSFUL" = "yes" ]; then | |
410 | info "Building '$TARGET' succeeded." | |
411 | else | |
412 | if [ -f $TARGET ]; then | |
413 | touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null | |
414 | fi | |
415 | error "Building '$TARGET' failed." | |
416 | exit 1 | |
417 | fi | |
418 | } | |
419 | ||
420 | install_package() { | |
421 | local COMMAND | |
422 | ||
423 | info "Installing '$TARGET'." | |
424 | ||
425 | if [ "$PKGMK_INSTALL" = "install" ]; then | |
426 | COMMAND="pkgadd $TARGET" | |
427 | else | |
428 | COMMAND="pkgadd -u $TARGET" | |
429 | fi | |
430 | ||
431 | cd $PKGMK_ROOT | |
432 | echo "$COMMAND" | |
433 | $COMMAND | |
434 | ||
435 | if [ $? = 0 ]; then | |
436 | info "Installing '$TARGET' succeeded." | |
437 | else | |
438 | error "Installing '$TARGET' failed." | |
439 | exit 1 | |
440 | fi | |
441 | } | |
442 | ||
443 | recursive() { | |
444 | local ARGS FILE DIR | |
445 | ||
446 | ARGS=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"` | |
447 | ||
448 | for FILE in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do | |
449 | DIR="`dirname $FILE`/" | |
450 | if [ -d $DIR ]; then | |
451 | info "Entering directory '$DIR'." | |
452 | (cd $DIR && $PKGMK_COMMAND $ARGS) | |
453 | info "Leaving directory '$DIR'." | |
454 | fi | |
455 | done | |
456 | } | |
457 | ||
458 | clean() { | |
459 | local FILE LOCAL_FILENAME | |
460 | ||
461 | if [ -f $TARGET ]; then | |
462 | info "Removing $TARGET" | |
463 | rm -f $TARGET | |
464 | fi | |
465 | ||
466 | for FILE in ${source[@]}; do | |
467 | LOCAL_FILENAME=`get_filename $FILE` | |
468 | if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then | |
469 | info "Removing $LOCAL_FILENAME" | |
470 | rm -f $LOCAL_FILENAME | |
471 | fi | |
472 | done | |
473 | } | |
474 | ||
475 | update_footprint() { | |
476 | if [ ! -f $TARGET ]; then | |
477 | error "Unable to update footprint. File '$TARGET' not found." | |
478 | exit 1 | |
479 | fi | |
480 | ||
de428c29 | 481 | check_file "$PKGMK_FOOTPRINT" |
9ac667e6 SR |
482 | make_footprint > $PKGMK_FOOTPRINT |
483 | touch $TARGET | |
484 | ||
485 | info "Footprint updated." | |
486 | } | |
487 | ||
488 | build_needed() { | |
489 | local FILE RESULT | |
490 | ||
491 | RESULT="yes" | |
492 | if [ -f $TARGET ]; then | |
493 | RESULT="no" | |
494 | for FILE in $PKGMK_PKGFILE ${source[@]}; do | |
495 | FILE=`get_filename $FILE` | |
496 | if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then | |
497 | RESULT="yes" | |
498 | break | |
499 | fi | |
500 | done | |
501 | fi | |
502 | ||
503 | echo $RESULT | |
504 | } | |
505 | ||
506 | interrupted() { | |
507 | echo "" | |
508 | error "Interrupted." | |
509 | ||
510 | if [ "$PKGMK_KEEP_WORK" = "no" ]; then | |
511 | rm -rf $PKGMK_WORK_DIR | |
512 | fi | |
513 | ||
514 | exit 1 | |
515 | } | |
516 | ||
517 | print_help() { | |
518 | echo "usage: `basename $PKGMK_COMMAND` [options]" | |
519 | echo "options:" | |
520 | echo " -i, --install build and install package" | |
521 | echo " -u, --upgrade build and install package (as upgrade)" | |
522 | echo " -r, --recursive search for and build packages recursively" | |
523 | echo " -d, --download download missing source file(s)" | |
524 | echo " -do, --download-only do not build, only download missing source file(s)" | |
92dbaab6 | 525 | echo " -eo, --extract-only do not build, only extract source file(s)" |
9ac667e6 SR |
526 | echo " -utd, --up-to-date do not build, only check if package is up to date" |
527 | echo " -uf, --update-footprint update footprint using result from last build" | |
528 | echo " -if, --ignore-footprint build package without checking footprint" | |
163aacb1 | 529 | echo " -in, --ignore-new build package, ignore new files in a footprint missmatch" |
9ac667e6 SR |
530 | echo " -um, --update-md5sum update md5sum" |
531 | echo " -im, --ignore-md5sum build package without checking md5sum" | |
532 | echo " -cm, --check-md5sum do not build, only check md5sum" | |
533 | echo " -ns, --no-strip do not strip executable binaries or libraries" | |
534 | echo " -f, --force build package even if it appears to be up to date" | |
535 | echo " -c, --clean remove package and downloaded files" | |
536 | echo " -kw, --keep-work keep temporary working directory" | |
537 | echo " -cf, --config-file <file> use alternative configuration file" | |
538 | echo " -v, --version print version and exit " | |
539 | echo " -h, --help print help and exit" | |
540 | } | |
541 | ||
542 | parse_options() { | |
543 | while [ "$1" ]; do | |
544 | case $1 in | |
545 | -i|--install) | |
546 | PKGMK_INSTALL="install" ;; | |
547 | -u|--upgrade) | |
548 | PKGMK_INSTALL="upgrade" ;; | |
549 | -r|--recursive) | |
550 | PKGMK_RECURSIVE="yes" ;; | |
551 | -d|--download) | |
552 | PKGMK_DOWNLOAD="yes" ;; | |
553 | -do|--download-only) | |
554 | PKGMK_DOWNLOAD="yes" | |
555 | PKGMK_DOWNLOAD_ONLY="yes" ;; | |
92dbaab6 JW |
556 | -eo|--extract-only) |
557 | PKGMK_EXTRACT_ONLY="yes" ;; | |
9ac667e6 SR |
558 | -utd|--up-to-date) |
559 | PKGMK_UP_TO_DATE="yes" ;; | |
560 | -uf|--update-footprint) | |
561 | PKGMK_UPDATE_FOOTPRINT="yes" ;; | |
562 | -if|--ignore-footprint) | |
563 | PKGMK_IGNORE_FOOTPRINT="yes" ;; | |
163aacb1 JW |
564 | -in|--ignore-new) |
565 | PKGMK_IGNORE_NEW="yes" ;; | |
9ac667e6 SR |
566 | -um|--update-md5sum) |
567 | PKGMK_UPDATE_MD5SUM="yes" ;; | |
568 | -im|--ignore-md5sum) | |
569 | PKGMK_IGNORE_MD5SUM="yes" ;; | |
570 | -cm|--check-md5sum) | |
571 | PKGMK_CHECK_MD5SUM="yes" ;; | |
572 | -ns|--no-strip) | |
573 | PKGMK_NO_STRIP="yes" ;; | |
574 | -f|--force) | |
575 | PKGMK_FORCE="yes" ;; | |
576 | -c|--clean) | |
577 | PKGMK_CLEAN="yes" ;; | |
578 | -kw|--keep-work) | |
579 | PKGMK_KEEP_WORK="yes" ;; | |
580 | -cf|--config-file) | |
581 | if [ ! "$2" ]; then | |
582 | echo "`basename $PKGMK_COMMAND`: option $1 requires an argument" | |
583 | exit 1 | |
584 | fi | |
585 | PKGMK_CONFFILE="$2" | |
586 | shift ;; | |
587 | -v|--version) | |
588 | echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION" | |
589 | exit 0 ;; | |
590 | -h|--help) | |
591 | print_help | |
592 | exit 0 ;; | |
593 | *) | |
594 | echo "`basename $PKGMK_COMMAND`: invalid option $1" | |
595 | exit 1 ;; | |
596 | esac | |
597 | shift | |
598 | done | |
599 | } | |
600 | ||
601 | main() { | |
602 | local FILE TARGET | |
603 | ||
604 | parse_options "$@" | |
605 | ||
606 | if [ "$PKGMK_RECURSIVE" = "yes" ]; then | |
607 | recursive "$@" | |
608 | exit 0 | |
609 | fi | |
610 | ||
611 | for FILE in $PKGMK_PKGFILE $PKGMK_CONFFILE; do | |
612 | if [ ! -f $FILE ]; then | |
613 | error "File '$FILE' not found." | |
614 | exit 1 | |
615 | fi | |
616 | . $FILE | |
617 | done | |
618 | ||
619 | check_directory "$PKGMK_SOURCE_DIR" | |
620 | check_directory "$PKGMK_PACKAGE_DIR" | |
621 | check_directory "`dirname $PKGMK_WORK_DIR`" | |
622 | ||
623 | check_pkgfile | |
37c478ef JD |
624 | |
625 | case $PKGMK_COMPRESSION_MODE in | |
626 | gz|bz2|xz) | |
627 | TARGET="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.$PKGMK_COMPRESSION_MODE" | |
628 | ;; | |
629 | *) | |
630 | error "Compression mode '$PKGMK_COMPRESSION_MODE' not supported" | |
631 | exit 1 | |
632 | ;; | |
633 | esac | |
634 | ||
9ac667e6 SR |
635 | if [ "$PKGMK_CLEAN" = "yes" ]; then |
636 | clean | |
637 | exit 0 | |
638 | fi | |
639 | ||
640 | if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then | |
641 | update_footprint | |
642 | exit 0 | |
643 | fi | |
644 | ||
645 | if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then | |
646 | download_source | |
de428c29 | 647 | check_file "$PKGMK_MD5SUM" |
9ac667e6 SR |
648 | make_md5sum > $PKGMK_MD5SUM |
649 | info "Md5sum updated." | |
650 | exit 0 | |
651 | fi | |
652 | ||
653 | if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then | |
654 | download_source | |
655 | exit 0 | |
656 | fi | |
657 | ||
92dbaab6 JW |
658 | if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then |
659 | download_source | |
660 | make_work_dir | |
661 | info "Extracting sources of package '$name-$version'." | |
662 | unpack_source | |
663 | exit 0 | |
664 | fi | |
665 | ||
9ac667e6 SR |
666 | if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then |
667 | if [ "`build_needed`" = "yes" ]; then | |
668 | info "Package '$TARGET' is not up to date." | |
669 | else | |
670 | info "Package '$TARGET' is up to date." | |
671 | fi | |
672 | exit 0 | |
673 | fi | |
674 | ||
675 | if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then | |
676 | info "Package '$TARGET' is up to date." | |
677 | else | |
678 | download_source | |
679 | build_package | |
680 | fi | |
681 | ||
682 | if [ "$PKGMK_INSTALL" != "no" ]; then | |
683 | install_package | |
684 | fi | |
685 | ||
686 | exit 0 | |
687 | } | |
688 | ||
689 | trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM | |
690 | ||
691 | export LC_ALL=POSIX | |
692 | ||
693 | readonly PKGMK_VERSION="#VERSION#" | |
694 | readonly PKGMK_COMMAND="$0" | |
695 | readonly PKGMK_ROOT="$PWD" | |
696 | ||
697 | PKGMK_CONFFILE="/etc/pkgmk.conf" | |
698 | PKGMK_PKGFILE="Pkgfile" | |
699 | PKGMK_FOOTPRINT=".footprint" | |
700 | PKGMK_MD5SUM=".md5sum" | |
701 | PKGMK_NOSTRIP=".nostrip" | |
702 | ||
2dee8e17 | 703 | PKGMK_SOURCE_MIRRORS=() |
9ac667e6 SR |
704 | PKGMK_SOURCE_DIR="$PWD" |
705 | PKGMK_PACKAGE_DIR="$PWD" | |
706 | PKGMK_WORK_DIR="$PWD/work" | |
707 | ||
37c478ef JD |
708 | PKGMK_COMPRESSION_MODE="gz" |
709 | ||
9ac667e6 SR |
710 | PKGMK_INSTALL="no" |
711 | PKGMK_RECURSIVE="no" | |
712 | PKGMK_DOWNLOAD="no" | |
713 | PKGMK_DOWNLOAD_ONLY="no" | |
92dbaab6 | 714 | PKGMK_EXTRACT_ONLY="no" |
9ac667e6 SR |
715 | PKGMK_UP_TO_DATE="no" |
716 | PKGMK_UPDATE_FOOTPRINT="no" | |
717 | PKGMK_IGNORE_FOOTPRINT="no" | |
163aacb1 | 718 | PKGMK_IGNORE_NEW="no" |
9ac667e6 SR |
719 | PKGMK_FORCE="no" |
720 | PKGMK_KEEP_WORK="no" | |
721 | PKGMK_UPDATE_MD5SUM="no" | |
722 | PKGMK_IGNORE_MD5SUM="no" | |
723 | PKGMK_CHECK_MD5SUM="no" | |
724 | PKGMK_NO_STRIP="no" | |
725 | PKGMK_CLEAN="no" | |
726 | ||
727 | main "$@" | |
728 | ||
729 | # End of file |