1 #!/bin/bash
2 #
3 # pkgutils
4 #
5 # Copyright (c) 2000-2005 Per Liden
6 # Copyright (c) 2006-2017 by CRUX team (http://crux.nu)
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 ##
25 # error codes
26 E_GENERAL=1
27 E_PKGFILE=2 # invalid Pkgfile
28 E_DIR_PERM=3 # (source/build) directory missing or missing read/write permission
29 E_DOWNLOAD=4 # error during download
30 E_UNPACK=5 # error during unpacking of source file(s)
31 E_MD5=6 # md5sum verification failed
32 E_FOOTPRINT=7 # footprint check failure
33 E_BUILD=8 # error while running 'build()'
34 E_INSTALL=9 # error while installing the package via 'pkgadd'
35 E_SIGNATURE=10 # error verifying the signature
36
37 info() {
38 echo "=======> $1"
39 }
40
41 warning() {
42 info "WARNING: $1" >&2
43 }
44
45 error() {
46 info "ERROR: $1" >&2
47 }
48
49 get_filename() {
50 local ABSOLUTE=""
51 if [ "$1" = "-a" ]; then
52 ABSOLUTE=1
53 shift
54 fi
55
56 if [[ $1 =~ ^(http|https|ftp|file)://.*/(.+) ]]; then
57 echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}"
58 else
59 if [ "$ABSOLUTE" ]; then
60 echo $PKGMK_ROOT/$1
61 else
62 echo $1
63 fi
64 fi
65 }
66
67 get_basename() {
68 local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
69 echo $FILE
70 }
71
72 check_pkgfile() {
73 if [ ! "$name" ]; then
74 error "Variable 'name' not specified in $PKGMK_PKGFILE."
75 exit $E_PKGFILE
76 elif [ ! "$version" ]; then
77 error "Variable 'version' not specified in $PKGMK_PKGFILE."
78 exit $E_PKGFILE
79 elif [ ! "$release" ]; then
80 error "Variable 'release' not specified in $PKGMK_PKGFILE."
81 exit $E_PKGFILE
82 elif [ "`type -t build`" != "function" ]; then
83 error "Function 'build' not specified in $PKGMK_PKGFILE."
84 exit $E_PKGFILE
85 fi
86 }
87
88 check_directory() {
89 if [ ! -d $1 ]; then
90 error "Directory '$1' does not exist."
91 exit $E_DIR_PERM
92 elif [ ! -w $1 ]; then
93 error "Directory '$1' not writable."
94 exit $E_DIR_PERM
95 elif [ ! -x $1 ] || [ ! -r $1 ]; then
96 error "Directory '$1' not readable."
97 exit $E_DIR_PERM
98 fi
99 }
100
101 check_file() {
102 if [ -e $1 ] && [ ! -w $1 ]; then
103 error "File '$1' is not writable."
104 exit 1
105 fi
106 }
107
108 download_file() {
109 info "Downloading '$1'."
110
111 PKGMK_DOWNLOAD_PROG=${PKGMK_DOWNLOAD_PROG:-wget}
112 if [ ! "`type -p ${PKGMK_DOWNLOAD_PROG}`" ]; then
113 error "Command '${PKGMK_DOWNLOAD_PROG}' not found."
114 exit $E_GENERAL
115 fi
116
117 LOCAL_FILENAME=`get_filename $1`
118 LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial"
119
120 case ${PKGMK_DOWNLOAD_PROG} in
121 curl)
122 RESUME_CMD="-C -"
123 DOWNLOAD_OPTS="-L --fail --ftp-pasv --retry 3 --retry-delay 3 \
124 -o $LOCAL_FILENAME_PARTIAL $PKGMK_CURL_OPTS"
125 ;;
126 wget)
127 RESUME_CMD="-c"
128 DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \
129 --directory-prefix=$PKGMK_SOURCE_DIR \
130 --output-document=$LOCAL_FILENAME_PARTIAL $PKGMK_WGET_OPTS"
131 ;;
132 esac
133
134 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
135 info "Partial download found, trying to resume"
136 RESUME_OPTS="$RESUME_CMD"
137 fi
138
139 error=1
140
141 BASENAME=`get_basename $1`
142 for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do
143 REPO="`echo $REPO | sed 's|/$||'`"
144 $PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $REPO/$BASENAME
145 error=$?
146 if [ $error == 0 ]; then
147 break
148 fi
149 done
150
151 if [ $error != 0 ]; then
152 while true; do
153 $PKGMK_DOWNLOAD_PROG $DOWNLOAD_OPTS $RESUME_OPTS $1
154 error=$?
155 if [ $error != 0 ] && [ "$RESUME_OPTS" ]; then
156 info "Partial download failed, restarting"
157 rm -f "$LOCAL_FILENAME_PARTIAL"
158 RESUME_OPTS=""
159 else
160 break
161 fi
162 done
163 fi
164
165 if [ $error != 0 -o ! -f "$LOCAL_FILENAME_PARTIAL" ]; then
166 error "Downloading '$1' failed."
167 exit $E_DOWNLOAD
168 fi
169
170 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
171 }
172
173 download_source() {
174 local FILE LOCAL_FILENAME
175
176 for FILE in ${source[@]}; do
177 LOCAL_FILENAME=`get_filename $FILE`
178 if [ ! -e $LOCAL_FILENAME ]; then
179 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
180 error "Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
181 exit $E_DOWNLOAD
182 else
183 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
184 download_file $FILE
185 else
186 error "Source file '$LOCAL_FILENAME' not found (use option -d to download)."
187 exit $E_DOWNLOAD
188 fi
189 fi
190 fi
191 done
192 }
193
194 unpack_source() {
195 local FILE LOCAL_FILENAME COMMAND
196
197 for FILE in ${source[@]}; do
198 LOCAL_FILENAME=`get_filename $FILE`
199 case $LOCAL_FILENAME in
200 *.tar|*.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.tar.lz|*.zip|*.rpm|*.7z)
201 COMMAND="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
202 *)
203 COMMAND="cp $LOCAL_FILENAME $SRC" ;;
204 esac
205
206 echo "$COMMAND"
207
208 $COMMAND
209
210 if [ $? != 0 ]; then
211 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
212 rm -rf $PKGMK_WORK_DIR
213 fi
214 error "Building '$TARGET' failed."
215 exit $E_UNPACK
216 fi
217 done
218 }
219
220 make_md5sum() {
221 local FILE LOCAL_FILENAMES
222
223 if [ "$source" ]; then
224 for FILE in ${source[@]}; do
225 LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`"
226 done
227
228 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
229 fi
230 }
231
232 make_footprint() {
233 pkginfo --footprint $TARGET | \
234 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
235 sort -k 3
236 }
237
238 check_md5sum() {
239 local FILE="$PKGMK_WORK_DIR/.tmp"
240
241 cd $PKGMK_ROOT
242
243 if [ -f $PKGMK_MD5SUM ]; then
244 make_md5sum > $FILE.md5sum
245 sort -k 2 $PKGMK_MD5SUM > $FILE.md5sum.orig
246 diff -w -t -U 0 $FILE.md5sum.orig $FILE.md5sum | \
247 sed '/^@@/d' | \
248 sed '/^+++/d' | \
249 sed '/^---/d' | \
250 sed 's/^+/NEW /g' | \
251 sed 's/^-/MISSING /g' > $FILE.md5sum.diff
252 if [ -s $FILE.md5sum.diff ]; then
253 error "Md5sum mismatch found:"
254 cat $FILE.md5sum.diff >&2
255
256 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
257 rm -rf $PKGMK_WORK_DIR
258 fi
259
260 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
261 error "Md5sum not ok."
262 exit $E_MD5
263 fi
264
265 error "Building '$TARGET' failed."
266 exit $E_MD5
267 fi
268 else
269 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
270 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
271 rm -rf $PKGMK_WORK_DIR
272 fi
273 info "Md5sum not found."
274 exit $E_MD5
275 fi
276
277 warning "Md5sum not found, creating new."
278 make_md5sum > $PKGMK_MD5SUM
279 fi
280
281 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
282 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
283 rm -rf $PKGMK_WORK_DIR
284 fi
285 info "Md5sum ok."
286 exit 0
287 fi
288 }
289
290 # requires a previous call of make_work_dir()
291 check_signature() {
292 local RESULT=0
293 local PUBKEY=""
294
295 if [ -f $PKGMK_ROOT/$PKGMK_SIGNATURE ]; then
296 cd $SRC
297 for FILE in "$PKGMK_PKGFILE" "$PKGMK_FOOTPRINT" ${source[@]}; do
298 ln -s $(get_filename -a $FILE) .
299 done
300
301 if [ "$PKGMK_PUBLICKEY" ]; then
302 err=$(signify -q -C -p "$PKGMK_PUBLICKEY" -x "$PKGMK_ROOT/$PKGMK_SIGNATURE" 2>&1)
303 else
304 err=$(signify -q -C -x "$PKGMK_ROOT/$PKGMK_SIGNATURE" 2>&1)
305 fi
306
307 RESULT=$?
308 cd $PKGMK_ROOT
309
310 if [ $RESULT -ne 0 ]; then
311 if [ "$err" = "signify: signature verification failed" ]; then
312 error "Failed verifying cryptographic digest"
313 else
314 error "Signature mismatch found:"
315 echo "$err" | while read n; do echo 'MISMATCH '${n%%:*}; done
316 fi
317
318 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
319 rm -rf $PKGMK_WORK_DIR
320 fi
321
322 error "Building '$TARGET' failed."
323 exit $E_SIGNATURE
324 #else
325 #info "Signature verification succeeded."
326 fi
327 else
328 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ] && [ "$PKGMK_CHECK_SIGNATURE" = "no" ]; then
329 warning "Signature file not found, falling back to old md5sum checking."
330 return 1;
331 fi
332 if [ "$PKGMK_CHECK_SIGNATURE" = "yes" ]; then
333 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
334 rm -rf $PKGMK_WORK_DIR
335 fi
336 info "Signature not found."
337 exit $E_SIGNATURE
338 fi
339
340 warning "Signature not found, creating new."
341 cd $PKGMK_ROOT
342 make_signature
343 fi
344
345 if [ "$PKGMK_CHECK_SIGNATURE" = "yes" ]; then
346 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
347 rm -rf $PKGMK_WORK_DIR
348 fi
349 info "Signature ok."
350 exit 0
351 fi
352
353 # remove soft links
354 find $SRC -maxdepth 1 -mindepth 1 -type l -delete
355 return 0
356 }
357
358 make_signature() {
359 local FILE LOCAL_FILENAMES
360 local REPO
361
362 for FILE in "$PKGMK_PKGFILE" "$PKGMK_FOOTPRINT" ${source[@]}; do
363 LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`"
364 done
365
366 if [ ! "$PKGMK_PRIVATEKEY" ]; then
367 REPO=${PWD%/*}
368 REPO=${REPO##*/}
369 REPO=${REPO%.git}
370 fi
371
372 if [ "$REPO" ]; then
373 PKGMK_PRIVATEKEY="/etc/ports/${REPO}.sec"
374 fi
375
376 sha256sum --tag $LOCAL_FILENAMES | sed 's|^SHA256 (.*/\(.*\))\(.* = .*\)|SHA256 (\1)\2|' | \
377 signify -S -e -x - -q -s "$PKGMK_PRIVATEKEY" -m - > ${PKGMK_SIGNATURE}.tmp
378
379 if [ $? -ne 0 ]; then
380 rm ${PKGMK_SIGNATURE}.tmp
381 error "Creating signature failed"
382 exit $E_SIGNATURE
383 else
384 mv ${PKGMK_SIGNATURE}.tmp ${PKGMK_SIGNATURE}
385 fi
386 }
387
388 refresh_signature() {
389 if [ ! "$PKGMK_PRIVATEKEY" ]; then
390 REPO=${PWD%/*}
391 REPO=${REPO##*/}
392 REPO=${REPO%.git}
393 fi
394
395 if [ "$REPO" ]; then
396 PKGMK_PRIVATEKEY="/etc/ports/${REPO}.sec"
397 fi
398
399 tail -n +3 ${PKGMK_SIGNATURE} | \
400 signify -S -e -x - -q -s "$PKGMK_PRIVATEKEY" -m - > ${PKGMK_SIGNATURE}.tmp
401
402 if [ $? -ne 0 ]; then
403 rm ${PKGMK_SIGNATURE}.tmp
404 error "Refreshing signature failed"
405 exit $E_SIGNATURE
406 else
407 mv ${PKGMK_SIGNATURE}.tmp ${PKGMK_SIGNATURE}
408 fi
409 }
410
411 strip_files() {
412 local FILE FILTER
413
414 cd $PKG
415
416 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
417 FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
418 else
419 FILTER="cat"
420 fi
421
422 find . -type f -printf "%P\n" | $FILTER | while read FILE; do
423 case $(file -b "$FILE") in
424 *ELF*executable*not\ stripped*)
425 strip --strip-all "$FILE"
426 ;;
427 *ELF*shared\ object*not\ stripped*)
428 strip --strip-unneeded "$FILE"
429 ;;
430 current\ ar\ archive)
431 strip --strip-debug "$FILE"
432 esac
433 done
434 }
435
436 compress_manpages() {
437 local FILE DIR TARGET
438
439 cd $PKG
440
441 find . -type f -path "*/man/man*/*" | while read FILE; do
442 if [ "$FILE" = "${FILE%%.gz}" ]; then
443 gzip -9 "$FILE"
444 fi
445 done
446
447 find . -type l -path "*/man/man*/*" | while read FILE; do
448 TARGET=`readlink -n "$FILE"`
449 TARGET="${TARGET##*/}"
450 TARGET="${TARGET%%.gz}.gz"
451 rm -f "$FILE"
452 FILE="${FILE%%.gz}.gz"
453 DIR=`dirname "$FILE"`
454
455 if [ -e "$DIR/$TARGET" ]; then
456 ln -sf "$TARGET" "$FILE"
457 fi
458 done
459 }
460
461 check_footprint() {
462 local FILE="$PKGMK_WORK_DIR/.tmp"
463
464 cd $PKGMK_ROOT
465
466 if [ -f $TARGET ]; then
467 make_footprint > $FILE.footprint
468 if [ -f $PKGMK_FOOTPRINT ]; then
469 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
470 diff -w -t -U 0 $FILE.footprint.orig $FILE.footprint | \
471 sed '/^@@/d' | \
472 sed '/^+++/d' | \
473 sed '/^---/d' | \
474 sed 's/^+/NEW /g' | \
475 sed 's/^-/MISSING /g' > $FILE.footprint.diff
476 if [ -s $FILE.footprint.diff ]; then
477 if [ "$PKGMK_IGNORE_NEW" = "yes" ] && \
478 [ -z "$(egrep -l ^MISSING $FILE.footprint.diff)" ] ; then
479 info "New files found:"
480 else
481 error "Footprint mismatch found:"
482 BUILD_SUCCESSFUL="no"
483 fi
484 cat $FILE.footprint.diff >&2
485 fi
486 else
487 warning "Footprint not found, creating new."
488 mv $FILE.footprint $PKGMK_FOOTPRINT
489 fi
490 else
491 error "Package '$TARGET' was not found."
492 BUILD_SUCCESSFUL="no"
493 fi
494 }
495
496 make_work_dir() {
497 export PKG="$PKGMK_WORK_DIR/pkg"
498 export SRC="$PKGMK_WORK_DIR/src"
499 umask 022
500
501 cd $PKGMK_ROOT
502 remove_work_dir
503 mkdir -p $SRC $PKG
504
505 if [ "$PKGMK_IGNORE_SIGNATURE" = "no" ] || [ "$PKGMK_CHECK_SIGNATURE" = "yes" ]; then
506 test -f $PKGMK_SIGNATURE && cp $PKGMK_SIGNATURE $PKGMK_WORK_DIR
507 if check_signature && test ! -f $PKGMK_MD5SUM
508 then
509 return 0
510 fi
511 fi
512 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
513 check_md5sum
514 fi
515 }
516
517 remove_work_dir() {
518 rm -rf $PKGMK_WORK_DIR
519 }
520
521
522 build_package() {
523 local BUILD_SUCCESSFUL="no"
524 local COMPRESSION
525
526 check_file "$TARGET"
527 make_work_dir
528
529 if [ "$UID" != "0" ]; then
530 warning "Packages should be built as root."
531 fi
532
533 info "Building '$TARGET'."
534
535 unpack_source
536
537 cd $SRC
538 (set -e -x ; build)
539
540 if [ $? = 0 ]; then
541 if [ "$PKGMK_NO_STRIP" = "no" ]; then
542 strip_files
543 fi
544
545 compress_manpages
546
547 cd $PKG
548 info "Build result:"
549
550 case $PKGMK_COMPRESSION_MODE in
551 gz) COMPRESSION="-z" ;;
552 bz2) COMPRESSION="-j" ;;
553 xz) COMPRESSION="-J" ;;
554 esac
555 bsdtar -c $COMPRESSION -f $TARGET * && bsdtar -t -v -f $TARGET
556
557 if [ $? = 0 ]; then
558 BUILD_SUCCESSFUL="yes"
559
560 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
561 warning "Footprint ignored."
562 else
563 check_footprint
564 fi
565 fi
566 fi
567
568 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
569 remove_work_dir
570 fi
571
572 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
573 info "Building '$TARGET' succeeded."
574 else
575 if [ -f $TARGET ]; then
576 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null
577 fi
578 error "Building '$TARGET' failed."
579 exit 1
580 fi
581 }
582
583 install_package() {
584 local COMMAND
585
586 info "Installing '$TARGET'."
587
588 if [ "$PKGMK_INSTALL" = "install" ]; then
589 COMMAND="pkgadd $TARGET"
590 else
591 COMMAND="pkgadd -u $TARGET"
592 fi
593
594 cd $PKGMK_ROOT
595 echo "$COMMAND"
596 $COMMAND
597
598 if [ $? = 0 ]; then
599 info "Installing '$TARGET' succeeded."
600 else
601 error "Installing '$TARGET' failed."
602 exit 1
603 fi
604 }
605
606 recursive() {
607 local ARGS FILE DIR
608
609 ARGS=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
610
611 for FILE in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
612 DIR="`dirname $FILE`/"
613 if [ -d $DIR ]; then
614 info "Entering directory '$DIR'."
615 (cd $DIR && $PKGMK_COMMAND $ARGS)
616 info "Leaving directory '$DIR'."
617 fi
618 done
619 }
620
621 clean() {
622 local FILE LOCAL_FILENAME
623
624 if [ -f $TARGET ]; then
625 info "Removing $TARGET"
626 rm -f $TARGET
627 fi
628
629 for FILE in ${source[@]}; do
630 LOCAL_FILENAME=`get_filename $FILE`
631 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
632 info "Removing $LOCAL_FILENAME"
633 rm -f $LOCAL_FILENAME
634 fi
635 done
636 }
637
638 update_footprint() {
639 if [ ! -f $TARGET ]; then
640 error "Unable to update footprint. File '$TARGET' not found."
641 exit 1
642 fi
643
644 check_file "$PKGMK_FOOTPRINT"
645 make_footprint > $PKGMK_FOOTPRINT
646 touch $TARGET
647
648 info "Footprint updated."
649 }
650
651 build_needed() {
652 local FILE RESULT
653
654 RESULT="yes"
655 if [ -f $TARGET ]; then
656 RESULT="no"
657 for FILE in $PKGMK_PKGFILE ${source[@]}; do
658 FILE=`get_filename $FILE`
659 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
660 RESULT="yes"
661 break
662 fi
663 done
664 fi
665
666 echo $RESULT
667 }
668
669 interrupted() {
670 echo ""
671 error "Interrupted."
672
673 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
674 rm -rf $PKGMK_WORK_DIR
675 fi
676
677 exit 1
678 }
679
680 print_help() {
681 echo "usage: `basename $PKGMK_COMMAND` [options]"
682 echo "options:"
683 echo " -i, --install build and install package"
684 echo " -u, --upgrade build and install package (as upgrade)"
685 echo " -r, --recursive search for and build packages recursively"
686 echo " -d, --download download missing source file(s)"
687 echo " -do, --download-only do not build, only download missing source file(s)"
688 echo " -eo, --extract-only do not build, only extract source file(s)"
689 echo " -utd, --up-to-date do not build, only check if package is up to date"
690 echo " -uf, --update-footprint update footprint using result from last build"
691 echo " -if, --ignore-footprint build package without checking footprint"
692 echo " -in, --ignore-new build package, ignore new files in a footprint missmatch"
693 echo " -um, --update-md5sum update md5sum"
694 echo " -im, --ignore-md5sum build package without checking md5sum"
695 echo " -cm, --check-md5sum do not build, only check md5sum"
696 echo " -us, --update-signature update signature including sha256 checksums"
697 echo " -cs, --check-signature check the validity of the port files"
698 echo " -is, --ignore-signature build package without checking the signature"
699 echo " -rs, --refresh-signature create new signature and keep existing sha256 checksums"
700 echo " -sk, --secret-key <file> use <file> to sign the port"
701 echo " -pk, --public-key <file> check the port signature using public-key <file>"
702 echo " -ns, --no-strip do not strip executable binaries or libraries"
703 echo " -f, --force build package even if it appears to be up to date"
704 echo " -c, --clean remove package and downloaded files"
705 echo " -kw, --keep-work keep temporary working directory"
706 echo " -cf, --config-file <file> use alternative configuration file"
707 echo " -v, --version print version and exit"
708 echo " -h, --help print help and exit"
709 }
710
711 parse_options() {
712 while [ "$1" ]; do
713 case $1 in
714 -i|--install)
715 PKGMK_INSTALL="install" ;;
716 -u|--upgrade)
717 PKGMK_INSTALL="upgrade" ;;
718 -r|--recursive)
719 PKGMK_RECURSIVE="yes" ;;
720 -d|--download)
721 PKGMK_DOWNLOAD="yes" ;;
722 -do|--download-only)
723 PKGMK_DOWNLOAD="yes"
724 PKGMK_DOWNLOAD_ONLY="yes" ;;
725 -eo|--extract-only)
726 PKGMK_EXTRACT_ONLY="yes" ;;
727 -utd|--up-to-date)
728 PKGMK_UP_TO_DATE="yes" ;;
729 -uf|--update-footprint)
730 PKGMK_UPDATE_FOOTPRINT="yes" ;;
731 -if|--ignore-footprint)
732 PKGMK_IGNORE_FOOTPRINT="yes" ;;
733 -in|--ignore-new)
734 PKGMK_IGNORE_NEW="yes" ;;
735 -um|--update-md5sum)
736 PKGMK_UPDATE_MD5SUM="yes" ;;
737 -im|--ignore-md5sum)
738 PKGMK_IGNORE_MD5SUM="yes" ;;
739 -cm|--check-md5sum)
740 PKGMK_CHECK_MD5SUM="yes" ;;
741 -us|--update-signature)
742 PKGMK_UPDATE_SIGNATURE="yes" ;;
743 -cs|--check-signature)
744 PKGMK_CHECK_SIGNATURE="yes" ;;
745 -is|--ignore-signature)
746 PKGMK_IGNORE_SIGNATURE="yes" ;;
747 -rs|--referesh-signature)
748 PKGMK_REFRESH_SIGNATURE="yes" ;;
749 -ns|--no-strip)
750 PKGMK_NO_STRIP="yes" ;;
751 -f|--force)
752 PKGMK_FORCE="yes" ;;
753 -c|--clean)
754 PKGMK_CLEAN="yes" ;;
755 -kw|--keep-work)
756 PKGMK_KEEP_WORK="yes" ;;
757 -pk|--public-key)
758 if [ ! "$2" ]; then
759 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
760 exit 1
761 fi
762 PKGMK_PUBLICKEY="$2"
763 shift ;;
764 -sk|--secret-key)
765 if [ ! "$2" ]; then
766 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
767 exit 1
768 fi
769 PKGMK_PRIVATEKEY="$2"
770 shift ;;
771 -cf|--config-file)
772 if [ ! "$2" ]; then
773 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
774 exit 1
775 fi
776 PKGMK_CONFFILE="$2"
777 shift ;;
778 -v|--version)
779 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
780 exit 0 ;;
781 -h|--help)
782 print_help
783 exit 0 ;;
784 *)
785 echo "`basename $PKGMK_COMMAND`: invalid option $1"
786 exit 1 ;;
787 esac
788 shift
789 done
790 }
791
792 main() {
793 # multilib
794 PKGMK_ARCH=64
795 if [ -f ".32bit" ]; then
796 PKGMK_ARCH=32
797 fi
798
799 local FILE TARGET
800
801 parse_options "$@"
802
803 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
804 recursive "$@"
805 exit 0
806 fi
807
808 for FILE in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
809 if [ ! -f $FILE ]; then
810 error "File '$FILE' not found."
811 exit 1
812 fi
813 . $FILE
814 done
815
816 check_directory "$PKGMK_SOURCE_DIR"
817 check_directory "$PKGMK_PACKAGE_DIR"
818 check_directory "`dirname $PKGMK_WORK_DIR`"
819
820 check_pkgfile
821
822 case $PKGMK_COMPRESSION_MODE in
823 gz|bz2|xz)
824 TARGET="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.$PKGMK_COMPRESSION_MODE"
825 ;;
826 *)
827 error "Compression mode '$PKGMK_COMPRESSION_MODE' not supported"
828 exit 1
829 ;;
830 esac
831
832 if [ "$PKGMK_CLEAN" = "yes" ]; then
833 clean
834 exit 0
835 fi
836
837 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
838 update_footprint
839 exit 0
840 fi
841
842 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
843 download_source
844 check_file "$PKGMK_MD5SUM"
845 make_md5sum > $PKGMK_MD5SUM
846 info "Md5sum updated."
847 exit 0
848 fi
849
850 if [ "$PKGMK_UPDATE_SIGNATURE" = "yes" ]; then
851 download_source
852 check_file "$PKGMK_SIGNATURE"
853 make_signature
854 info "Signature updated."
855 exit 0
856 fi
857
858 if [ "$PKGMK_REFRESH_SIGNATURE" = "yes" ]; then
859 check_file "$PKGMK_SIGNATURE"
860 refresh_signature
861 info "Signature refreshed."
862 exit 0
863 fi
864
865 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
866 download_source
867 exit 0
868 fi
869
870 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
871 download_source
872 make_work_dir
873 info "Extracting sources of package '$name-$version'."
874 unpack_source
875 exit 0
876 fi
877
878 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
879 if [ "`build_needed`" = "yes" ]; then
880 info "Package '$TARGET' is not up to date."
881 else
882 info "Package '$TARGET' is up to date."
883 fi
884 exit 0
885 fi
886
887 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ] && [ "$PKGMK_CHECK_SIGNATURE" = "no" ]; then
888 info "Package '$TARGET' is up to date."
889 else
890 download_source
891 build_package
892 fi
893
894 if [ "$PKGMK_INSTALL" != "no" ]; then
895 install_package
896 fi
897
898 exit 0
899 }
900
901 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
902
903 export LC_ALL=POSIX
904
905 readonly PKGMK_VERSION="#VERSION#"
906 readonly PKGMK_COMMAND="$0"
907 readonly PKGMK_ROOT="$PWD"
908
909 PKGMK_CONFFILE="/etc/pkgmk.conf"
910 PKGMK_PKGFILE="Pkgfile"
911 PKGMK_FOOTPRINT=".footprint"
912 PKGMK_MD5SUM=".md5sum"
913 PKGMK_NOSTRIP=".nostrip"
914 PKGMK_SIGNATURE=".signature"
915
916 PKGMK_SOURCE_MIRRORS=()
917 PKGMK_SOURCE_DIR="$PWD"
918 PKGMK_PACKAGE_DIR="$PWD"
919 PKGMK_WORK_DIR="$PWD/work"
920
921 PKGMK_COMPRESSION_MODE="gz"
922
923 PKGMK_INSTALL="no"
924 PKGMK_RECURSIVE="no"
925 PKGMK_DOWNLOAD="no"
926 PKGMK_DOWNLOAD_ONLY="no"
927 PKGMK_EXTRACT_ONLY="no"
928 PKGMK_UP_TO_DATE="no"
929 PKGMK_UPDATE_FOOTPRINT="no"
930 PKGMK_IGNORE_FOOTPRINT="no"
931 PKGMK_IGNORE_NEW="no"
932 PKGMK_FORCE="no"
933 PKGMK_KEEP_WORK="no"
934 PKGMK_UPDATE_MD5SUM="no"
935 PKGMK_IGNORE_MD5SUM="no"
936 PKGMK_CHECK_MD5SUM="no"
937 PKGMK_UPDATE_SIGNATURE="no"
938 PKGMK_IGNORE_SIGNATURE="no"
939 PKGMK_CHECK_SIGNATURE="no"
940 PKGMK_REFRESH_SIGNATURE="no"
941 PKGMK_PRIVATEKEY=""
942 PKGMK_NO_STRIP="no"
943 PKGMK_CLEAN="no"
944
945 main "$@"
946
947 # End of file
|