5 # Copyright (c) 2000-2005 Per Liden
6 # Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
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.
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.
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,
29 info
"WARNING: $1" >&2
37 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
39 if [ "$FILE" != "$1" ]; then
40 FILE
="$PKGMK_SOURCE_DIR/$FILE"
47 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
52 if [ ! "$name" ]; then
53 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
55 elif [ ! "$version" ]; then
56 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
58 elif [ ! "$release" ]; then
59 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
61 elif [ "`type -t build`" != "function" ]; then
62 error
"Function 'build' not specified in $PKGMK_PKGFILE."
69 error
"Directory '$1' does not exist."
71 elif [ ! -w $1 ]; then
72 error
"Directory '$1' not writable."
74 elif [ ! -x $1 ] || [ ! -r $1 ]; then
75 error
"Directory '$1' not readable."
81 info
"Downloading '$1'."
83 if [ ! "`type -p wget`" ]; then
84 error
"Command 'wget' not found."
88 LOCAL_FILENAME
=`get_filename $1`
89 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
90 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
91 --directory-prefix=$PKGMK_SOURCE_DIR \
92 --output-document=$LOCAL_FILENAME_PARTIAL"
94 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
95 info
"Partial download found, trying to resume"
101 BASENAME
=`get_basename $1`
102 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
103 REPO
="`echo $REPO | sed 's|/$||'`"
104 wget
$RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME
106 if [ $error == 0 ]; then
111 if [ $error != 0 ]; then
113 wget
$RESUME_CMD $DOWNLOAD_OPTS $1
115 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
116 info
"Partial download failed, restarting"
117 rm -f "$LOCAL_FILENAME_PARTIAL"
125 if [ $error != 0 ]; then
126 error
"Downloading '$1' failed."
130 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
134 local FILE LOCAL_FILENAME
136 for FILE
in ${source[@]}; do
137 LOCAL_FILENAME
=`get_filename $FILE`
138 if [ ! -e $LOCAL_FILENAME ]; then
139 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
140 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
143 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
146 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
155 local FILE LOCAL_FILENAME COMMAND
157 for FILE
in ${source[@]}; do
158 LOCAL_FILENAME
=`get_filename $FILE`
159 case $LOCAL_FILENAME in
160 *.
tar.gz
|*.
tar.Z
|*.tgz
)
161 COMMAND
="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;;
163 COMMAND
="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;;
165 COMMAND
="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;;
167 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
175 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
176 rm -rf $PKGMK_WORK_DIR
178 error
"Building '$TARGET' failed."
185 local FILE LOCAL_FILENAMES
187 if [ "$source" ]; then
188 for FILE
in ${source[@]}; do
189 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
192 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
197 pkginfo
--footprint $TARGET | \
198 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
203 local FILE
="$PKGMK_WORK_DIR/.tmp"
207 if [ -f $PKGMK_MD5SUM ]; then
208 make_md5sum
> $FILE.
md5sum
209 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
210 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
214 sed 's/^+/NEW /g' | \
215 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
216 if [ -s $FILE.
md5sum.
diff ]; then
217 error
"Md5sum mismatch found:"
218 cat $FILE.
md5sum.
diff >&2
220 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
221 rm -rf $PKGMK_WORK_DIR
224 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
225 error
"Md5sum not ok."
229 error
"Building '$TARGET' failed."
233 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
234 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
235 rm -rf $PKGMK_WORK_DIR
237 info
"Md5sum not found."
241 warning
"Md5sum not found, creating new."
242 make_md5sum
> $PKGMK_MD5SUM
245 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
246 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
247 rm -rf $PKGMK_WORK_DIR
259 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
260 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
265 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
266 case $
(file -b "$FILE") in
267 *ELF
*executable
*not\ stripped
)
268 strip
--strip-all "$FILE"
270 *ELF
*shared\ object
*not\ stripped
)
271 strip
--strip-unneeded "$FILE"
273 current\
ar\ archive
)
274 strip
--strip-debug "$FILE"
279 compress_manpages
() {
280 local FILE DIR TARGET
284 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
285 if [ "$FILE" = "${FILE%%.gz}" ]; then
290 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
291 TARGET
=`readlink -n "$FILE"`
292 TARGET
="${TARGET##*/}"
293 TARGET
="${TARGET%%.gz}.gz"
295 FILE
="${FILE%%.gz}.gz"
296 DIR
=`dirname "$FILE"`
298 if [ -e "$DIR/$TARGET" ]; then
299 ln -sf "$TARGET" "$FILE"
305 local FILE
="$PKGMK_WORK_DIR/.tmp"
309 if [ -f $TARGET ]; then
310 make_footprint
> $FILE.footprint
311 if [ -f $PKGMK_FOOTPRINT ]; then
312 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
313 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
317 sed 's/^+/NEW /g' | \
318 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
319 if [ -s $FILE.footprint.
diff ]; then
320 error
"Footprint mismatch found:"
321 cat $FILE.footprint.
diff >&2
322 BUILD_SUCCESSFUL
="no"
325 warning
"Footprint not found, creating new."
326 mv $FILE.footprint
$PKGMK_FOOTPRINT
329 error
"Package '$TARGET' was not found."
330 BUILD_SUCCESSFUL
="no"
335 local BUILD_SUCCESSFUL
="no"
337 export PKG
="$PKGMK_WORK_DIR/pkg"
338 export SRC
="$PKGMK_WORK_DIR/src"
342 rm -rf $PKGMK_WORK_DIR
345 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
349 if [ "$UID" != "0" ]; then
350 warning
"Packages should be built as root."
353 info
"Building '$TARGET'."
361 if [ "$PKGMK_NO_STRIP" = "no" ]; then
372 BUILD_SUCCESSFUL
="yes"
374 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
375 warning
"Footprint ignored."
382 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
383 rm -rf $PKGMK_WORK_DIR
386 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
387 info
"Building '$TARGET' succeeded."
389 if [ -f $TARGET ]; then
390 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
392 error
"Building '$TARGET' failed."
400 info
"Installing '$TARGET'."
402 if [ "$PKGMK_INSTALL" = "install" ]; then
403 COMMAND
="pkgadd $TARGET"
405 COMMAND
="pkgadd -u $TARGET"
413 info
"Installing '$TARGET' succeeded."
415 error
"Installing '$TARGET' failed."
423 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
425 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
426 DIR
="`dirname $FILE`/"
428 info
"Entering directory '$DIR'."
429 (cd $DIR && $PKGMK_COMMAND $ARGS)
430 info
"Leaving directory '$DIR'."
436 local FILE LOCAL_FILENAME
438 if [ -f $TARGET ]; then
439 info
"Removing $TARGET"
443 for FILE
in ${source[@]}; do
444 LOCAL_FILENAME
=`get_filename $FILE`
445 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
446 info
"Removing $LOCAL_FILENAME"
447 rm -f $LOCAL_FILENAME
453 if [ ! -f $TARGET ]; then
454 error
"Unable to update footprint. File '$TARGET' not found."
458 make_footprint
> $PKGMK_FOOTPRINT
461 info
"Footprint updated."
468 if [ -f $TARGET ]; then
470 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
471 FILE
=`get_filename $FILE`
472 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
486 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
487 rm -rf $PKGMK_WORK_DIR
494 echo "usage: `basename $PKGMK_COMMAND` [options]"
496 echo " -i, --install build and install package"
497 echo " -u, --upgrade build and install package (as upgrade)"
498 echo " -r, --recursive search for and build packages recursively"
499 echo " -d, --download download missing source file(s)"
500 echo " -do, --download-only do not build, only download missing source file(s)"
501 echo " -utd, --up-to-date do not build, only check if package is up to date"
502 echo " -uf, --update-footprint update footprint using result from last build"
503 echo " -if, --ignore-footprint build package without checking footprint"
504 echo " -um, --update-md5sum update md5sum"
505 echo " -im, --ignore-md5sum build package without checking md5sum"
506 echo " -cm, --check-md5sum do not build, only check md5sum"
507 echo " -ns, --no-strip do not strip executable binaries or libraries"
508 echo " -f, --force build package even if it appears to be up to date"
509 echo " -c, --clean remove package and downloaded files"
510 echo " -kw, --keep-work keep temporary working directory"
511 echo " -cf, --config-file <file> use alternative configuration file"
512 echo " -v, --version print version and exit "
513 echo " -h, --help print help and exit"
520 PKGMK_INSTALL
="install" ;;
522 PKGMK_INSTALL
="upgrade" ;;
524 PKGMK_RECURSIVE
="yes" ;;
526 PKGMK_DOWNLOAD
="yes" ;;
529 PKGMK_DOWNLOAD_ONLY
="yes" ;;
531 PKGMK_UP_TO_DATE
="yes" ;;
532 -uf|--update-footprint)
533 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
534 -if|--ignore-footprint)
535 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
537 PKGMK_UPDATE_MD5SUM
="yes" ;;
539 PKGMK_IGNORE_MD5SUM
="yes" ;;
541 PKGMK_CHECK_MD5SUM
="yes" ;;
543 PKGMK_NO_STRIP
="yes" ;;
549 PKGMK_KEEP_WORK
="yes" ;;
552 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
558 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
564 echo "`basename $PKGMK_COMMAND`: invalid option $1"
576 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
581 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
582 if [ ! -f $FILE ]; then
583 error
"File '$FILE' not found."
589 check_directory
"$PKGMK_SOURCE_DIR"
590 check_directory
"$PKGMK_PACKAGE_DIR"
591 check_directory
"`dirname $PKGMK_WORK_DIR`"
595 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
597 if [ "$PKGMK_CLEAN" = "yes" ]; then
602 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
607 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
609 make_md5sum
> $PKGMK_MD5SUM
610 info
"Md5sum updated."
614 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
619 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
620 if [ "`build_needed`" = "yes" ]; then
621 info
"Package '$TARGET' is not up to date."
623 info
"Package '$TARGET' is up to date."
628 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
629 info
"Package '$TARGET' is up to date."
635 if [ "$PKGMK_INSTALL" != "no" ]; then
642 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
646 readonly PKGMK_VERSION
="#VERSION#"
647 readonly PKGMK_COMMAND
="$0"
648 readonly PKGMK_ROOT
="$PWD"
650 PKGMK_CONFFILE
="/etc/pkgmk.conf"
651 PKGMK_PKGFILE
="Pkgfile"
652 PKGMK_FOOTPRINT
=".footprint"
653 PKGMK_MD5SUM
=".md5sum"
654 PKGMK_NOSTRIP
=".nostrip"
656 PKGMK_SOURCE_MIRRORS
=()
657 PKGMK_SOURCE_DIR
="$PWD"
658 PKGMK_PACKAGE_DIR
="$PWD"
659 PKGMK_WORK_DIR
="$PWD/work"
664 PKGMK_DOWNLOAD_ONLY
="no"
665 PKGMK_UP_TO_DATE
="no"
666 PKGMK_UPDATE_FOOTPRINT
="no"
667 PKGMK_IGNORE_FOOTPRINT
="no"
670 PKGMK_UPDATE_MD5SUM
="no"
671 PKGMK_IGNORE_MD5SUM
="no"
672 PKGMK_CHECK_MD5SUM
="no"