5 # Copyright (c) 2000-2005 Per Liden
6 # Copyright (c) 2006-2010 by CRUX team (http://crux.nu)
7 # Patches for crosscompilation by Jose V Beneyto <sepen@crux.nu>
8 # (CRUX-ARM System Team <devel@crux-arm.nu>)
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
29 E_PKGFILE
=2 # invalid Pkgfile
30 E_DIR_PERM
=3 # (source/build) directory missing or missing read/write permission
31 E_DOWNLOAD
=4 # error during download
32 E_UNPACK
=5 # error during unpacking of source file(s)
33 E_MD5
=6 # md5sum verification failed
34 E_FOOTPRINT
=7 # footprint check failure
35 E_BUILD
=8 # error while running 'build()'
36 E_INSTALL
=9 # error while installing the package via 'pkgadd'
43 info
"WARNING: $1" >&2
51 if [[ $1 =~ ^
(http
|https
|ftp|file)://.
*/(.
+) ]]; then
52 echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}"
59 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
64 if [ ! "$name" ]; then
65 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
67 elif [ ! "$version" ]; then
68 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
70 elif [ ! "$release" ]; then
71 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
73 elif [ "`type -t build`" != "function" ]; then
74 error
"Function 'build' not specified in $PKGMK_PKGFILE."
81 error
"Directory '$1' does not exist."
83 elif [ ! -w $1 ]; then
84 error
"Directory '$1' not writable."
86 elif [ ! -x $1 ] || [ ! -r $1 ]; then
87 error
"Directory '$1' not readable."
93 if [ -e $1 ] && [ ! -w $1 ]; then
94 error
"File '$1' is not writable."
100 info
"Downloading '$1'."
102 if [ ! "`type -p wget`" ]; then
103 error
"Command 'wget' not found."
107 LOCAL_FILENAME
=`get_filename $1`
108 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
109 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
110 --directory-prefix=$PKGMK_SOURCE_DIR \
111 --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
113 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
114 info
"Partial download found, trying to resume"
120 BASENAME
=`get_basename $1`
121 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
122 REPO
="`echo $REPO | sed 's|/$||'`"
123 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
125 if [ $error == 0 ]; then
130 if [ $error != 0 ]; then
132 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
134 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
135 info
"Partial download failed, restarting"
136 rm -f "$LOCAL_FILENAME_PARTIAL"
144 if [ $error != 0 ]; then
145 error
"Downloading '$1' failed."
149 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
153 local FILE LOCAL_FILENAME
155 for FILE
in ${source[@]}; do
156 LOCAL_FILENAME
=`get_filename $FILE`
157 if [ ! -e $LOCAL_FILENAME ]; then
158 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
159 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
162 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
165 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
174 local FILE LOCAL_FILENAME COMMAND
176 for FILE
in ${source[@]}; do
177 LOCAL_FILENAME
=`get_filename $FILE`
178 case $LOCAL_FILENAME in
179 *.
tar.gz
|*.
tar.Z
|*.tgz
|*.
tar.bz2
|*.tbz2
|*.
tar.xz
|*.txz
|*.
tar.lzma
|*.
zip|*.rpm
)
180 COMMAND
="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
182 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
190 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
191 rm -rf $PKGMK_WORK_DIR
193 error
"Building '$TARGET' failed."
200 local FILE LOCAL_FILENAMES
202 if [ "$source" ]; then
203 for FILE
in ${source[@]}; do
204 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
207 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
212 pkginfo
--footprint $TARGET | \
213 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
218 local FILE
="$PKGMK_WORK_DIR/.tmp"
222 if [ -f $PKGMK_MD5SUM ]; then
223 make_md5sum
> $FILE.
md5sum
224 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
225 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
229 sed 's/^+/NEW /g' | \
230 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
231 if [ -s $FILE.
md5sum.
diff ]; then
232 error
"Md5sum mismatch found:"
233 cat $FILE.
md5sum.
diff >&2
235 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
236 rm -rf $PKGMK_WORK_DIR
239 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
240 error
"Md5sum not ok."
244 error
"Building '$TARGET' failed."
248 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
249 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
250 rm -rf $PKGMK_WORK_DIR
252 info
"Md5sum not found."
256 warning
"Md5sum not found, creating new."
257 make_md5sum
> $PKGMK_MD5SUM
260 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
261 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
262 rm -rf $PKGMK_WORK_DIR
274 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
275 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
280 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
281 case $
(file -b "$FILE") in
282 *ELF
*executable
*not\ stripped
)
283 $STRIP_CMD --strip-all "$FILE"
285 *ELF
*shared\ object
*not\ stripped
)
286 $STRIP_CMD --strip-unneeded "$FILE"
288 current\
ar\ archive
)
289 $STRIP_CMD --strip-debug "$FILE"
294 compress_manpages
() {
295 local FILE DIR TARGET
299 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
300 if [ "$FILE" = "${FILE%%.gz}" ]; then
305 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
306 TARGET
=`readlink -n "$FILE"`
307 TARGET
="${TARGET##*/}"
308 TARGET
="${TARGET%%.gz}.gz"
310 FILE
="${FILE%%.gz}.gz"
311 DIR
=`dirname "$FILE"`
313 if [ -e "$DIR/$TARGET" ]; then
314 ln -sf "$TARGET" "$FILE"
320 # remove the last / from CLFS path if appeared
323 find $PKG -type f
-name '*.la' -exec sed -e "s|$CLFS||g" -e "s|$CROSTOOLS/$CTARGET|/usr|g" -i {} \
;
327 local FILE
="$PKGMK_WORK_DIR/.tmp"
331 if [ -f $TARGET ]; then
332 make_footprint
> $FILE.footprint
333 if [ -f $PKGMK_FOOTPRINT ]; then
334 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
335 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
339 sed 's/^+/NEW /g' | \
340 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
341 if [ -s $FILE.footprint.
diff ]; then
342 if [ "$PKGMK_IGNORE_NEW" = "yes" ] && \
343 [ -z "$(egrep -l ^MISSING $FILE.footprint.diff)" ] ; then
344 info
"New files found:"
346 error
"Footprint mismatch found:"
347 BUILD_SUCCESSFUL
="no"
349 cat $FILE.footprint.
diff >&2
352 warning
"Footprint not found, creating new."
353 mv $FILE.footprint
$PKGMK_FOOTPRINT
356 error
"Package '$TARGET' was not found."
357 BUILD_SUCCESSFUL
="no"
362 export PKG
="$PKGMK_WORK_DIR/pkg"
363 export SRC
="$PKGMK_WORK_DIR/src"
370 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
376 rm -rf $PKGMK_WORK_DIR
381 local BUILD_SUCCESSFUL
="no"
387 if [ "$UID" != "0" ]; then
388 warning
"Packages should be built as root."
391 info
"Building '$TARGET'."
399 if [ "$PKGMK_NO_STRIP" = "no" ]; then
409 case $PKGMK_COMPRESSION_MODE in
410 gz
) COMPRESSION
="-z" ;;
411 bz2
) COMPRESSION
="-j" ;;
412 xz
) COMPRESSION
="-J" ;;
414 bsdtar
-c $COMPRESSION -f $TARGET * && bsdtar
-t -v -f $TARGET
417 BUILD_SUCCESSFUL
="yes"
419 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
420 warning
"Footprint ignored."
427 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
431 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
432 info
"Building '$TARGET' succeeded."
434 if [ -f $TARGET ]; then
435 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
437 error
"Building '$TARGET' failed."
445 info
"Installing '$TARGET'."
447 if [ "$PKGMK_INSTALL" = "install" ]; then
448 COMMAND
="pkgadd $TARGET"
450 COMMAND
="pkgadd -u $TARGET"
458 info
"Installing '$TARGET' succeeded."
460 error
"Installing '$TARGET' failed."
468 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
470 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
471 DIR
="`dirname $FILE`/"
473 info
"Entering directory '$DIR'."
474 (cd $DIR && $PKGMK_COMMAND $ARGS)
475 info
"Leaving directory '$DIR'."
481 local FILE LOCAL_FILENAME
483 if [ -f $TARGET ]; then
484 info
"Removing $TARGET"
488 for FILE
in ${source[@]}; do
489 LOCAL_FILENAME
=`get_filename $FILE`
490 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
491 info
"Removing $LOCAL_FILENAME"
492 rm -f $LOCAL_FILENAME
498 if [ ! -f $TARGET ]; then
499 error
"Unable to update footprint. File '$TARGET' not found."
503 check_file
"$PKGMK_FOOTPRINT"
504 make_footprint
> $PKGMK_FOOTPRINT
507 info
"Footprint updated."
514 if [ -f $TARGET ]; then
516 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
517 FILE
=`get_filename $FILE`
518 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
532 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
533 rm -rf $PKGMK_WORK_DIR
540 echo "usage: `basename $PKGMK_COMMAND` [options]"
542 echo " -i, --install build and install package"
543 echo " -u, --upgrade build and install package (as upgrade)"
544 echo " -r, --recursive search for and build packages recursively"
545 echo " -d, --download download missing source file(s)"
546 echo " -do, --download-only do not build, only download missing source file(s)"
547 echo " -eo, --extract-only do not build, only extract source file(s)"
548 echo " -utd, --up-to-date do not build, only check if package is up to date"
549 echo " -uf, --update-footprint update footprint using result from last build"
550 echo " -if, --ignore-footprint build package without checking footprint"
551 echo " -in, --ignore-new build package, ignore new files in a footprint missmatch"
552 echo " -um, --update-md5sum update md5sum"
553 echo " -im, --ignore-md5sum build package without checking md5sum"
554 echo " -cm, --check-md5sum do not build, only check md5sum"
555 echo " -ns, --no-strip do not strip executable binaries or libraries"
556 echo " -f, --force build package even if it appears to be up to date"
557 echo " -c, --clean remove package and downloaded files"
558 echo " -kw, --keep-work keep temporary working directory"
559 echo " -cf, --config-file <file> use alternative configuration file"
560 echo " -v, --version print version and exit "
561 echo " -h, --help print help and exit"
568 PKGMK_INSTALL
="install" ;;
570 PKGMK_INSTALL
="upgrade" ;;
572 PKGMK_RECURSIVE
="yes" ;;
574 PKGMK_DOWNLOAD
="yes" ;;
577 PKGMK_DOWNLOAD_ONLY
="yes" ;;
579 PKGMK_EXTRACT_ONLY
="yes" ;;
581 PKGMK_UP_TO_DATE
="yes" ;;
582 -uf|--update-footprint)
583 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
584 -if|--ignore-footprint)
585 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
587 PKGMK_IGNORE_NEW
="yes" ;;
589 PKGMK_UPDATE_MD5SUM
="yes" ;;
591 PKGMK_IGNORE_MD5SUM
="yes" ;;
593 PKGMK_CHECK_MD5SUM
="yes" ;;
595 PKGMK_NO_STRIP
="yes" ;;
601 PKGMK_KEEP_WORK
="yes" ;;
604 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
610 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
616 echo "`basename $PKGMK_COMMAND`: invalid option $1"
628 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
633 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
634 if [ ! -f $FILE ]; then
635 error
"File '$FILE' not found."
641 check_directory
"$PKGMK_SOURCE_DIR"
642 check_directory
"$PKGMK_PACKAGE_DIR"
643 check_directory
"`dirname $PKGMK_WORK_DIR`"
647 case $PKGMK_COMPRESSION_MODE in
649 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.$PKGMK_COMPRESSION_MODE"
652 error
"Compression mode '$PKGMK_COMPRESSION_MODE' not supported"
657 if [ "$PKGMK_CLEAN" = "yes" ]; then
662 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
667 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
669 check_file
"$PKGMK_MD5SUM"
670 make_md5sum
> $PKGMK_MD5SUM
671 info
"Md5sum updated."
675 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
680 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
683 info
"Extracting sources of package '$name-$version'."
688 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
689 if [ "`build_needed`" = "yes" ]; then
690 info
"Package '$TARGET' is not up to date."
692 info
"Package '$TARGET' is up to date."
697 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
698 info
"Package '$TARGET' is up to date."
704 if [ "$PKGMK_INSTALL" != "no" ]; then
711 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
715 readonly PKGMK_VERSION
="#VERSION#"
716 readonly PKGMK_COMMAND
="$0"
717 readonly PKGMK_ROOT
="$PWD"
719 PKGMK_CONFFILE
="/etc/pkgmk.conf"
720 PKGMK_PKGFILE
="Pkgfile"
721 PKGMK_FOOTPRINT
=".footprint"
722 PKGMK_MD5SUM
=".md5sum"
723 PKGMK_NOSTRIP
=".nostrip"
725 PKGMK_SOURCE_MIRRORS
=()
726 PKGMK_SOURCE_DIR
="$PWD"
727 PKGMK_PACKAGE_DIR
="$PWD"
728 PKGMK_WORK_DIR
="$PWD/work"
730 PKGMK_COMPRESSION_MODE
="gz"
735 PKGMK_DOWNLOAD_ONLY
="no"
736 PKGMK_EXTRACT_ONLY
="no"
737 PKGMK_UP_TO_DATE
="no"
738 PKGMK_UPDATE_FOOTPRINT
="no"
739 PKGMK_IGNORE_FOOTPRINT
="no"
740 PKGMK_IGNORE_NEW
="no"
743 PKGMK_UPDATE_MD5SUM
="no"
744 PKGMK_IGNORE_MD5SUM
="no"
745 PKGMK_CHECK_MD5SUM
="no"