5 # Copyright (c) 2000-2005 Per Liden
6 # Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
8 # Patches for crosscompilation by Jose V Beneyto <sepen@crux.nu>
9 # (CRUX-ARM System Team <crux-arm@mikeux.dyndns.org>)
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,
32 info
"WARNING: $1" >&2
40 if [[ $1 =~ ^
(http
|https
|ftp|file)://.
*/(.
+) ]]; then
41 echo "$PKGMK_SOURCE_DIR/${BASH_REMATCH[2]}"
48 local FILE
="`echo $1 | sed 's|^.*://.*/||g'`"
53 if [ ! "$name" ]; then
54 error
"Variable 'name' not specified in $PKGMK_PKGFILE."
56 elif [ ! "$version" ]; then
57 error
"Variable 'version' not specified in $PKGMK_PKGFILE."
59 elif [ ! "$release" ]; then
60 error
"Variable 'release' not specified in $PKGMK_PKGFILE."
62 elif [ "`type -t build`" != "function" ]; then
63 error
"Function 'build' not specified in $PKGMK_PKGFILE."
70 error
"Directory '$1' does not exist."
72 elif [ ! -w $1 ]; then
73 error
"Directory '$1' not writable."
75 elif [ ! -x $1 ] || [ ! -r $1 ]; then
76 error
"Directory '$1' not readable."
82 if [ -e $1 ] && [ ! -w $1 ]; then
83 error
"File '$1' is not writable."
89 info
"Downloading '$1'."
91 if [ ! "`type -p wget`" ]; then
92 error
"Command 'wget' not found."
96 LOCAL_FILENAME
=`get_filename $1`
97 LOCAL_FILENAME_PARTIAL
="$LOCAL_FILENAME.partial"
98 DOWNLOAD_OPTS
="--passive-ftp --no-directories --tries=3 --waitretry=3 \
99 --directory-prefix=$PKGMK_SOURCE_DIR \
100 --output-document=$LOCAL_FILENAME_PARTIAL --no-check-certificate"
102 if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
103 info
"Partial download found, trying to resume"
109 BASENAME
=`get_basename $1`
110 for REPO
in ${PKGMK_SOURCE_MIRRORS[@]}; do
111 REPO
="`echo $REPO | sed 's|/$||'`"
112 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $REPO/$BASENAME
114 if [ $error == 0 ]; then
119 if [ $error != 0 ]; then
121 wget
$RESUME_CMD $DOWNLOAD_OPTS $PKGMK_WGET_OPTS $1
123 if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
124 info
"Partial download failed, restarting"
125 rm -f "$LOCAL_FILENAME_PARTIAL"
133 if [ $error != 0 ]; then
134 error
"Downloading '$1' failed."
138 mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
142 local FILE LOCAL_FILENAME
144 for FILE
in ${source[@]}; do
145 LOCAL_FILENAME
=`get_filename $FILE`
146 if [ ! -e $LOCAL_FILENAME ]; then
147 if [ "$LOCAL_FILENAME" = "$FILE" ]; then
148 error
"Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
151 if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
154 error
"Source file '$LOCAL_FILENAME' not found (use option -d to download)."
163 local FILE LOCAL_FILENAME COMMAND
165 for FILE
in ${source[@]}; do
166 LOCAL_FILENAME
=`get_filename $FILE`
167 case $LOCAL_FILENAME in
168 *.
tar.gz
|*.
tar.Z
|*.tgz
|*.
tar.bz2
|*.
tar.xz
|*.
tar.lzma
|*.
zip)
169 COMMAND
="bsdtar -m -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
171 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
179 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
180 rm -rf $PKGMK_WORK_DIR
182 error
"Building '$TARGET' failed."
189 local FILE LOCAL_FILENAMES
191 if [ "$source" ]; then
192 for FILE
in ${source[@]}; do
193 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
196 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
201 pkginfo
--footprint $TARGET | \
202 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
207 local FILE
="$PKGMK_WORK_DIR/.tmp"
211 if [ -f $PKGMK_MD5SUM ]; then
212 make_md5sum
> $FILE.
md5sum
213 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
214 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
218 sed 's/^+/NEW /g' | \
219 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
220 if [ -s $FILE.
md5sum.
diff ]; then
221 error
"Md5sum mismatch found:"
222 cat $FILE.
md5sum.
diff >&2
224 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
225 rm -rf $PKGMK_WORK_DIR
228 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
229 error
"Md5sum not ok."
233 error
"Building '$TARGET' failed."
237 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
238 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
239 rm -rf $PKGMK_WORK_DIR
241 info
"Md5sum not found."
245 warning
"Md5sum not found, creating new."
246 make_md5sum
> $PKGMK_MD5SUM
249 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
250 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
251 rm -rf $PKGMK_WORK_DIR
263 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
264 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
269 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
270 case $
(file -b "$FILE") in
271 *ELF
*executable
*not\ stripped
)
272 $STRIP_CMD --strip-all "$FILE"
274 *ELF
*shared\ object
*not\ stripped
)
275 $STRIP_CMD --strip-unneeded "$FILE"
277 current\
ar\ archive
)
278 $STRIP_CMD --strip-debug "$FILE"
283 compress_manpages
() {
284 local FILE DIR TARGET
288 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
289 if [ "$FILE" = "${FILE%%.gz}" ]; then
294 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
295 TARGET
=`readlink -n "$FILE"`
296 TARGET
="${TARGET##*/}"
297 TARGET
="${TARGET%%.gz}.gz"
299 FILE
="${FILE%%.gz}.gz"
300 DIR
=`dirname "$FILE"`
302 if [ -e "$DIR/$TARGET" ]; then
303 ln -sf "$TARGET" "$FILE"
309 local FILE
="$PKGMK_WORK_DIR/.tmp"
313 if [ -f $TARGET ]; then
314 make_footprint
> $FILE.footprint
315 if [ -f $PKGMK_FOOTPRINT ]; then
316 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
317 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
321 sed 's/^+/NEW /g' | \
322 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
323 if [ -s $FILE.footprint.
diff ]; then
324 error
"Footprint mismatch found:"
325 cat $FILE.footprint.
diff >&2
326 BUILD_SUCCESSFUL
="no"
329 warning
"Footprint not found, creating new."
330 mv $FILE.footprint
$PKGMK_FOOTPRINT
333 error
"Package '$TARGET' was not found."
334 BUILD_SUCCESSFUL
="no"
339 export PKG
="$PKGMK_WORK_DIR/pkg"
340 export SRC
="$PKGMK_WORK_DIR/src"
347 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
353 rm -rf $PKGMK_WORK_DIR
358 local BUILD_SUCCESSFUL
="no"
363 if [ "$UID" != "0" ]; then
364 warning
"Packages should be built as root."
367 info
"Building '$TARGET'."
375 if [ "$PKGMK_NO_STRIP" = "no" ]; then
386 BUILD_SUCCESSFUL
="yes"
388 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
389 warning
"Footprint ignored."
396 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
400 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
401 info
"Building '$TARGET' succeeded."
403 if [ -f $TARGET ]; then
404 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
406 error
"Building '$TARGET' failed."
414 info
"Installing '$TARGET'."
416 if [ "$PKGMK_INSTALL" = "install" ]; then
417 COMMAND
="pkgadd $TARGET"
419 COMMAND
="pkgadd -u $TARGET"
427 info
"Installing '$TARGET' succeeded."
429 error
"Installing '$TARGET' failed."
437 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
439 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
440 DIR
="`dirname $FILE`/"
442 info
"Entering directory '$DIR'."
443 (cd $DIR && $PKGMK_COMMAND $ARGS)
444 info
"Leaving directory '$DIR'."
450 local FILE LOCAL_FILENAME
452 if [ -f $TARGET ]; then
453 info
"Removing $TARGET"
457 for FILE
in ${source[@]}; do
458 LOCAL_FILENAME
=`get_filename $FILE`
459 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
460 info
"Removing $LOCAL_FILENAME"
461 rm -f $LOCAL_FILENAME
467 if [ ! -f $TARGET ]; then
468 error
"Unable to update footprint. File '$TARGET' not found."
472 check_file
"$PKGMK_FOOTPRINT"
473 make_footprint
> $PKGMK_FOOTPRINT
476 info
"Footprint updated."
483 if [ -f $TARGET ]; then
485 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
486 FILE
=`get_filename $FILE`
487 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
501 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
502 rm -rf $PKGMK_WORK_DIR
509 echo "usage: `basename $PKGMK_COMMAND` [options]"
511 echo " -i, --install build and install package"
512 echo " -u, --upgrade build and install package (as upgrade)"
513 echo " -r, --recursive search for and build packages recursively"
514 echo " -d, --download download missing source file(s)"
515 echo " -do, --download-only do not build, only download missing source file(s)"
516 echo " -eo, --extract-only do not build, only extract source file(s)"
517 echo " -utd, --up-to-date do not build, only check if package is up to date"
518 echo " -uf, --update-footprint update footprint using result from last build"
519 echo " -if, --ignore-footprint build package without checking footprint"
520 echo " -um, --update-md5sum update md5sum"
521 echo " -im, --ignore-md5sum build package without checking md5sum"
522 echo " -cm, --check-md5sum do not build, only check md5sum"
523 echo " -ns, --no-strip do not strip executable binaries or libraries"
524 echo " -f, --force build package even if it appears to be up to date"
525 echo " -c, --clean remove package and downloaded files"
526 echo " -kw, --keep-work keep temporary working directory"
527 echo " -cf, --config-file <file> use alternative configuration file"
528 echo " -v, --version print version and exit "
529 echo " -h, --help print help and exit"
536 PKGMK_INSTALL
="install" ;;
538 PKGMK_INSTALL
="upgrade" ;;
540 PKGMK_RECURSIVE
="yes" ;;
542 PKGMK_DOWNLOAD
="yes" ;;
545 PKGMK_DOWNLOAD_ONLY
="yes" ;;
547 PKGMK_EXTRACT_ONLY
="yes" ;;
549 PKGMK_UP_TO_DATE
="yes" ;;
550 -uf|--update-footprint)
551 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
552 -if|--ignore-footprint)
553 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
555 PKGMK_UPDATE_MD5SUM
="yes" ;;
557 PKGMK_IGNORE_MD5SUM
="yes" ;;
559 PKGMK_CHECK_MD5SUM
="yes" ;;
561 PKGMK_NO_STRIP
="yes" ;;
567 PKGMK_KEEP_WORK
="yes" ;;
570 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
576 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
582 echo "`basename $PKGMK_COMMAND`: invalid option $1"
594 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
599 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
600 if [ ! -f $FILE ]; then
601 error
"File '$FILE' not found."
607 check_directory
"$PKGMK_SOURCE_DIR"
608 check_directory
"$PKGMK_PACKAGE_DIR"
609 check_directory
"`dirname $PKGMK_WORK_DIR`"
613 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
615 if [ "$PKGMK_CLEAN" = "yes" ]; then
620 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
625 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
627 check_file
"$PKGMK_MD5SUM"
628 make_md5sum
> $PKGMK_MD5SUM
629 info
"Md5sum updated."
633 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
638 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
641 info
"Extracting sources of package '$name-$version'."
646 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
647 if [ "`build_needed`" = "yes" ]; then
648 info
"Package '$TARGET' is not up to date."
650 info
"Package '$TARGET' is up to date."
655 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
656 info
"Package '$TARGET' is up to date."
662 if [ "$PKGMK_INSTALL" != "no" ]; then
669 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
673 readonly PKGMK_VERSION
="#VERSION#"
674 readonly PKGMK_COMMAND
="$0"
675 readonly PKGMK_ROOT
="$PWD"
679 PKGMK_CONFFILE
="/etc/pkgmk.conf"
680 PKGMK_PKGFILE
="Pkgfile"
681 PKGMK_FOOTPRINT
=".footprint"
682 PKGMK_MD5SUM
=".md5sum"
683 PKGMK_NOSTRIP
=".nostrip"
685 PKGMK_SOURCE_MIRRORS
=()
686 PKGMK_SOURCE_DIR
="$PWD"
687 PKGMK_PACKAGE_DIR
="$PWD"
688 PKGMK_WORK_DIR
="$PWD/work"
693 PKGMK_DOWNLOAD_ONLY
="no"
694 PKGMK_EXTRACT_ONLY
="no"
695 PKGMK_UP_TO_DATE
="no"
696 PKGMK_UPDATE_FOOTPRINT
="no"
697 PKGMK_IGNORE_FOOTPRINT
="no"
700 PKGMK_UPDATE_MD5SUM
="no"
701 PKGMK_IGNORE_MD5SUM
="no"
702 PKGMK_CHECK_MD5SUM
="no"