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 info
"Downloading '$1'."
81 if [ ! "`type -p wget`" ]; then
82 error
"Command 'wget' not found."
86 LOCAL_FILENAME
=`get_filename $1`
87 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
88 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
89 --directory-prefix=$PKGMK_SOURCE_DIR \
90 --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
92 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
93 info
"Partial download found, trying to resume"
99 BASENAME
=`get_basename $1`
100 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
101 REPO
="`echo $REPO | sed 's|/$||'`"
102 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
104 if [ $error == 0 ]; then
109 if [ $error != 0 ]; then
111 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
113 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
114 info
"Partial download failed, restarting"
115 rm -f "$LOCAL_FILENAME_PARTIAL"
123 if [ $error != 0 ]; then
124 error
"Downloading '$1' failed."
128 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
132 local FILE LOCAL_FILENAME
134 for FILE
in ${source[@]}; do
135 LOCAL_FILENAME
=`get_filename $FILE`
136 if [ ! -e $LOCAL_FILENAME ]; then
137 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
138 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
141 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
144 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
153 local FILE LOCAL_FILENAME COMMAND
155 for FILE
in ${source[@]}; do
156 LOCAL_FILENAME
=`get_filename $FILE`
157 case $LOCAL_FILENAME in
158 *.
tar.gz
|*.
tar.Z
|*.tgz
|*.
tar.bz2
|*.
tar.xz
|*.
zip)
159 COMMAND
="bsdtar -C $SRC -xf $LOCAL_FILENAME" ;;
161 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
169 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
170 rm -rf $PKGMK_WORK_DIR
172 error
"Building '$TARGET' failed."
179 local FILE LOCAL_FILENAMES
181 if [ "$source" ]; then
182 for FILE
in ${source[@]}; do
183 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
186 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
191 pkginfo
--footprint $TARGET | \
192 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
197 local FILE
="$PKGMK_WORK_DIR/.tmp"
201 if [ -f $PKGMK_MD5SUM ]; then
202 make_md5sum
> $FILE.
md5sum
203 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
204 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
208 sed 's/^+/NEW /g' | \
209 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
210 if [ -s $FILE.
md5sum.
diff ]; then
211 error
"Md5sum mismatch found:"
212 cat $FILE.
md5sum.
diff >&2
214 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
215 rm -rf $PKGMK_WORK_DIR
218 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
219 error
"Md5sum not ok."
223 error
"Building '$TARGET' failed."
227 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
228 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
229 rm -rf $PKGMK_WORK_DIR
231 info
"Md5sum not found."
235 warning
"Md5sum not found, creating new."
236 make_md5sum
> $PKGMK_MD5SUM
239 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
240 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
241 rm -rf $PKGMK_WORK_DIR
253 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
254 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
259 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
260 case $
(file -b "$FILE") in
261 *ELF
*executable
*not\ stripped
)
262 strip
--strip-all "$FILE"
264 *ELF
*shared\ object
*not\ stripped
)
265 strip
--strip-unneeded "$FILE"
267 current\
ar\ archive
)
268 strip
--strip-debug "$FILE"
273 compress_manpages
() {
274 local FILE DIR TARGET
278 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
279 if [ "$FILE" = "${FILE%%.gz}" ]; then
284 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
285 TARGET
=`readlink -n "$FILE"`
286 TARGET
="${TARGET##*/}"
287 TARGET
="${TARGET%%.gz}.gz"
289 FILE
="${FILE%%.gz}.gz"
290 DIR
=`dirname "$FILE"`
292 if [ -e "$DIR/$TARGET" ]; then
293 ln -sf "$TARGET" "$FILE"
299 local FILE
="$PKGMK_WORK_DIR/.tmp"
303 if [ -f $TARGET ]; then
304 make_footprint
> $FILE.footprint
305 if [ -f $PKGMK_FOOTPRINT ]; then
306 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
307 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
311 sed 's/^+/NEW /g' | \
312 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
313 if [ -s $FILE.footprint.
diff ]; then
314 error
"Footprint mismatch found:"
315 cat $FILE.footprint.
diff >&2
316 BUILD_SUCCESSFUL
="no"
319 warning
"Footprint not found, creating new."
320 mv $FILE.footprint
$PKGMK_FOOTPRINT
323 error
"Package '$TARGET' was not found."
324 BUILD_SUCCESSFUL
="no"
329 export PKG
="$PKGMK_WORK_DIR/pkg"
330 export SRC
="$PKGMK_WORK_DIR/src"
337 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
343 rm -rf $PKGMK_WORK_DIR
348 local BUILD_SUCCESSFUL
="no"
352 if [ "$UID" != "0" ]; then
353 warning
"Packages should be built as root."
356 info
"Building '$TARGET'."
364 if [ "$PKGMK_NO_STRIP" = "no" ]; then
375 BUILD_SUCCESSFUL
="yes"
377 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
378 warning
"Footprint ignored."
385 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
389 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
390 info
"Building '$TARGET' succeeded."
392 if [ -f $TARGET ]; then
393 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
395 error
"Building '$TARGET' failed."
403 info
"Installing '$TARGET'."
405 if [ "$PKGMK_INSTALL" = "install" ]; then
406 COMMAND
="pkgadd $TARGET"
408 COMMAND
="pkgadd -u $TARGET"
416 info
"Installing '$TARGET' succeeded."
418 error
"Installing '$TARGET' failed."
426 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
428 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
429 DIR
="`dirname $FILE`/"
431 info
"Entering directory '$DIR'."
432 (cd $DIR && $PKGMK_COMMAND $ARGS)
433 info
"Leaving directory '$DIR'."
439 local FILE LOCAL_FILENAME
441 if [ -f $TARGET ]; then
442 info
"Removing $TARGET"
446 for FILE
in ${source[@]}; do
447 LOCAL_FILENAME
=`get_filename $FILE`
448 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
449 info
"Removing $LOCAL_FILENAME"
450 rm -f $LOCAL_FILENAME
456 if [ ! -f $TARGET ]; then
457 error
"Unable to update footprint. File '$TARGET' not found."
461 make_footprint
> $PKGMK_FOOTPRINT
464 info
"Footprint updated."
471 if [ -f $TARGET ]; then
473 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
474 FILE
=`get_filename $FILE`
475 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
489 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
490 rm -rf $PKGMK_WORK_DIR
497 echo "usage: `basename $PKGMK_COMMAND` [options]"
499 echo " -i, --install build and install package"
500 echo " -u, --upgrade build and install package (as upgrade)"
501 echo " -r, --recursive search for and build packages recursively"
502 echo " -d, --download download missing source file(s)"
503 echo " -do, --download-only do not build, only download missing source file(s)"
504 echo " -eo, --extract-only do not build, only extract source file(s)"
505 echo " -utd, --up-to-date do not build, only check if package is up to date"
506 echo " -uf, --update-footprint update footprint using result from last build"
507 echo " -if, --ignore-footprint build package without checking footprint"
508 echo " -um, --update-md5sum update md5sum"
509 echo " -im, --ignore-md5sum build package without checking md5sum"
510 echo " -cm, --check-md5sum do not build, only check md5sum"
511 echo " -ns, --no-strip do not strip executable binaries or libraries"
512 echo " -f, --force build package even if it appears to be up to date"
513 echo " -c, --clean remove package and downloaded files"
514 echo " -kw, --keep-work keep temporary working directory"
515 echo " -cf, --config-file <file> use alternative configuration file"
516 echo " -v, --version print version and exit "
517 echo " -h, --help print help and exit"
524 PKGMK_INSTALL
="install" ;;
526 PKGMK_INSTALL
="upgrade" ;;
528 PKGMK_RECURSIVE
="yes" ;;
530 PKGMK_DOWNLOAD
="yes" ;;
533 PKGMK_DOWNLOAD_ONLY
="yes" ;;
535 PKGMK_EXTRACT_ONLY
="yes" ;;
537 PKGMK_UP_TO_DATE
="yes" ;;
538 -uf|--update-footprint)
539 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
540 -if|--ignore-footprint)
541 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
543 PKGMK_UPDATE_MD5SUM
="yes" ;;
545 PKGMK_IGNORE_MD5SUM
="yes" ;;
547 PKGMK_CHECK_MD5SUM
="yes" ;;
549 PKGMK_NO_STRIP
="yes" ;;
555 PKGMK_KEEP_WORK
="yes" ;;
558 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
564 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
570 echo "`basename $PKGMK_COMMAND`: invalid option $1"
582 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
587 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
588 if [ ! -f $FILE ]; then
589 error
"File '$FILE' not found."
595 check_directory
"$PKGMK_SOURCE_DIR"
596 check_directory
"$PKGMK_PACKAGE_DIR"
597 check_directory
"`dirname $PKGMK_WORK_DIR`"
601 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
603 if [ "$PKGMK_CLEAN" = "yes" ]; then
608 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
613 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
615 make_md5sum
> $PKGMK_MD5SUM
616 info
"Md5sum updated."
620 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
625 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
628 info
"Extracting sources of package '$name-$version'."
633 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
634 if [ "`build_needed`" = "yes" ]; then
635 info
"Package '$TARGET' is not up to date."
637 info
"Package '$TARGET' is up to date."
642 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
643 info
"Package '$TARGET' is up to date."
649 if [ "$PKGMK_INSTALL" != "no" ]; then
656 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
660 readonly PKGMK_VERSION
="#VERSION#"
661 readonly PKGMK_COMMAND
="$0"
662 readonly PKGMK_ROOT
="$PWD"
664 PKGMK_CONFFILE
="/etc/pkgmk.conf"
665 PKGMK_PKGFILE
="Pkgfile"
666 PKGMK_FOOTPRINT
=".footprint"
667 PKGMK_MD5SUM
=".md5sum"
668 PKGMK_NOSTRIP
=".nostrip"
670 PKGMK_SOURCE_MIRRORS
=()
671 PKGMK_SOURCE_DIR
="$PWD"
672 PKGMK_PACKAGE_DIR
="$PWD"
673 PKGMK_WORK_DIR
="$PWD/work"
678 PKGMK_DOWNLOAD_ONLY
="no"
679 PKGMK_EXTRACT_ONLY
="no"
680 PKGMK_UP_TO_DATE
="no"
681 PKGMK_UPDATE_FOOTPRINT
="no"
682 PKGMK_IGNORE_FOOTPRINT
="no"
685 PKGMK_UPDATE_MD5SUM
="no"
686 PKGMK_IGNORE_MD5SUM
="no"
687 PKGMK_CHECK_MD5SUM
="no"