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 if [ ! "$name" ]; then
48 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
50 elif [ ! "$version" ]; then
51 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
53 elif [ ! "$release" ]; then
54 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
56 elif [ "`type -t build`" != "function" ]; then
57 error
"Function 'build' not specified in $PKGMK_PKGFILE."
64 error
"Directory '$1' does not exist."
66 elif [ ! -w $1 ]; then
67 error
"Directory '$1' not writable."
69 elif [ ! -x $1 ] || [ ! -r $1 ]; then
70 error
"Directory '$1' not readable."
76 info
"Downloading '$1'."
78 if [ ! "`type -p wget`" ]; then
79 error
"Command 'wget' not found."
83 LOCAL_FILENAME
=`get_filename $1`
84 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
85 DOWNLOAD_CMD
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
86 --directory-prefix=$PKGMK_SOURCE_DIR --output-document=$LOCAL_FILENAME_PARTIAL $1"
88 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
89 info
"Partial download found, trying to resume"
94 wget
$RESUME_CMD $DOWNLOAD_CMD
96 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
97 info
"Partial download failed, restarting"
98 rm -f "$LOCAL_FILENAME_PARTIAL"
105 if [ $error != 0 ]; then
106 error
"Downloading '$1' failed."
110 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
114 local FILE LOCAL_FILENAME
116 for FILE
in ${source[@]}; do
117 LOCAL_FILENAME
=`get_filename $FILE`
118 if [ ! -e $LOCAL_FILENAME ]; then
119 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
120 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
123 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
126 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
135 local FILE LOCAL_FILENAME COMMAND
137 for FILE
in ${source[@]}; do
138 LOCAL_FILENAME
=`get_filename $FILE`
139 case $LOCAL_FILENAME in
140 *.
tar.gz
|*.
tar.Z
|*.tgz
)
141 COMMAND
="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;;
143 COMMAND
="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;;
145 COMMAND
="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;;
147 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
155 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
156 rm -rf $PKGMK_WORK_DIR
158 error
"Building '$TARGET' failed."
165 local FILE LOCAL_FILENAMES
167 if [ "$source" ]; then
168 for FILE
in ${source[@]}; do
169 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
172 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
177 pkginfo
--footprint $TARGET | \
178 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
183 local FILE
="$PKGMK_WORK_DIR/.tmp"
187 if [ -f $PKGMK_MD5SUM ]; then
188 make_md5sum
> $FILE.
md5sum
189 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
190 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
194 sed 's/^+/NEW /g' | \
195 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
196 if [ -s $FILE.
md5sum.
diff ]; then
197 error
"Md5sum mismatch found:"
198 cat $FILE.
md5sum.
diff >&2
200 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
201 rm -rf $PKGMK_WORK_DIR
204 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
205 error
"Md5sum not ok."
209 error
"Building '$TARGET' failed."
213 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
214 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
215 rm -rf $PKGMK_WORK_DIR
217 info
"Md5sum not found."
221 warning
"Md5sum not found, creating new."
222 make_md5sum
> $PKGMK_MD5SUM
225 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
226 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
227 rm -rf $PKGMK_WORK_DIR
239 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
240 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
245 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
246 case $
(file -b "$FILE") in
247 *ELF
*executable
*not\ stripped
)
248 strip
--strip-all "$FILE"
250 *ELF
*shared\ object
*not\ stripped
)
251 strip
--strip-unneeded "$FILE"
253 current\
ar\ archive
)
254 strip
--strip-debug "$FILE"
259 compress_manpages
() {
260 local FILE DIR TARGET
264 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
265 if [ "$FILE" = "${FILE%%.gz}" ]; then
270 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
271 TARGET
=`readlink -n "$FILE"`
272 TARGET
="${TARGET##*/}"
273 TARGET
="${TARGET%%.gz}.gz"
275 FILE
="${FILE%%.gz}.gz"
276 DIR
=`dirname "$FILE"`
278 if [ -e "$DIR/$TARGET" ]; then
279 ln -sf "$TARGET" "$FILE"
285 local FILE
="$PKGMK_WORK_DIR/.tmp"
289 if [ -f $TARGET ]; then
290 make_footprint
> $FILE.footprint
291 if [ -f $PKGMK_FOOTPRINT ]; then
292 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
293 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
297 sed 's/^+/NEW /g' | \
298 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
299 if [ -s $FILE.footprint.
diff ]; then
300 error
"Footprint mismatch found:"
301 cat $FILE.footprint.
diff >&2
302 BUILD_SUCCESSFUL
="no"
305 warning
"Footprint not found, creating new."
306 mv $FILE.footprint
$PKGMK_FOOTPRINT
309 error
"Package '$TARGET' was not found."
310 BUILD_SUCCESSFUL
="no"
315 local BUILD_SUCCESSFUL
="no"
317 export PKG
="$PKGMK_WORK_DIR/pkg"
318 export SRC
="$PKGMK_WORK_DIR/src"
322 rm -rf $PKGMK_WORK_DIR
325 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
329 if [ "$UID" != "0" ]; then
330 warning
"Packages should be built as root."
333 info
"Building '$TARGET'."
341 if [ "$PKGMK_NO_STRIP" = "no" ]; then
352 BUILD_SUCCESSFUL
="yes"
354 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
355 warning
"Footprint ignored."
362 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
363 rm -rf $PKGMK_WORK_DIR
366 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
367 info
"Building '$TARGET' succeeded."
369 if [ -f $TARGET ]; then
370 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
372 error
"Building '$TARGET' failed."
380 info
"Installing '$TARGET'."
382 if [ "$PKGMK_INSTALL" = "install" ]; then
383 COMMAND
="pkgadd $TARGET"
385 COMMAND
="pkgadd -u $TARGET"
393 info
"Installing '$TARGET' succeeded."
395 error
"Installing '$TARGET' failed."
403 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
405 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
406 DIR
="`dirname $FILE`/"
408 info
"Entering directory '$DIR'."
409 (cd $DIR && $PKGMK_COMMAND $ARGS)
410 info
"Leaving directory '$DIR'."
416 local FILE LOCAL_FILENAME
418 if [ -f $TARGET ]; then
419 info
"Removing $TARGET"
423 for FILE
in ${source[@]}; do
424 LOCAL_FILENAME
=`get_filename $FILE`
425 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
426 info
"Removing $LOCAL_FILENAME"
427 rm -f $LOCAL_FILENAME
433 if [ ! -f $TARGET ]; then
434 error
"Unable to update footprint. File '$TARGET' not found."
438 make_footprint
> $PKGMK_FOOTPRINT
441 info
"Footprint updated."
448 if [ -f $TARGET ]; then
450 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
451 FILE
=`get_filename $FILE`
452 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
466 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
467 rm -rf $PKGMK_WORK_DIR
474 echo "usage: `basename $PKGMK_COMMAND` [options]"
476 echo " -i, --install build and install package"
477 echo " -u, --upgrade build and install package (as upgrade)"
478 echo " -r, --recursive search for and build packages recursively"
479 echo " -d, --download download missing source file(s)"
480 echo " -do, --download-only do not build, only download missing source file(s)"
481 echo " -utd, --up-to-date do not build, only check if package is up to date"
482 echo " -uf, --update-footprint update footprint using result from last build"
483 echo " -if, --ignore-footprint build package without checking footprint"
484 echo " -um, --update-md5sum update md5sum"
485 echo " -im, --ignore-md5sum build package without checking md5sum"
486 echo " -cm, --check-md5sum do not build, only check md5sum"
487 echo " -ns, --no-strip do not strip executable binaries or libraries"
488 echo " -f, --force build package even if it appears to be up to date"
489 echo " -c, --clean remove package and downloaded files"
490 echo " -kw, --keep-work keep temporary working directory"
491 echo " -cf, --config-file <file> use alternative configuration file"
492 echo " -v, --version print version and exit "
493 echo " -h, --help print help and exit"
500 PKGMK_INSTALL
="install" ;;
502 PKGMK_INSTALL
="upgrade" ;;
504 PKGMK_RECURSIVE
="yes" ;;
506 PKGMK_DOWNLOAD
="yes" ;;
509 PKGMK_DOWNLOAD_ONLY
="yes" ;;
511 PKGMK_UP_TO_DATE
="yes" ;;
512 -uf|--update-footprint)
513 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
514 -if|--ignore-footprint)
515 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
517 PKGMK_UPDATE_MD5SUM
="yes" ;;
519 PKGMK_IGNORE_MD5SUM
="yes" ;;
521 PKGMK_CHECK_MD5SUM
="yes" ;;
523 PKGMK_NO_STRIP
="yes" ;;
529 PKGMK_KEEP_WORK
="yes" ;;
532 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
538 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
544 echo "`basename $PKGMK_COMMAND`: invalid option $1"
556 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
561 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
562 if [ ! -f $FILE ]; then
563 error
"File '$FILE' not found."
569 check_directory
"$PKGMK_SOURCE_DIR"
570 check_directory
"$PKGMK_PACKAGE_DIR"
571 check_directory
"`dirname $PKGMK_WORK_DIR`"
575 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
577 if [ "$PKGMK_CLEAN" = "yes" ]; then
582 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
587 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
589 make_md5sum
> $PKGMK_MD5SUM
590 info
"Md5sum updated."
594 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
599 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
600 if [ "`build_needed`" = "yes" ]; then
601 info
"Package '$TARGET' is not up to date."
603 info
"Package '$TARGET' is up to date."
608 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
609 info
"Package '$TARGET' is up to date."
615 if [ "$PKGMK_INSTALL" != "no" ]; then
622 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
626 readonly PKGMK_VERSION
="#VERSION#"
627 readonly PKGMK_COMMAND
="$0"
628 readonly PKGMK_ROOT
="$PWD"
630 PKGMK_CONFFILE
="/etc/pkgmk.conf"
631 PKGMK_PKGFILE
="Pkgfile"
632 PKGMK_FOOTPRINT
=".footprint"
633 PKGMK_MD5SUM
=".md5sum"
634 PKGMK_NOSTRIP
=".nostrip"
636 PKGMK_SOURCE_DIR
="$PWD"
637 PKGMK_PACKAGE_DIR
="$PWD"
638 PKGMK_WORK_DIR
="$PWD/work"
643 PKGMK_DOWNLOAD_ONLY
="no"
644 PKGMK_UP_TO_DATE
="no"
645 PKGMK_UPDATE_FOOTPRINT
="no"
646 PKGMK_IGNORE_FOOTPRINT
="no"
649 PKGMK_UPDATE_MD5SUM
="no"
650 PKGMK_IGNORE_MD5SUM
="no"
651 PKGMK_CHECK_MD5SUM
="no"