5 # Copyright (c) 2000-2005 Per Liden
6 # Copyright (c) 2006-2013 by CRUX team (http://crux.nu)
8 # Patches for crosscompilation by Jose V Beneyto <sepen@crux.nu>
9 # (CRUX-ARM System Team <devel@crux-arm.nu>)
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
30 E_PKGFILE
=2 # invalid Pkgfile
31 E_DIR_PERM
=3 # (source/build) directory missing or missing read/write permission
32 E_DOWNLOAD
=4 # error during download
33 E_UNPACK
=5 # error during unpacking of source file(s)
34 E_MD5
=6 # md5sum verification failed
35 E_FOOTPRINT
=7 # footprint check failure
36 E_BUILD
=8 # error while running 'build()'
37 E_INSTALL
=9 # error while installing the package via 'pkgadd'
44 info
"WARNING: $1" >&2
52 if [[ $1 =~ ^
(http
|https
|ftp|file)://.
*/(.
+) ]]; then
53 echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}"
60 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
65 if [ ! "$name" ]; then
66 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
68 elif [ ! "$version" ]; then
69 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
71 elif [ ! "$release" ]; then
72 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
74 elif [ "`type -t build`" != "function" ]; then
75 error
"Function 'build' not specified in $PKGMK_PKGFILE."
82 error
"Directory '$1' does not exist."
84 elif [ ! -w $1 ]; then
85 error
"Directory '$1' not writable."
87 elif [ ! -x $1 ] || [ ! -r $1 ]; then
88 error
"Directory '$1' not readable."
94 if [ -e $1 ] && [ ! -w $1 ]; then
95 error
"File '$1' is not writable."
101 info
"Downloading '$1'."
103 if [ ! "`type -p wget`" ]; then
104 error
"Command 'wget' not found."
108 LOCAL_FILENAME
=`get_filename $1`
109 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
110 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
111 --directory-prefix=$PKGMK_SOURCE_DIR \
112 --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
114 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
115 info
"Partial download found, trying to resume"
121 BASENAME
=`get_basename $1`
122 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
123 REPO
="`echo $REPO | sed 's|/$||'`"
124 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
126 if [ $error == 0 ]; then
131 if [ $error != 0 ]; then
133 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
135 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
136 info
"Partial download failed, restarting"
137 rm -f "$LOCAL_FILENAME_PARTIAL"
145 if [ $error != 0 ]; then
146 error
"Downloading '$1' failed."
150 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
154 local FILE LOCAL_FILENAME
156 for FILE
in ${source[@]}; do
157 LOCAL_FILENAME
=`get_filename $FILE`
158 if [ ! -e $LOCAL_FILENAME ]; then
159 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
160 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
163 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
166 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
175 local FILE LOCAL_FILENAME COMMAND
177 for FILE
in ${source[@]}; do
178 LOCAL_FILENAME
=`get_filename $FILE`
179 case $LOCAL_FILENAME in
180 *.
tar|*.
tar.gz
|*.
tar.Z
|*.tgz
|*.
tar.bz2
|*.tbz2
|*.
tar.xz
|*.txz
|*.
tar.lzma
|*.
zip|*.rpm
)
181 COMMAND
="bsdtar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
183 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
191 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
192 rm -rf $PKGMK_WORK_DIR
194 error
"Building '$TARGET' failed."
201 local FILE LOCAL_FILENAMES
203 if [ "$source" ]; then
204 for FILE
in ${source[@]}; do
205 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
208 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
213 pkginfo
--footprint $TARGET | \
214 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
219 local FILE
="$PKGMK_WORK_DIR/.tmp"
223 if [ -f $PKGMK_MD5SUM ]; then
224 make_md5sum
> $FILE.
md5sum
225 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
226 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
230 sed 's/^+/NEW /g' | \
231 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
232 if [ -s $FILE.
md5sum.
diff ]; then
233 error
"Md5sum mismatch found:"
234 cat $FILE.
md5sum.
diff >&2
236 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
237 rm -rf $PKGMK_WORK_DIR
240 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
241 error
"Md5sum not ok."
245 error
"Building '$TARGET' failed."
249 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
250 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
251 rm -rf $PKGMK_WORK_DIR
253 info
"Md5sum not found."
257 warning
"Md5sum not found, creating new."
258 make_md5sum
> $PKGMK_MD5SUM
261 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
262 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
263 rm -rf $PKGMK_WORK_DIR
275 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
276 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
281 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
282 case $
(file -b "$FILE") in
283 *ELF
*executable
*not\ stripped
)
284 $STRIP_CMD --strip-all "$FILE"
286 *ELF
*shared\ object
*not\ stripped
)
287 $STRIP_CMD --strip-unneeded "$FILE"
289 current\
ar\ archive
)
290 $STRIP_CMD --strip-debug "$FILE"
295 compress_manpages
() {
296 local FILE DIR TARGET
300 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
301 if [ "$FILE" = "${FILE%%.gz}" ]; then
306 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
307 TARGET
=`readlink -n "$FILE"`
308 TARGET
="${TARGET##*/}"
309 TARGET
="${TARGET%%.gz}.gz"
311 FILE
="${FILE%%.gz}.gz"
312 DIR
=`dirname "$FILE"`
314 if [ -e "$DIR/$TARGET" ]; then
315 ln -sf "$TARGET" "$FILE"
321 # remove the last / from CLFS path if appeared
324 find $PKG -type f
-name '*.la' -exec sed -e "s|$CLFS||g" -e "s|$CROSTOOLS/$CTARGET|/usr|g" -i {} \
;
328 local FILE
="$PKGMK_WORK_DIR/.tmp"
332 if [ -f $TARGET ]; then
333 make_footprint
> $FILE.footprint
334 if [ -f $PKGMK_FOOTPRINT ]; then
335 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
336 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
340 sed 's/^+/NEW /g' | \
341 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
342 if [ -s $FILE.footprint.
diff ]; then
343 if [ "$PKGMK_IGNORE_NEW" = "yes" ] && \
344 [ -z "$(egrep -l ^MISSING $FILE.footprint.diff)" ] ; then
345 info
"New files found:"
347 error
"Footprint mismatch found:"
348 BUILD_SUCCESSFUL
="no"
350 cat $FILE.footprint.
diff >&2
353 warning
"Footprint not found, creating new."
354 mv $FILE.footprint
$PKGMK_FOOTPRINT
357 error
"Package '$TARGET' was not found."
358 BUILD_SUCCESSFUL
="no"
363 export PKG
="$PKGMK_WORK_DIR/pkg"
364 export SRC
="$PKGMK_WORK_DIR/src"
371 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
377 rm -rf $PKGMK_WORK_DIR
382 local BUILD_SUCCESSFUL
="no"
388 if [ "$UID" != "0" ]; then
389 warning
"Packages should be built as root."
392 info
"Building '$TARGET'."
400 if [ "$PKGMK_NO_STRIP" = "no" ]; then
410 case $PKGMK_COMPRESSION_MODE in
411 gz
) COMPRESSION
="-z" ;;
412 bz2
) COMPRESSION
="-j" ;;
413 xz
) COMPRESSION
="-J" ;;
415 bsdtar
-c $COMPRESSION -f $TARGET * && bsdtar
-t -v -f $TARGET
418 BUILD_SUCCESSFUL
="yes"
420 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
421 warning
"Footprint ignored."
428 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
432 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
433 info
"Building '$TARGET' succeeded."
435 if [ -f $TARGET ]; then
436 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
438 error
"Building '$TARGET' failed."
446 info
"Installing '$TARGET'."
448 if [ "$PKGMK_INSTALL" = "install" ]; then
449 COMMAND
="pkgadd $TARGET"
451 COMMAND
="pkgadd -u $TARGET"
459 info
"Installing '$TARGET' succeeded."
461 error
"Installing '$TARGET' failed."
469 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
471 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
472 DIR
="`dirname $FILE`/"
474 info
"Entering directory '$DIR'."
475 (cd $DIR && $PKGMK_COMMAND $ARGS)
476 info
"Leaving directory '$DIR'."
482 local FILE LOCAL_FILENAME
484 if [ -f $TARGET ]; then
485 info
"Removing $TARGET"
489 for FILE
in ${source[@]}; do
490 LOCAL_FILENAME
=`get_filename $FILE`
491 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
492 info
"Removing $LOCAL_FILENAME"
493 rm -f $LOCAL_FILENAME
499 if [ ! -f $TARGET ]; then
500 error
"Unable to update footprint. File '$TARGET' not found."
504 check_file
"$PKGMK_FOOTPRINT"
505 make_footprint
> $PKGMK_FOOTPRINT
508 info
"Footprint updated."
515 if [ -f $TARGET ]; then
517 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
518 FILE
=`get_filename $FILE`
519 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
533 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
534 rm -rf $PKGMK_WORK_DIR
541 echo "usage: `basename $PKGMK_COMMAND` [options]"
543 echo " -i, --install build and install package"
544 echo " -u, --upgrade build and install package (as upgrade)"
545 echo " -r, --recursive search for and build packages recursively"
546 echo " -d, --download download missing source file(s)"
547 echo " -do, --download-only do not build, only download missing source file(s)"
548 echo " -eo, --extract-only do not build, only extract source file(s)"
549 echo " -utd, --up-to-date do not build, only check if package is up to date"
550 echo " -uf, --update-footprint update footprint using result from last build"
551 echo " -if, --ignore-footprint build package without checking footprint"
552 echo " -in, --ignore-new build package, ignore new files in a footprint missmatch"
553 echo " -um, --update-md5sum update md5sum"
554 echo " -im, --ignore-md5sum build package without checking md5sum"
555 echo " -cm, --check-md5sum do not build, only check md5sum"
556 echo " -ns, --no-strip do not strip executable binaries or libraries"
557 echo " -f, --force build package even if it appears to be up to date"
558 echo " -c, --clean remove package and downloaded files"
559 echo " -kw, --keep-work keep temporary working directory"
560 echo " -cf, --config-file <file> use alternative configuration file"
561 echo " -v, --version print version and exit "
562 echo " -h, --help print help and exit"
569 PKGMK_INSTALL
="install" ;;
571 PKGMK_INSTALL
="upgrade" ;;
573 PKGMK_RECURSIVE
="yes" ;;
575 PKGMK_DOWNLOAD
="yes" ;;
578 PKGMK_DOWNLOAD_ONLY
="yes" ;;
580 PKGMK_EXTRACT_ONLY
="yes" ;;
582 PKGMK_UP_TO_DATE
="yes" ;;
583 -uf|--update-footprint)
584 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
585 -if|--ignore-footprint)
586 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
588 PKGMK_IGNORE_NEW
="yes" ;;
590 PKGMK_UPDATE_MD5SUM
="yes" ;;
592 PKGMK_IGNORE_MD5SUM
="yes" ;;
594 PKGMK_CHECK_MD5SUM
="yes" ;;
596 PKGMK_NO_STRIP
="yes" ;;
602 PKGMK_KEEP_WORK
="yes" ;;
605 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
611 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
617 echo "`basename $PKGMK_COMMAND`: invalid option $1"
629 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
634 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
635 if [ ! -f $FILE ]; then
636 error
"File '$FILE' not found."
642 check_directory
"$PKGMK_SOURCE_DIR"
643 check_directory
"$PKGMK_PACKAGE_DIR"
644 check_directory
"`dirname $PKGMK_WORK_DIR`"
648 case $PKGMK_COMPRESSION_MODE in
650 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.$PKGMK_COMPRESSION_MODE"
653 error
"Compression mode '$PKGMK_COMPRESSION_MODE' not supported"
658 if [ "$PKGMK_CLEAN" = "yes" ]; then
663 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
668 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
670 check_file
"$PKGMK_MD5SUM"
671 make_md5sum
> $PKGMK_MD5SUM
672 info
"Md5sum updated."
676 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
681 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
684 info
"Extracting sources of package '$name-$version'."
689 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
690 if [ "`build_needed`" = "yes" ]; then
691 info
"Package '$TARGET' is not up to date."
693 info
"Package '$TARGET' is up to date."
698 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
699 info
"Package '$TARGET' is up to date."
705 if [ "$PKGMK_INSTALL" != "no" ]; then
712 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
716 readonly PKGMK_VERSION
="#VERSION#"
717 readonly PKGMK_COMMAND
="$0"
718 readonly PKGMK_ROOT
="$PWD"
720 PKGMK_CONFFILE
="/etc/pkgmk.conf"
721 PKGMK_PKGFILE
="Pkgfile"
722 PKGMK_FOOTPRINT
=".footprint"
723 PKGMK_MD5SUM
=".md5sum"
724 PKGMK_NOSTRIP
=".nostrip"
726 PKGMK_SOURCE_MIRRORS
=()
727 PKGMK_SOURCE_DIR
="$PWD"
728 PKGMK_PACKAGE_DIR
="$PWD"
729 PKGMK_WORK_DIR
="$PWD/work"
731 PKGMK_COMPRESSION_MODE
="gz"
736 PKGMK_DOWNLOAD_ONLY
="no"
737 PKGMK_EXTRACT_ONLY
="no"
738 PKGMK_UP_TO_DATE
="no"
739 PKGMK_UPDATE_FOOTPRINT
="no"
740 PKGMK_IGNORE_FOOTPRINT
="no"
741 PKGMK_IGNORE_NEW
="no"
744 PKGMK_UPDATE_MD5SUM
="no"
745 PKGMK_IGNORE_MD5SUM
="no"
746 PKGMK_CHECK_MD5SUM
="no"