5 # Copyright (c) 2000-2005 Per Liden
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 info
"WARNING: $1" >&2
36 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
38 if [ "$FILE" != "$1" ]; then
39 FILE
="$PKGMK_SOURCE_DIR/$FILE"
46 if [ ! "$name" ]; then
47 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
49 elif [ ! "$version" ]; then
50 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
52 elif [ ! "$release" ]; then
53 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
55 elif [ "`type -t build`" != "function" ]; then
56 error
"Function 'build' not specified in $PKGMK_PKGFILE."
63 error
"Directory '$1' does not exist."
65 elif [ ! -w $1 ]; then
66 error
"Directory '$1' not writable."
68 elif [ ! -x $1 ] || [ ! -r $1 ]; then
69 error
"Directory '$1' not readable."
75 info
"Downloading '$1'."
77 if [ ! "`type -p wget`" ]; then
78 error
"Command 'wget' not found."
82 LOCAL_FILENAME
=`get_filename $1`
83 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
84 DOWNLOAD_CMD
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
85 --directory-prefix=$PKGMK_SOURCE_DIR --output-document=$LOCAL_FILENAME_PARTIAL $1"
87 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
88 info
"Partial download found, trying to resume"
93 wget
$RESUME_CMD $DOWNLOAD_CMD
95 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
96 info
"Partial download failed, restarting"
97 rm -f "$LOCAL_FILENAME_PARTIAL"
104 if [ $error != 0 ]; then
105 error
"Downloading '$1' failed."
109 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
113 local FILE LOCAL_FILENAME
115 for FILE
in ${source[@]}; do
116 LOCAL_FILENAME
=`get_filename $FILE`
117 if [ ! -e $LOCAL_FILENAME ]; then
118 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
119 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
122 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
125 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
134 local FILE LOCAL_FILENAME COMMAND
136 for FILE
in ${source[@]}; do
137 LOCAL_FILENAME
=`get_filename $FILE`
138 case $LOCAL_FILENAME in
139 *.
tar.gz
|*.
tar.Z
|*.tgz
)
140 COMMAND
="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;;
142 COMMAND
="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;;
144 COMMAND
="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;;
146 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
154 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
155 rm -rf $PKGMK_WORK_DIR
157 error
"Building '$TARGET' failed."
164 local FILE LOCAL_FILENAMES
166 if [ "$source" ]; then
167 for FILE
in ${source[@]}; do
168 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
171 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
176 pkginfo
--footprint $TARGET | \
177 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
182 local FILE
="$PKGMK_WORK_DIR/.tmp"
186 if [ -f $PKGMK_MD5SUM ]; then
187 make_md5sum
> $FILE.
md5sum
188 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
189 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
193 sed 's/^+/NEW /g' | \
194 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
195 if [ -s $FILE.
md5sum.
diff ]; then
196 error
"Md5sum mismatch found:"
197 cat $FILE.
md5sum.
diff >&2
199 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
200 rm -rf $PKGMK_WORK_DIR
203 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
204 error
"Md5sum not ok."
208 error
"Building '$TARGET' failed."
212 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
213 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
214 rm -rf $PKGMK_WORK_DIR
216 info
"Md5sum not found."
220 warning
"Md5sum not found, creating new."
221 make_md5sum
> $PKGMK_MD5SUM
224 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
225 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
226 rm -rf $PKGMK_WORK_DIR
238 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
239 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
244 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
245 case $
(file -b "$FILE") in
246 *ELF
*executable
*not\ stripped
)
247 strip
--strip-all "$FILE"
249 *ELF
*shared\ object
*not\ stripped
)
250 strip
--strip-unneeded "$FILE"
252 current\
ar\ archive
)
253 strip
--strip-debug "$FILE"
258 compress_manpages
() {
259 local FILE DIR TARGET
263 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
264 if [ "$FILE" = "${FILE%%.gz}" ]; then
269 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
270 TARGET
=`readlink -n "$FILE"`
271 TARGET
="${TARGET##*/}"
272 TARGET
="${TARGET%%.gz}.gz"
274 FILE
="${FILE%%.gz}.gz"
275 DIR
=`dirname "$FILE"`
277 if [ -e "$DIR/$TARGET" ]; then
278 ln -sf "$TARGET" "$FILE"
284 local FILE
="$PKGMK_WORK_DIR/.tmp"
288 if [ -f $TARGET ]; then
289 make_footprint
> $FILE.footprint
290 if [ -f $PKGMK_FOOTPRINT ]; then
291 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
292 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
296 sed 's/^+/NEW /g' | \
297 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
298 if [ -s $FILE.footprint.
diff ]; then
299 error
"Footprint mismatch found:"
300 cat $FILE.footprint.
diff >&2
301 BUILD_SUCCESSFUL
="no"
304 warning
"Footprint not found, creating new."
305 mv $FILE.footprint
$PKGMK_FOOTPRINT
308 error
"Package '$TARGET' was not found."
309 BUILD_SUCCESSFUL
="no"
314 local BUILD_SUCCESSFUL
="no"
316 export PKG
="$PKGMK_WORK_DIR/pkg"
317 export SRC
="$PKGMK_WORK_DIR/src"
321 rm -rf $PKGMK_WORK_DIR
324 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
328 if [ "$UID" != "0" ]; then
329 warning
"Packages should be built as root."
332 info
"Building '$TARGET'."
340 if [ "$PKGMK_NO_STRIP" = "no" ]; then
351 BUILD_SUCCESSFUL
="yes"
353 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
354 warning
"Footprint ignored."
361 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
362 rm -rf $PKGMK_WORK_DIR
365 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
366 info
"Building '$TARGET' succeeded."
368 if [ -f $TARGET ]; then
369 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
371 error
"Building '$TARGET' failed."
379 info
"Installing '$TARGET'."
381 if [ "$PKGMK_INSTALL" = "install" ]; then
382 COMMAND
="pkgadd $TARGET"
384 COMMAND
="pkgadd -u $TARGET"
392 info
"Installing '$TARGET' succeeded."
394 error
"Installing '$TARGET' failed."
402 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
404 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
405 DIR
="`dirname $FILE`/"
407 info
"Entering directory '$DIR'."
408 (cd $DIR && $PKGMK_COMMAND $ARGS)
409 info
"Leaving directory '$DIR'."
415 local FILE LOCAL_FILENAME
417 if [ -f $TARGET ]; then
418 info
"Removing $TARGET"
422 for FILE
in ${source[@]}; do
423 LOCAL_FILENAME
=`get_filename $FILE`
424 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
425 info
"Removing $LOCAL_FILENAME"
426 rm -f $LOCAL_FILENAME
432 if [ ! -f $TARGET ]; then
433 error
"Unable to update footprint. File '$TARGET' not found."
437 make_footprint
> $PKGMK_FOOTPRINT
440 info
"Footprint updated."
447 if [ -f $TARGET ]; then
449 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
450 FILE
=`get_filename $FILE`
451 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
465 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
466 rm -rf $PKGMK_WORK_DIR
473 echo "usage: `basename $PKGMK_COMMAND` [options]"
475 echo " -i, --install build and install package"
476 echo " -u, --upgrade build and install package (as upgrade)"
477 echo " -r, --recursive search for and build packages recursively"
478 echo " -d, --download download missing source file(s)"
479 echo " -do, --download-only do not build, only download missing source file(s)"
480 echo " -utd, --up-to-date do not build, only check if package is up to date"
481 echo " -uf, --update-footprint update footprint using result from last build"
482 echo " -if, --ignore-footprint build package without checking footprint"
483 echo " -um, --update-md5sum update md5sum"
484 echo " -im, --ignore-md5sum build package without checking md5sum"
485 echo " -cm, --check-md5sum do not build, only check md5sum"
486 echo " -ns, --no-strip do not strip executable binaries or libraries"
487 echo " -f, --force build package even if it appears to be up to date"
488 echo " -c, --clean remove package and downloaded files"
489 echo " -kw, --keep-work keep temporary working directory"
490 echo " -cf, --config-file <file> use alternative configuration file"
491 echo " -v, --version print version and exit "
492 echo " -h, --help print help and exit"
499 PKGMK_INSTALL
="install" ;;
501 PKGMK_INSTALL
="upgrade" ;;
503 PKGMK_RECURSIVE
="yes" ;;
505 PKGMK_DOWNLOAD
="yes" ;;
508 PKGMK_DOWNLOAD_ONLY
="yes" ;;
510 PKGMK_UP_TO_DATE
="yes" ;;
511 -uf|--update-footprint)
512 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
513 -if|--ignore-footprint)
514 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
516 PKGMK_UPDATE_MD5SUM
="yes" ;;
518 PKGMK_IGNORE_MD5SUM
="yes" ;;
520 PKGMK_CHECK_MD5SUM
="yes" ;;
522 PKGMK_NO_STRIP
="yes" ;;
528 PKGMK_KEEP_WORK
="yes" ;;
531 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
537 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
543 echo "`basename $PKGMK_COMMAND`: invalid option $1"
555 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
560 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
561 if [ ! -f $FILE ]; then
562 error
"File '$FILE' not found."
568 check_directory
"$PKGMK_SOURCE_DIR"
569 check_directory
"$PKGMK_PACKAGE_DIR"
570 check_directory
"`dirname $PKGMK_WORK_DIR`"
574 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
576 if [ "$PKGMK_CLEAN" = "yes" ]; then
581 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
586 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
588 make_md5sum
> $PKGMK_MD5SUM
589 info
"Md5sum updated."
593 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
598 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
599 if [ "`build_needed`" = "yes" ]; then
600 info
"Package '$TARGET' is not up to date."
602 info
"Package '$TARGET' is up to date."
607 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
608 info
"Package '$TARGET' is up to date."
614 if [ "$PKGMK_INSTALL" != "no" ]; then
621 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
625 readonly PKGMK_VERSION
="#VERSION#"
626 readonly PKGMK_COMMAND
="$0"
627 readonly PKGMK_ROOT
="$PWD"
629 PKGMK_CONFFILE
="/etc/pkgmk.conf"
630 PKGMK_PKGFILE
="Pkgfile"
631 PKGMK_FOOTPRINT
=".footprint"
632 PKGMK_MD5SUM
=".md5sum"
633 PKGMK_NOSTRIP
=".nostrip"
635 PKGMK_SOURCE_DIR
="$PWD"
636 PKGMK_PACKAGE_DIR
="$PWD"
637 PKGMK_WORK_DIR
="$PWD/work"
642 PKGMK_DOWNLOAD_ONLY
="no"
643 PKGMK_UP_TO_DATE
="no"
644 PKGMK_UPDATE_FOOTPRINT
="no"
645 PKGMK_IGNORE_FOOTPRINT
="no"
648 PKGMK_UPDATE_MD5SUM
="no"
649 PKGMK_IGNORE_MD5SUM
="no"
650 PKGMK_CHECK_MD5SUM
="no"