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 if [[ $1 =~ ^
(http
|https
|ftp|file)://.
*/(.
+) ]]; then
38 echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}"
45 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
50 if [ ! "$name" ]; then
51 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
53 elif [ ! "$version" ]; then
54 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
56 elif [ ! "$release" ]; then
57 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
59 elif [ "`type -t build`" != "function" ]; then
60 error
"Function 'build' not specified in $PKGMK_PKGFILE."
67 error
"Directory '$1' does not exist."
69 elif [ ! -w $1 ]; then
70 error
"Directory '$1' not writable."
72 elif [ ! -x $1 ] || [ ! -r $1 ]; then
73 error
"Directory '$1' not readable."
79 if [ -e $1 ] && [ ! -w $1 ]; then
80 error
"File '$1' is not writable."
86 info
"Downloading '$1'."
88 if [ ! "`type -p wget`" ]; then
89 error
"Command 'wget' not found."
93 LOCAL_FILENAME
=`get_filename $1`
94 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
95 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
96 --directory-prefix=$PKGMK_SOURCE_DIR \
97 --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
99 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
100 info
"Partial download found, trying to resume"
106 BASENAME
=`get_basename $1`
107 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
108 REPO
="`echo $REPO | sed 's|/$||'`"
109 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
111 if [ $error == 0 ]; then
116 if [ $error != 0 ]; then
118 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
120 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
121 info
"Partial download failed, restarting"
122 rm -f "$LOCAL_FILENAME_PARTIAL"
130 if [ $error != 0 ]; then
131 error
"Downloading '$1' failed."
135 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
139 local FILE LOCAL_FILENAME
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)."
148 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
151 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
160 local FILE LOCAL_FILENAME COMMAND
162 for FILE
in ${source[@]}; do
163 LOCAL_FILENAME
=`get_filename $FILE`
164 case $LOCAL_FILENAME in
165 *.
tar.gz
|*.
tar.Z
|*.tgz
|*.
tar.bz2
|*.
tar.xz
|*.
tar.lzma
|*.
zip)
166 COMMAND
="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
168 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
176 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
177 rm -rf $PKGMK_WORK_DIR
179 error
"Building '$TARGET' failed."
186 local FILE LOCAL_FILENAMES
188 if [ "$source" ]; then
189 for FILE
in ${source[@]}; do
190 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
193 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
198 pkginfo
--footprint $TARGET | \
199 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
204 local FILE
="$PKGMK_WORK_DIR/.tmp"
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 | \
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:"
219 cat $FILE.
md5sum.
diff >&2
221 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
222 rm -rf $PKGMK_WORK_DIR
225 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
226 error
"Md5sum not ok."
230 error
"Building '$TARGET' failed."
234 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
235 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
236 rm -rf $PKGMK_WORK_DIR
238 info
"Md5sum not found."
242 warning
"Md5sum not found, creating new."
243 make_md5sum
> $PKGMK_MD5SUM
246 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
247 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
248 rm -rf $PKGMK_WORK_DIR
260 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
261 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
266 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
267 case $
(file -b "$FILE") in
268 *ELF
*executable
*not\ stripped
)
269 strip
--strip-all "$FILE"
271 *ELF
*shared\ object
*not\ stripped
)
272 strip
--strip-unneeded "$FILE"
274 current\
ar\ archive
)
275 strip
--strip-debug "$FILE"
280 compress_manpages
() {
281 local FILE DIR TARGET
285 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
286 if [ "$FILE" = "${FILE%%.gz}" ]; then
291 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
292 TARGET
=`readlink -n "$FILE"`
293 TARGET
="${TARGET##*/}"
294 TARGET
="${TARGET%%.gz}.gz"
296 FILE
="${FILE%%.gz}.gz"
297 DIR
=`dirname "$FILE"`
299 if [ -e "$DIR/$TARGET" ]; then
300 ln -sf "$TARGET" "$FILE"
306 local FILE
="$PKGMK_WORK_DIR/.tmp"
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
| \
318 sed 's/^+/NEW /g' | \
319 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
320 if [ -s $FILE.footprint.
diff ]; then
321 error
"Footprint mismatch found:"
322 cat $FILE.footprint.
diff >&2
323 BUILD_SUCCESSFUL
="no"
326 warning
"Footprint not found, creating new."
327 mv $FILE.footprint
$PKGMK_FOOTPRINT
330 error
"Package '$TARGET' was not found."
331 BUILD_SUCCESSFUL
="no"
336 export PKG
="$PKGMK_WORK_DIR/pkg"
337 export SRC
="$PKGMK_WORK_DIR/src"
344 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
350 rm -rf $PKGMK_WORK_DIR
355 local BUILD_SUCCESSFUL
="no"
360 if [ "$UID" != "0" ]; then
361 warning
"Packages should be built as root."
364 info
"Building '$TARGET'."
372 if [ "$PKGMK_NO_STRIP" = "no" ]; then
383 BUILD_SUCCESSFUL
="yes"
385 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
386 warning
"Footprint ignored."
393 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
397 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
398 info
"Building '$TARGET' succeeded."
400 if [ -f $TARGET ]; then
401 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
403 error
"Building '$TARGET' failed."
411 info
"Installing '$TARGET'."
413 if [ "$PKGMK_INSTALL" = "install" ]; then
414 COMMAND
="pkgadd $TARGET"
416 COMMAND
="pkgadd -u $TARGET"
424 info
"Installing '$TARGET' succeeded."
426 error
"Installing '$TARGET' failed."
434 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
436 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
437 DIR
="`dirname $FILE`/"
439 info
"Entering directory '$DIR'."
440 (cd $DIR && $PKGMK_COMMAND $ARGS)
441 info
"Leaving directory '$DIR'."
447 local FILE LOCAL_FILENAME
449 if [ -f $TARGET ]; then
450 info
"Removing $TARGET"
454 for FILE
in ${source[@]}; do
455 LOCAL_FILENAME
=`get_filename $FILE`
456 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
457 info
"Removing $LOCAL_FILENAME"
458 rm -f $LOCAL_FILENAME
464 if [ ! -f $TARGET ]; then
465 error
"Unable to update footprint. File '$TARGET' not found."
469 check_file
"$PKGMK_FOOTPRINT"
470 make_footprint
> $PKGMK_FOOTPRINT
473 info
"Footprint updated."
480 if [ -f $TARGET ]; then
482 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
483 FILE
=`get_filename $FILE`
484 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
498 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
499 rm -rf $PKGMK_WORK_DIR
506 echo "usage: `basename $PKGMK_COMMAND` [options]"
508 echo " -i, --install build and install package"
509 echo " -u, --upgrade build and install package (as upgrade)"
510 echo " -r, --recursive search for and build packages recursively"
511 echo " -d, --download download missing source file(s)"
512 echo " -do, --download-only do not build, only download missing source file(s)"
513 echo " -eo, --extract-only do not build, only extract source file(s)"
514 echo " -utd, --up-to-date do not build, only check if package is up to date"
515 echo " -uf, --update-footprint update footprint using result from last build"
516 echo " -if, --ignore-footprint build package without checking footprint"
517 echo " -um, --update-md5sum update md5sum"
518 echo " -im, --ignore-md5sum build package without checking md5sum"
519 echo " -cm, --check-md5sum do not build, only check md5sum"
520 echo " -ns, --no-strip do not strip executable binaries or libraries"
521 echo " -f, --force build package even if it appears to be up to date"
522 echo " -c, --clean remove package and downloaded files"
523 echo " -kw, --keep-work keep temporary working directory"
524 echo " -cf, --config-file <file> use alternative configuration file"
525 echo " -v, --version print version and exit "
526 echo " -h, --help print help and exit"
533 PKGMK_INSTALL
="install" ;;
535 PKGMK_INSTALL
="upgrade" ;;
537 PKGMK_RECURSIVE
="yes" ;;
539 PKGMK_DOWNLOAD
="yes" ;;
542 PKGMK_DOWNLOAD_ONLY
="yes" ;;
544 PKGMK_EXTRACT_ONLY
="yes" ;;
546 PKGMK_UP_TO_DATE
="yes" ;;
547 -uf|--update-footprint)
548 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
549 -if|--ignore-footprint)
550 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
552 PKGMK_UPDATE_MD5SUM
="yes" ;;
554 PKGMK_IGNORE_MD5SUM
="yes" ;;
556 PKGMK_CHECK_MD5SUM
="yes" ;;
558 PKGMK_NO_STRIP
="yes" ;;
564 PKGMK_KEEP_WORK
="yes" ;;
567 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
573 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
579 echo "`basename $PKGMK_COMMAND`: invalid option $1"
591 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
596 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
597 if [ ! -f $FILE ]; then
598 error
"File '$FILE' not found."
604 check_directory
"$PKGMK_SOURCE_DIR"
605 check_directory
"$PKGMK_PACKAGE_DIR"
606 check_directory
"`dirname $PKGMK_WORK_DIR`"
610 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
612 if [ "$PKGMK_CLEAN" = "yes" ]; then
617 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
622 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
624 check_file
"$PKGMK_MD5SUM"
625 make_md5sum
> $PKGMK_MD5SUM
626 info
"Md5sum updated."
630 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
635 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
638 info
"Extracting sources of package '$name-$version'."
643 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
644 if [ "`build_needed`" = "yes" ]; then
645 info
"Package '$TARGET' is not up to date."
647 info
"Package '$TARGET' is up to date."
652 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
653 info
"Package '$TARGET' is up to date."
659 if [ "$PKGMK_INSTALL" != "no" ]; then
666 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
670 readonly PKGMK_VERSION
="#VERSION#"
671 readonly PKGMK_COMMAND
="$0"
672 readonly PKGMK_ROOT
="$PWD"
674 PKGMK_CONFFILE
="/etc/pkgmk.conf"
675 PKGMK_PKGFILE
="Pkgfile"
676 PKGMK_FOOTPRINT
=".footprint"
677 PKGMK_MD5SUM
=".md5sum"
678 PKGMK_NOSTRIP
=".nostrip"
680 PKGMK_SOURCE_MIRRORS
=()
681 PKGMK_SOURCE_DIR
="$PWD"
682 PKGMK_PACKAGE_DIR
="$PWD"
683 PKGMK_WORK_DIR
="$PWD/work"
688 PKGMK_DOWNLOAD_ONLY
="no"
689 PKGMK_EXTRACT_ONLY
="no"
690 PKGMK_UP_TO_DATE
="no"
691 PKGMK_UPDATE_FOOTPRINT
="no"
692 PKGMK_IGNORE_FOOTPRINT
="no"
695 PKGMK_UPDATE_MD5SUM
="no"
696 PKGMK_IGNORE_MD5SUM
="no"
697 PKGMK_CHECK_MD5SUM
="no"