CRUX-ARM : Home

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