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 if file -b "$FILE" | grep '^.*ELF.*executable.*not stripped$' &> /dev
/null
; then
246 strip
--strip-all "$FILE"
247 elif file -b "$FILE" | grep '^.*ELF.*shared object.*not stripped$' &> /dev
/null
; then
248 strip
--strip-unneeded "$FILE"
249 elif file -b "$FILE" | grep '^current ar archive$' &> /dev
/null
; then
250 strip
--strip-debug "$FILE"
255 compress_manpages
() {
256 local FILE DIR TARGET
260 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
261 if [ "$FILE" = "${FILE%%.gz}" ]; then
266 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
267 TARGET
=`readlink -n "$FILE"`
268 TARGET
="${TARGET##*/}"
269 TARGET
="${TARGET%%.gz}.gz"
271 FILE
="${FILE%%.gz}.gz"
272 DIR
=`dirname "$FILE"`
274 if [ -e "$DIR/$TARGET" ]; then
275 ln -sf "$TARGET" "$FILE"
281 local FILE
="$PKGMK_WORK_DIR/.tmp"
285 if [ -f $TARGET ]; then
286 make_footprint
> $FILE.footprint
287 if [ -f $PKGMK_FOOTPRINT ]; then
288 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
289 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
293 sed 's/^+/NEW /g' | \
294 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
295 if [ -s $FILE.footprint.
diff ]; then
296 error
"Footprint mismatch found:"
297 cat $FILE.footprint.
diff >&2
298 BUILD_SUCCESSFUL
="no"
301 warning
"Footprint not found, creating new."
302 mv $FILE.footprint
$PKGMK_FOOTPRINT
305 error
"Package '$TARGET' was not found."
306 BUILD_SUCCESSFUL
="no"
311 local BUILD_SUCCESSFUL
="no"
313 export PKG
="$PKGMK_WORK_DIR/pkg"
314 export SRC
="$PKGMK_WORK_DIR/src"
318 rm -rf $PKGMK_WORK_DIR
321 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
325 if [ "$UID" != "0" ]; then
326 warning
"Packages should be built as root."
329 info
"Building '$TARGET'."
337 if [ "$PKGMK_NO_STRIP" = "no" ]; then
348 BUILD_SUCCESSFUL
="yes"
350 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
351 warning
"Footprint ignored."
358 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
359 rm -rf $PKGMK_WORK_DIR
362 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
363 info
"Building '$TARGET' succeeded."
365 if [ -f $TARGET ]; then
366 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
368 error
"Building '$TARGET' failed."
376 info
"Installing '$TARGET'."
378 if [ "$PKGMK_INSTALL" = "install" ]; then
379 COMMAND
="pkgadd $TARGET"
381 COMMAND
="pkgadd -u $TARGET"
389 info
"Installing '$TARGET' succeeded."
391 error
"Installing '$TARGET' failed."
399 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
401 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
402 DIR
="`dirname $FILE`/"
404 info
"Entering directory '$DIR'."
405 (cd $DIR && $PKGMK_COMMAND $ARGS)
406 info
"Leaving directory '$DIR'."
412 local FILE LOCAL_FILENAME
414 if [ -f $TARGET ]; then
415 info
"Removing $TARGET"
419 for FILE
in ${source[@]}; do
420 LOCAL_FILENAME
=`get_filename $FILE`
421 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
422 info
"Removing $LOCAL_FILENAME"
423 rm -f $LOCAL_FILENAME
429 if [ ! -f $TARGET ]; then
430 error
"Unable to update footprint. File '$TARGET' not found."
434 make_footprint
> $PKGMK_FOOTPRINT
437 info
"Footprint updated."
444 if [ -f $TARGET ]; then
446 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
447 FILE
=`get_filename $FILE`
448 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
462 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
463 rm -rf $PKGMK_WORK_DIR
470 echo "usage: `basename $PKGMK_COMMAND` [options]"
472 echo " -i, --install build and install package"
473 echo " -u, --upgrade build and install package (as upgrade)"
474 echo " -r, --recursive search for and build packages recursively"
475 echo " -d, --download download missing source file(s)"
476 echo " -do, --download-only do not build, only download missing source file(s)"
477 echo " -utd, --up-to-date do not build, only check if package is up to date"
478 echo " -uf, --update-footprint update footprint using result from last build"
479 echo " -if, --ignore-footprint build package without checking footprint"
480 echo " -um, --update-md5sum update md5sum"
481 echo " -im, --ignore-md5sum build package without checking md5sum"
482 echo " -cm, --check-md5sum do not build, only check md5sum"
483 echo " -ns, --no-strip do not strip executable binaries or libraries"
484 echo " -f, --force build package even if it appears to be up to date"
485 echo " -c, --clean remove package and downloaded files"
486 echo " -kw, --keep-work keep temporary working directory"
487 echo " -cf, --config-file <file> use alternative configuration file"
488 echo " -v, --version print version and exit "
489 echo " -h, --help print help and exit"
496 PKGMK_INSTALL
="install" ;;
498 PKGMK_INSTALL
="upgrade" ;;
500 PKGMK_RECURSIVE
="yes" ;;
502 PKGMK_DOWNLOAD
="yes" ;;
505 PKGMK_DOWNLOAD_ONLY
="yes" ;;
507 PKGMK_UP_TO_DATE
="yes" ;;
508 -uf|--update-footprint)
509 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
510 -if|--ignore-footprint)
511 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
513 PKGMK_UPDATE_MD5SUM
="yes" ;;
515 PKGMK_IGNORE_MD5SUM
="yes" ;;
517 PKGMK_CHECK_MD5SUM
="yes" ;;
519 PKGMK_NO_STRIP
="yes" ;;
525 PKGMK_KEEP_WORK
="yes" ;;
528 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
534 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
540 echo "`basename $PKGMK_COMMAND`: invalid option $1"
552 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
557 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
558 if [ ! -f $FILE ]; then
559 error
"File '$FILE' not found."
565 check_directory
"$PKGMK_SOURCE_DIR"
566 check_directory
"$PKGMK_PACKAGE_DIR"
567 check_directory
"`dirname $PKGMK_WORK_DIR`"
571 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
573 if [ "$PKGMK_CLEAN" = "yes" ]; then
578 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
583 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
585 make_md5sum
> $PKGMK_MD5SUM
586 info
"Md5sum updated."
590 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
595 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
596 if [ "`build_needed`" = "yes" ]; then
597 info
"Package '$TARGET' is not up to date."
599 info
"Package '$TARGET' is up to date."
604 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
605 info
"Package '$TARGET' is up to date."
611 if [ "$PKGMK_INSTALL" != "no" ]; then
618 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
622 readonly PKGMK_VERSION
="#VERSION#"
623 readonly PKGMK_COMMAND
="$0"
624 readonly PKGMK_ROOT
="$PWD"
626 PKGMK_CONFFILE
="/etc/pkgmk.conf"
627 PKGMK_PKGFILE
="Pkgfile"
628 PKGMK_FOOTPRINT
=".footprint"
629 PKGMK_MD5SUM
=".md5sum"
630 PKGMK_NOSTRIP
=".nostrip"
632 PKGMK_SOURCE_DIR
="$PWD"
633 PKGMK_PACKAGE_DIR
="$PWD"
634 PKGMK_WORK_DIR
="$PWD/work"
639 PKGMK_DOWNLOAD_ONLY
="no"
640 PKGMK_UP_TO_DATE
="no"
641 PKGMK_UPDATE_FOOTPRINT
="no"
642 PKGMK_IGNORE_FOOTPRINT
="no"
645 PKGMK_UPDATE_MD5SUM
="no"
646 PKGMK_IGNORE_MD5SUM
="no"
647 PKGMK_CHECK_MD5SUM
="no"