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
)
159 COMMAND
="tar -C $SRC --use-compress-program=gzip -xf $LOCAL_FILENAME" ;;
161 COMMAND
="tar -C $SRC --use-compress-program=bzip2 -xf $LOCAL_FILENAME" ;;
163 COMMAND
="unzip -qq -o -d $SRC $LOCAL_FILENAME" ;;
165 COMMAND
="cp $LOCAL_FILENAME $SRC" ;;
173 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
174 rm -rf $PKGMK_WORK_DIR
176 error
"Building '$TARGET' failed."
183 local FILE LOCAL_FILENAMES
185 if [ "$source" ]; then
186 for FILE
in ${source[@]}; do
187 LOCAL_FILENAMES
="$LOCAL_FILENAMES `get_filename $FILE`"
190 md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
195 pkginfo
--footprint $TARGET | \
196 sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
201 local FILE
="$PKGMK_WORK_DIR/.tmp"
205 if [ -f $PKGMK_MD5SUM ]; then
206 make_md5sum
> $FILE.
md5sum
207 sort -k 2 $PKGMK_MD5SUM > $FILE.
md5sum.orig
208 diff -w -t -U 0 $FILE.
md5sum.orig
$FILE.
md5sum | \
212 sed 's/^+/NEW /g' | \
213 sed 's/^-/MISSING /g' > $FILE.
md5sum.
diff
214 if [ -s $FILE.
md5sum.
diff ]; then
215 error
"Md5sum mismatch found:"
216 cat $FILE.
md5sum.
diff >&2
218 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
219 rm -rf $PKGMK_WORK_DIR
222 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
223 error
"Md5sum not ok."
227 error
"Building '$TARGET' failed."
231 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
232 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
233 rm -rf $PKGMK_WORK_DIR
235 info
"Md5sum not found."
239 warning
"Md5sum not found, creating new."
240 make_md5sum
> $PKGMK_MD5SUM
243 if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
244 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
245 rm -rf $PKGMK_WORK_DIR
257 if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
258 FILTER
="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
263 find .
-type f
-printf "%P\n" | $FILTER | while read FILE
; do
264 case $
(file -b "$FILE") in
265 *ELF
*executable
*not\ stripped
)
266 strip
--strip-all "$FILE"
268 *ELF
*shared\ object
*not\ stripped
)
269 strip
--strip-unneeded "$FILE"
271 current\
ar\ archive
)
272 strip
--strip-debug "$FILE"
277 compress_manpages
() {
278 local FILE DIR TARGET
282 find .
-type f
-path "*/man/man*/*" | while read FILE
; do
283 if [ "$FILE" = "${FILE%%.gz}" ]; then
288 find .
-type l
-path "*/man/man*/*" | while read FILE
; do
289 TARGET
=`readlink -n "$FILE"`
290 TARGET
="${TARGET##*/}"
291 TARGET
="${TARGET%%.gz}.gz"
293 FILE
="${FILE%%.gz}.gz"
294 DIR
=`dirname "$FILE"`
296 if [ -e "$DIR/$TARGET" ]; then
297 ln -sf "$TARGET" "$FILE"
303 local FILE
="$PKGMK_WORK_DIR/.tmp"
307 if [ -f $TARGET ]; then
308 make_footprint
> $FILE.footprint
309 if [ -f $PKGMK_FOOTPRINT ]; then
310 sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
311 diff -w -t -U 0 $FILE.footprint.orig
$FILE.footprint
| \
315 sed 's/^+/NEW /g' | \
316 sed 's/^-/MISSING /g' > $FILE.footprint.
diff
317 if [ -s $FILE.footprint.
diff ]; then
318 error
"Footprint mismatch found:"
319 cat $FILE.footprint.
diff >&2
320 BUILD_SUCCESSFUL
="no"
323 warning
"Footprint not found, creating new."
324 mv $FILE.footprint
$PKGMK_FOOTPRINT
327 error
"Package '$TARGET' was not found."
328 BUILD_SUCCESSFUL
="no"
333 export PKG
="$PKGMK_WORK_DIR/pkg"
334 export SRC
="$PKGMK_WORK_DIR/src"
341 if [ "$PKGMK_IGNORE_MD5SUM" = "no" ]; then
347 rm -rf $PKGMK_WORK_DIR
352 local BUILD_SUCCESSFUL
="no"
356 if [ "$UID" != "0" ]; then
357 warning
"Packages should be built as root."
360 info
"Building '$TARGET'."
368 if [ "$PKGMK_NO_STRIP" = "no" ]; then
379 BUILD_SUCCESSFUL
="yes"
381 if [ "$PKGMK_IGNORE_FOOTPRINT" = "yes" ]; then
382 warning
"Footprint ignored."
389 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
393 if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
394 info
"Building '$TARGET' succeeded."
396 if [ -f $TARGET ]; then
397 touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev
/null
399 error
"Building '$TARGET' failed."
407 info
"Installing '$TARGET'."
409 if [ "$PKGMK_INSTALL" = "install" ]; then
410 COMMAND
="pkgadd $TARGET"
412 COMMAND
="pkgadd -u $TARGET"
420 info
"Installing '$TARGET' succeeded."
422 error
"Installing '$TARGET' failed."
430 ARGS
=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
432 for FILE
in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
433 DIR
="`dirname $FILE`/"
435 info
"Entering directory '$DIR'."
436 (cd $DIR && $PKGMK_COMMAND $ARGS)
437 info
"Leaving directory '$DIR'."
443 local FILE LOCAL_FILENAME
445 if [ -f $TARGET ]; then
446 info
"Removing $TARGET"
450 for FILE
in ${source[@]}; do
451 LOCAL_FILENAME
=`get_filename $FILE`
452 if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
453 info
"Removing $LOCAL_FILENAME"
454 rm -f $LOCAL_FILENAME
460 if [ ! -f $TARGET ]; then
461 error
"Unable to update footprint. File '$TARGET' not found."
465 make_footprint
> $PKGMK_FOOTPRINT
468 info
"Footprint updated."
475 if [ -f $TARGET ]; then
477 for FILE
in $PKGMK_PKGFILE ${source[@]}; do
478 FILE
=`get_filename $FILE`
479 if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
493 if [ "$PKGMK_KEEP_WORK" = "no" ]; then
494 rm -rf $PKGMK_WORK_DIR
501 echo "usage: `basename $PKGMK_COMMAND` [options]"
503 echo " -i, --install build and install package"
504 echo " -u, --upgrade build and install package (as upgrade)"
505 echo " -r, --recursive search for and build packages recursively"
506 echo " -d, --download download missing source file(s)"
507 echo " -do, --download-only do not build, only download missing source file(s)"
508 echo " -eo, --extract-only do not build, only extract source file(s)"
509 echo " -utd, --up-to-date do not build, only check if package is up to date"
510 echo " -uf, --update-footprint update footprint using result from last build"
511 echo " -if, --ignore-footprint build package without checking footprint"
512 echo " -um, --update-md5sum update md5sum"
513 echo " -im, --ignore-md5sum build package without checking md5sum"
514 echo " -cm, --check-md5sum do not build, only check md5sum"
515 echo " -ns, --no-strip do not strip executable binaries or libraries"
516 echo " -f, --force build package even if it appears to be up to date"
517 echo " -c, --clean remove package and downloaded files"
518 echo " -kw, --keep-work keep temporary working directory"
519 echo " -cf, --config-file <file> use alternative configuration file"
520 echo " -v, --version print version and exit "
521 echo " -h, --help print help and exit"
528 PKGMK_INSTALL
="install" ;;
530 PKGMK_INSTALL
="upgrade" ;;
532 PKGMK_RECURSIVE
="yes" ;;
534 PKGMK_DOWNLOAD
="yes" ;;
537 PKGMK_DOWNLOAD_ONLY
="yes" ;;
539 PKGMK_EXTRACT_ONLY
="yes" ;;
541 PKGMK_UP_TO_DATE
="yes" ;;
542 -uf|--update-footprint)
543 PKGMK_UPDATE_FOOTPRINT
="yes" ;;
544 -if|--ignore-footprint)
545 PKGMK_IGNORE_FOOTPRINT
="yes" ;;
547 PKGMK_UPDATE_MD5SUM
="yes" ;;
549 PKGMK_IGNORE_MD5SUM
="yes" ;;
551 PKGMK_CHECK_MD5SUM
="yes" ;;
553 PKGMK_NO_STRIP
="yes" ;;
559 PKGMK_KEEP_WORK
="yes" ;;
562 echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
568 echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
574 echo "`basename $PKGMK_COMMAND`: invalid option $1"
586 if [ "$PKGMK_RECURSIVE" = "yes" ]; then
591 for FILE
in $PKGMK_PKGFILE $PKGMK_CONFFILE; do
592 if [ ! -f $FILE ]; then
593 error
"File '$FILE' not found."
599 check_directory
"$PKGMK_SOURCE_DIR"
600 check_directory
"$PKGMK_PACKAGE_DIR"
601 check_directory
"`dirname $PKGMK_WORK_DIR`"
605 TARGET
="$PKGMK_PACKAGE_DIR/$name#$version-$release.pkg.tar.gz"
607 if [ "$PKGMK_CLEAN" = "yes" ]; then
612 if [ "$PKGMK_UPDATE_FOOTPRINT" = "yes" ]; then
617 if [ "$PKGMK_UPDATE_MD5SUM" = "yes" ]; then
619 make_md5sum
> $PKGMK_MD5SUM
620 info
"Md5sum updated."
624 if [ "$PKGMK_DOWNLOAD_ONLY" = "yes" ]; then
629 if [ "$PKGMK_EXTRACT_ONLY" = "yes" ]; then
632 info
"Extracting sources of package '$name-$version'."
637 if [ "$PKGMK_UP_TO_DATE" = "yes" ]; then
638 if [ "`build_needed`" = "yes" ]; then
639 info
"Package '$TARGET' is not up to date."
641 info
"Package '$TARGET' is up to date."
646 if [ "`build_needed`" = "no" ] && [ "$PKGMK_FORCE" = "no" ] && [ "$PKGMK_CHECK_MD5SUM" = "no" ]; then
647 info
"Package '$TARGET' is up to date."
653 if [ "$PKGMK_INSTALL" != "no" ]; then
660 trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
664 readonly PKGMK_VERSION
="#VERSION#"
665 readonly PKGMK_COMMAND
="$0"
666 readonly PKGMK_ROOT
="$PWD"
668 PKGMK_CONFFILE
="/etc/pkgmk.conf"
669 PKGMK_PKGFILE
="Pkgfile"
670 PKGMK_FOOTPRINT
=".footprint"
671 PKGMK_MD5SUM
=".md5sum"
672 PKGMK_NOSTRIP
=".nostrip"
674 PKGMK_SOURCE_MIRRORS
=()
675 PKGMK_SOURCE_DIR
="$PWD"
676 PKGMK_PACKAGE_DIR
="$PWD"
677 PKGMK_WORK_DIR
="$PWD/work"
682 PKGMK_DOWNLOAD_ONLY
="no"
683 PKGMK_EXTRACT_ONLY
="no"
684 PKGMK_UP_TO_DATE
="no"
685 PKGMK_UPDATE_FOOTPRINT
="no"
686 PKGMK_IGNORE_FOOTPRINT
="no"
689 PKGMK_UPDATE_MD5SUM
="no"
690 PKGMK_IGNORE_MD5SUM
="no"
691 PKGMK_CHECK_MD5SUM
="no"