3 # pkgfs - A simple, minimal, fast and uncomplete build package system.
6 # Copyright (c) 2008 Juan Romero Pardines.
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
18 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 # - Implement a routine that checks if installed version is sufficient
32 # to satisfy the required dependency... right now it's very prone
34 # - Multiple distfiles in a package.
35 # - Multiple URLs to download source distribution files.
37 # Default path to configuration file, can be overriden
38 # via the environment or command line.
40 : ${PKGFS_CONFIG_FILE:=/usr/local/etc/pkgfs.conf}
42 : ${progname:=$(basename $0)}
43 : ${topdir:=$(/bin/pwd -P 2>/dev/null)}
44 : ${fetch_cmd:=/usr/bin/ftp -a}
45 : ${cksum_cmd:=/usr/bin/cksum -a rmd160}
46 : ${awk_cmd:=/usr/bin/awk}
47 : ${mkdir_cmd:=/bin/mkdir -p}
48 : ${tar_cmd:=/usr/bin/tar}
52 : ${sed_cmd=/usr/bin/sed}
53 : ${grep_cmd=/usr/bin/grep}
54 : ${gunzip_cmd:=/usr/bin/gunzip}
55 : ${bunzip2_cmd:=/usr/bin/bunzip2}
56 : ${patch_cmd:=/usr/bin/patch}
57 : ${find_cmd:=/usr/bin/find}
58 : ${file_cmd:=/usr/bin/file}
60 : ${chmod_cmd:=/bin/chmod}
61 : ${db_cmd:=/usr/bin/db -q}
62 : ${chmod_cmd:=/bin/chmod}
63 : ${touch_cmd:=/usr/bin/touch}
66 : ${xstow_ignore_files:=perllocal.pod} # XXX For now ignore them.
71 : ${PKGFS_TEMPLATESDIR:=$PKGFS_DISTRIBUTIONDIR/templates}
72 : ${PKGFS_DEPSDIR:=$PKGFS_DISTRIBUTIONDIR/dependencies}
73 : ${PKGFS_BUILD_DEPS_DB:=$PKGFS_DEPSDIR/build-depends.db}
74 : ${PKGFS_TMPLHELPDIR:=$PKGFS_DISTRIBUTIONDIR/helper-templates}
75 : ${PKGFS_REGPKG_DB:=$PKGFS_DESTDIR/.pkgfs-registered-pkgs.db}
77 local DDIRS
="PKGFS_DEPSDIR PKGFS_TEMPLATESDIR PKGFS_TMPLHELPDIR"
80 if [ ! -d "$val" ]; then
81 echo "**** ERROR: cannot find $i, aborting ***"
90 $progname: [-C] [-c <config_file>] <target> [package_name]
93 build Builds a package, only build phase is done.
94 configure Configure a package, only configure phase is done.
95 extract Extract distribution file(s) into build directory.
96 fetch Download distribution file(s).
97 info Show information about <package_name>.
98 install build + configure + install into destdir + stow.
99 list Lists all currently ``stowned´´ packages.
100 remove Remove package completely (unstow + remove data)
101 stow Create links in master directory.
102 unstow Remove links in master directory.
105 -C Do not remove build directory after successful installation.
106 -c Path to global configuration file:
107 if not specified /usr/local/etc/pkgfs.conf is used.
123 orig
="$topdir/${orig%/}"
139 # This function merges two GNU info dirs into one and puts the result
140 # into PKGFS_MASTERDIR/share/info/dir.
145 local merge_info_cmd
="$PKGFS_MASTERDIR/bin/merge-info"
147 [ -z "$pkgname" -o ! -r "$PKGFS_MASTERDIR/share/info/dir" \
148 -o ! -r "$PKGFS_DESTDIR/$pkgname/share/info/dir" ] && return 1
150 $merge_info_cmd -d $PKGFS_MASTERDIR/share
/info
/dir \
151 $PKGFS_DESTDIR/$pkgname/share
/info
/dir
-o \
152 $PKGFS_MASTERDIR/share
/info
/dir.new
153 if [ $?
-ne 0 ]; then
154 echo -n "*** WARNING: there was an error merging info dir from"
155 echo " $pkgname, aborting ***"
159 $mv_cmd -f $PKGFS_MASTERDIR/share
/info
/dir.new \
160 $PKGFS_MASTERDIR/share
/info
/dir
164 # Shows info about a template.
168 echo "pkgname: $pkgname"
169 echo "version: $version"
170 for i
in "${distfiles}"; do
171 [ -n "$i" ] && echo "distfile: $i"
174 echo "maintainer: $maintainer"
175 [ -n $checksum ] && echo "checksum: $checksum"
176 echo "build_style: $build_style"
177 echo "short_desc: $short_desc"
180 check_build_depends_pkg
$pkgname-$version
181 if [ $?
-eq 0 ]; then
182 local list
="$($db_cmd -V btree $PKGFS_BUILD_DEPS_DB $pkgname)"
183 echo "This package requires the following dependencies to be built:"
191 # Checks that all required variables specified in the configuration
192 # file are properly working.
198 if [ -z "$config_file_specified" ]; then
199 config_file_paths
="$PKGFS_CONFIG_FILE ./pkgfs.conf"
200 for f
in $config_file_paths; do
201 [ -f $f ] && PKGFS_CONFIG_FILE
=$f && \
204 if [ -z "$cffound" ]; then
205 echo -n "*** ERROR: config file not specified "
206 echo "and not in default location or current dir ***"
211 run_file
${PKGFS_CONFIG_FILE}
212 PKGFS_CONFIG_FILE
=$path_fixed
214 if [ ! -f "$PKGFS_CONFIG_FILE" ]; then
215 echo -n "*** ERROR: cannot find configuration file: "
216 echo "'$PKGFS_CONFIG_FILE' ***"
220 local PKGFS_VARS
="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
221 PKGFS_SRCDISTDIR PKGFS_SYSCONFDIR"
223 for f
in ${PKGFS_VARS}; do
225 if [ -z "$val" ]; then
226 echo -n "**** ERROR: '$f' not set in configuration "
227 echo "file, aborting ***"
231 if [ ! -d "$val" ]; then
233 if [ "$?" -ne 0 ]; then
234 echo -n "*** ERROR: couldn't create '$f'"
235 echo "directory, aborting ***"
243 # Resets all vars used by a template.
247 local TMPL_VARS
="pkgname extract_sufx distfiles url configure_args \
248 make_build_args make_install_args build_style \
249 short_desc maintainer long_desc checksum wrksrc \
250 patch_files configure_env make_cmd pkgconfig_override \
251 configure_env make_env run_stuff_before run_stuff_after \
252 run_stuff_before_configure_file run_stuff_before_build_file \
253 run_stuff_before_install_file run_stuff_after_install \
254 run_stuff_after_install_file make_build_target \
255 run_stuff_before_configure_cmd run_stuff_before_build_cmd \
256 run_stuff_before_install_cmd run_stuff_after_install_cmd \
257 make_install_target postinstall_helpers version \
259 PKGFS_EXTRACT_DONE PKGFS_CONFIGURE_DONE \
260 PKGFS_BUILD_DONE PKGFS_INSTALL_DONE"
262 for i
in ${TMPL_VARS}; do
270 # Reads a template file and setups required variables for operations.
276 if [ -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
277 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
280 echo "*** ERROR: cannot find \`$pkg´ template file ***"
286 # Checks some vars used in templates and sets some of them required.
293 # There's nothing of interest if we are a meta template.
295 [ "$build_style" = "meta-template" ] && return 0
297 REQ_VARS
="pkgname version extract_sufx url build_style"
299 # Check if required vars weren't set.
300 for i
in ${REQ_VARS}; do
302 if [ -z "$val" -o -z "$i" ]; then
303 echo -n "*** ERROR: $i not set (incomplete template"
304 echo " build file), aborting ***"
309 if [ -z "$distfiles" ]; then
310 dfile
="$pkgname-$version$extract_sufx"
311 elif [ -n "${distfiles}" ]; then
312 dfile
="$distfiles$extract_sufx"
314 echo "*** ERROR unsupported fetch state ***"
318 dfile
="$PKGFS_SRCDISTDIR/$dfile"
320 case "$extract_sufx" in
321 .
tar.bz2|.
tar.gz|.tgz|.tbz
)
322 extract_cmd
="$tar_cmd xfz $dfile -C $PKGFS_BUILDDIR"
325 extract_cmd
="$tar_cmd xf $dfile -C $PKGFS_BUILDDIR"
328 if [ -f "$PKGFS_TMPLHELPDIR/unzip-extraction.sh" ]; then
329 .
$PKGFS_TMPLHELPDIR/unzip-extraction.sh
332 # $extract_cmd set by the helper
335 echo -n "*** ERROR: unknown 'extract_sufx' argument in build "
341 unset PKGFS_EXTRACT_DONE PKGFS_APPLYPATCHES_DONE
342 unset PKGFS_CONFIGURE_DONE PKGFS_BUILD_DONE PKGFS_INSTALL_DONE
344 if [ -n "$wrksrc" ]; then
345 wrksrc
=$PKGFS_BUILDDIR/$wrksrc
346 elif [ -z "$wrksrc" -a -z "$distfiles" ]; then
347 wrksrc
=$PKGFS_BUILDDIR/$pkgname-$version
348 elif [ -z "$wrksrc" -a -n "$distfiles" ]; then
349 wrksrc
=$PKGFS_BUILDDIR/$distfiles
351 echo "*** ERROR: can't guess what's the correct \$wrksrc! ***"
355 PKGFS_EXTRACT_DONE
="$wrksrc/.pkgfs_extract_done"
356 PKGFS_APPLYPATCHES_DONE
="$wrksrc/.pkgfs_applypatches_done"
357 PKGFS_CONFIGURE_DONE
="$wrksrc/.pkgfs_configure_done"
358 PKGFS_BUILD_DONE
="$wrksrc/.pkgfs_build_done"
359 PKGFS_INSTALL_DONE
="$wrksrc/.pkgfs_install_done"
361 export PATH
="/bin:/sbin:/usr/bin:/usr/sbin:$PKGFS_MASTERDIR/bin:$PKGFS_MASTERDIR/sbin"
365 # Extracts contents of distfiles specified in a template into
366 # the build directory.
373 # If we are being called via the target, just extract and return.
375 [ -n "$pkg" -a -z "$pkgname" ] && return 1
378 # There's nothing of interest if we are a meta template.
380 [ "$build_style" = "meta-template" ] && return 0
382 echo "==> Extracting \`$pkgname-$version' into $PKGFS_BUILDDIR."
385 if [ "$?" -ne 0 ]; then
386 echo -n "*** ERROR: there was an error extracting the "
387 echo "distfile(s), aborting *** "
392 $touch_cmd -f $PKGFS_EXTRACT_DONE
396 # Verifies that a checksum of a distfile is correct.
403 [ -z "$file" ] && return 1
405 if [ -z "${distfiles}" ]; then
406 dfile
="$pkgname-$version$extract_sufx"
407 elif [ -n "${distfiles}" ]; then
408 dfile
="$distfiles$extract_sufx"
410 dfile
="$file$extract_sufx"
413 if [ -z "$checksum" ]; then
414 echo "*** ERROR: checksum unset in template file for \`$pkgname' ***"
419 dfile
="$PKGFS_SRCDISTDIR/$dfile"
420 filesum
="$($cksum_cmd $dfile | $awk_cmd '{print $4}')"
421 if [ "$origsum" != "$filesum" ]; then
422 echo "*** WARNING: RMD160 checksum doesn't match for \`$dfile' ***"
426 echo "=> checksum (RMD160) OK for \`$pkgname-$version'."
430 # Downloads the distfiles for a template from $url.
440 # If we are being called by the target, just fetch distfiles
443 [ -n $pkg ] && only_fetch
=yes
444 [ -z $pkgname ] && exit 1
447 # There's nothing of interest if we are a meta template.
449 [ "$build_style" = "meta-template" ] && return 0
451 if [ -z "$distfiles" ]; then
452 file="$pkgname-$version"
458 file2
="$f$extract_sufx"
459 if [ -f "$PKGFS_SRCDISTDIR/$file2" ]; then
460 check_rmd160_cksum
$f
461 [ $?
-eq 0 ] && continue
464 echo "==> Fetching distfile: \`$file2'."
466 cd $PKGFS_SRCDISTDIR && $fetch_cmd $url/$file2
467 if [ $?
-ne 0 ]; then
468 if [ ! -f $PKGFS_SRCDISTDIR/$file2 ]; then
469 echo -n "*** ERROR: couldn't fetch '$file2', "
472 echo -n "*** ERROR: there was an error "
473 echo "fetching '$file2', aborting ***"
477 check_rmd160_cksum
$f
484 local lt_file
="$wrksrc/libtool"
487 # If package has a libtool file replace it with ours, so that
488 # we use the master directory while relinking, all will be fine
489 # once the package is stowned.
491 if [ -f "$lt_file" -a -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
492 $rm_cmd -f $wrksrc/libtool
493 $rm_cmd -f $wrksrc/ltmain.sh
494 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
495 $ln_cmd -s $PKGFS_MASTERDIR/share
/libtool
/config
/ltmain.sh \
497 elif [ -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
498 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
504 LDFLAGS
="-L$PKGFS_MASTERDIR/lib -Wl,-R$PKGFS_MASTERDIR/lib $LDFLAGS"
505 LDFLAGS
="-L$PKGFS_DESTDIR/$pkgname-$version/lib $LDFLAGS"
506 CFLAGS
="$CFLAGS $PKGFS_CFLAGS"
507 CXXFLAGS
="$CXXFLAGS $PKGFS_CXXFLAGS"
508 CPPFLAGS
="-I$PKGFS_MASTERDIR/include $CPPFLAGS"
509 PKG_CONFIG
="$PKGFS_MASTERDIR/bin/pkg-config"
511 export LDFLAGS
="$LDFLAGS" CFLAGS
="$CFLAGS" CXXFLAGS
="$CXXFLAGS"
512 export CPPFLAGS
="$CPPFLAGS" PKG_CONFIG
="$PKG_CONFIG"
517 unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS PKG_CONFIG
521 # Applies to the build directory the patches specified by a template.
528 # If package needs some patches applied before building,
531 if [ -n "$patch_files" ]; then
532 for i
in ${patch_files}; do
533 patch="$PKGFS_TEMPLATESDIR/$i"
534 if [ ! -f "$patch" ]; then
535 echo "*** WARNING: unexistent patch '$i' ***"
539 $cp_cmd -f $patch $wrksrc
541 # Try to guess if its a compressed patch.
542 if $
(echo $patch|
$grep_cmd -q .gz
); then
543 $gunzip_cmd $wrksrc/$i
545 elif $
(echo $patch|
$grep_cmd -q .bz2
); then
546 $bunzip2_cmd $wrksrc/$i
548 elif $
(echo $patch|
$grep_cmd -q .
diff); then
551 echo "*** WARNING: unknown patch type '$i' ***"
555 cd $wrksrc && $patch_cmd < $patch 2>/dev
/null
556 if [ "$?" -eq 0 ]; then
557 echo "=> Patch applied: \`$i'."
559 echo -n "*** ERROR: couldn't apply patch '$i'"
560 echo ", aborting ***"
566 $touch_cmd -f $PKGFS_APPLYPATCHES_DONE
570 # Runs the "configure" phase for a pkg. This setups the Makefiles or any
571 # other stuff required to be able to build binaries or such.
573 configure_src_phase
()
577 [ -z $pkg ] && [ -z $pkgname ] && return 1
580 # There's nothing we can do if we are a meta template.
582 [ "$build_style" = "meta-template" ] && return 0
584 if [ ! -d $wrksrc ]; then
585 echo "*** ERROR: unexistent build directory \`$wrksrc' ***"
589 echo "=> Running \`\`configure´´ phase for \`$pkgname-$version'."
591 # Apply patches if requested by template file
592 [ ! -f $PKGFS_APPLYPATCHES_DONE ] && apply_tmpl_patches
594 # Run stuff before configure.
595 for i
in "$run_stuff_before"; do
596 if [ "$i" = "configure" ]; then
597 [ -f $run_stuff_before_configure_file ] && \
598 .
$run_stuff_before_configure_file
599 [ -n "$run_stuff_before_configure_cmd" ] && \
600 ${run_stuff_before_configure_cmd}
604 # Export configure_env vars.
605 for f
in ${configure_env}; do
612 # Packages using GNU autoconf
614 if [ "$build_style" = "gnu_configure" ]; then
617 # Pass consistent arguments to not have unexpected
621 --prefix="$PKGFS_MASTERDIR" \
622 --mandir="$PKGFS_DESTDIR/$pkgname-$version/man" \
623 --infodir="$PKGFS_DESTDIR/$pkgname-$version/share/info" \
624 --sysconfdir="$PKGFS_SYSCONFDIR" \
628 # Packages using propietary configure scripts.
630 elif [ "$build_style" = "configure" ]; then
632 if [ -n "$configure_script" ]; then
633 .
/$configure_script ${configure_args}
635 .
/configure
${configure_args}
638 # Packages that are perl modules and use Makefile.PL files.
639 # They are all handled by the helper perl-module.sh.
641 elif [ "$build_style" = "perl_module" ]; then
642 .
$PKGFS_TMPLHELPDIR/perl-module.sh
643 perl_module_build
$pkgname
646 # Packages with BSD or GNU Makefiles are easy, just skip
647 # the configure stage and proceed.
649 elif [ "$build_style" = "bsd_makefile" -o \
650 "$build_style" = "gnu_makefile" ]; then
654 # Unknown build_style type won't work :-)
657 echo "*** ERROR unknown build_style \`$build_style' ***"
661 if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
662 echo "*** ERROR building (configure state) \`$pkg' ***"
666 # unset configure_env vars.
667 for f
in ${configure_env}; do
671 $touch_cmd -f $PKGFS_CONFIGURE_DONE
675 # Runs the "build" phase for a pkg. This builds the binaries and other
681 local pkg
="$pkgname-$version"
683 [ -z $pkgparam ] && [ -z $pkgname -o -z $version ] && return 1
686 # There's nothing of interest if we are a meta template.
688 [ "$build_style" = "meta-template" ] && return 0
690 if [ ! -d $wrksrc ]; then
691 echo "*** ERROR: unexistent build directory \`$wrksrc' ***"
697 echo "=> Running \`\`build´´ phase for \`$pkg'."
700 # Assume BSD make if make_cmd not set in template.
702 if [ -z "$make_cmd" ]; then
703 make_cmd
="/usr/bin/make"
706 # Fixup libtool script if necessary
710 # Run template stuff before building.
712 for i
in ${run_stuff_before}; do
713 if [ "$i" = "build" ]; then
714 [ -f $run_stuff_before_build_file ] && \
715 .
$run_stuff_before_build_file
716 [ -n "$run_stuff_before_build_cmd" ] && \
717 ${run_stuff_before_build_cmd}
721 [ -z "$make_build_target" ] && make_build_target
=
722 [ -n "$PKGFS_MAKEJOBS" ] && PKGFS_MAKEJOBS
="-j$PKGFS_MAKEJOBS"
724 # Export make_env vars.
725 for f
in ${make_env}; do
730 # Build package via make.
732 ${make_cmd} ${PKGFS_MAKEJOBS} ${make_build_args} ${make_build_target}
733 if [ "$?" -ne 0 ]; then
734 echo "*** ERROR building (make stage) \`$pkg' ***"
739 # Run template stuff before installing.
741 for i
in ${run_stuff_before}; do
742 if [ "$i" = "install" ]; then
743 [ -f $run_stuff_before_install_file ] && \
744 .
$run_stuff_before_install_file
745 [ -n "$run_stuff_before_install_cmd" ] && \
746 ${run_stuff_before_install_cmd}
750 $touch_cmd -f $PKGFS_BUILD_DONE
754 # Runs the "install" phase for a pkg. This consists in installing package
755 # into the destination directory.
761 [ -z $pkg ] && [ -z $pkgname ] && return 1
763 [ -z "$make_install_target" ] && make_install_target
=install
766 # There's nothing we can do if we are a meta template.
768 [ "$build_style" = "meta-template" ] && return 0
770 if [ ! -d $wrksrc ]; then
771 echo "*** ERROR: unexistent build directory \`$wrksrc' ***"
775 echo "=> Running \`\`install´´ phase for: \`$pkgname-$version´."
778 # Install package via make.
780 ${make_cmd} ${make_install_args} ${make_install_target} \
781 prefix
="$PKGFS_DESTDIR/$pkgname-$version"
782 if [ "$?" -ne 0 ]; then
783 echo "*** ERROR instaling \`$pkgname-$version' ***"
787 # Unset make_env vars.
788 for f
in ${make_env}; do
793 # Run template stuff after installing.
795 for i
in ${run_stuff_after}; do
796 if [ "$i" = "install" ]; then
797 [ -f $run_stuff_after_install_file ] && \
798 .
$run_stuff_after_install_file
799 [ -n "$run_stuff_after_install_cmd" ] && \
800 ${run_stuff_after_install_cmd}
805 # Transform pkg-config files if requested by template.
807 for i
in ${pkgconfig_override}; do
808 local tmpf
="$PKGFS_DESTDIR/$pkgname-$version/lib/pkgconfig/$i"
810 [ -f $PKGFS_TMPLHELPDIR/pkg-config-transform.sh
] && \
811 .
$PKGFS_TMPLHELPDIR/pkg-config-transform.sh
&& \
812 pkgconfig_transform_file
$tmpf
818 echo "==> Installed \`$pkgname-$version' into $PKGFS_DESTDIR."
820 $touch_cmd -f $PKGFS_INSTALL_DONE
823 # Remove $wrksrc if -C not specified.
825 if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
828 echo "=> Removed \`$pkgname-$version' build directory."
835 # Registers or unregisters a package from the db file.
837 register_pkg_handler
()
843 [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1
845 if [ "$action" = "register" ]; then
846 $db_cmd -w btree
$PKGFS_REGPKG_DB $pkg $version 2>&1 >/dev
/null
847 if [ "$?" -ne 0 ]; then
848 echo -n "*** ERROR: couldn't register \`$pkg'"
849 echo " in db file ***"
852 elif [ "$action" = "unregister" ]; then
853 $db_cmd -d btree
$PKGFS_REGPKG_DB $pkg 2>&1 >/dev
/null
854 if [ "$?" -ne 0 ]; then
855 echo -n "*** ERROR: \`$pkg' not registered "
856 echo "in db file? ***"
865 # Recursive function that founds dependencies in all required
868 add_dependency_tolist
()
872 [ -z "$curpkg" ] && return 1
873 [ -n "$prev_pkg" ] && curpkg
=$prev_pkg
875 for i
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do
877 # Check if dep already installed.
879 if [ -r "$PKGFS_REGPKG_DB" ]; then
880 check_installed_pkg
$i ${i##[aA-zZ]*-}
882 # If dep is already installed, put it on the
883 # installed deps list and continue.
885 if [ $?
-eq 0 ]; then
886 installed_deps_list
="$i $installed_deps_list"
890 deps_list
="$i $deps_list"
891 [ -n "$prev_pkg" ] && unset prev_pkg
893 # Check if dependency needs more deps.
895 check_build_depends_pkg
${i%-[0-9]*.*}
896 if [ $?
-eq 0 ]; then
897 add_dependency_tolist
$i
905 # Removes duplicate deps in the installed or not installed list.
907 find_dupdeps_inlist
()
913 [ -z "$action" ] && return 1
917 list
=$installed_deps_list
928 if [ -z "$tmp_list" ]; then
931 for i
in $tmp_list; do
932 [ "$f" = "$i" ] && dup
=yes
935 [ -z "$dup" ] && tmp_list
="$tmp_list $f"
942 installed_deps_list
="$tmp_list"
945 deps_list
="$tmp_list"
954 # Installs all dependencies required by a package.
956 install_dependencies_pkg
()
962 [ -z "$pkg" ] && return 1
966 add_dependency_tolist
$pkg
967 find_dupdeps_inlist installed
968 find_dupdeps_inlist notinstalled
970 [ -z "$deps_list" -a -z "$installed_deps_list" ] && return 0
972 echo "==> Required dependencies for $(basename $pkg):"
973 for i
in ${installed_deps_list}; do
974 fpkg
="$($db_cmd -O '-' btree $PKGFS_REGPKG_DB ${i%-[0-9]*.*})"
975 echo " $i: found $fpkg."
978 for i
in ${deps_list}; do
979 echo " $i: not installed."
982 for i
in ${deps_list}; do
984 check_installed_pkg
$i ${i##[aA-zZ]*-}
985 [ $?
-eq 0 ] && continue
986 # continue installing deps
987 echo "==> Installing \`$pkg´ dependency: \`$i´."
988 install_pkg
${i%-[0-9]*.*}
991 unset installed_deps_list
995 install_builddeps_required_pkg
()
999 [ -z "$pkg" ] && return 1
1001 for dep
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*}); do
1002 check_installed_pkg
$dep ${dep##[aA-zZ]*-}
1003 if [ $?
-ne 0 ]; then
1004 echo "==> Installing \`$pkg´ dependency: $dep."
1005 install_pkg
${dep%-[0-9]*.*}
1011 # Checks the registered pkgs db file and returns 0 if a pkg that satisfies
1012 # the minimal required version is there, or 1 otherwise.
1014 check_installed_pkg
()
1020 [ -z "$pkg" -o -z "$reqver" -o ! -r $PKGFS_REGPKG_DB ] && return 1
1022 run_file
$PKGFS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
1024 reqver
="$(echo $reqver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1026 $db_cmd -K btree
$PKGFS_REGPKG_DB $pkgname 2>&1 >/dev
/null
1027 if [ $?
-eq 0 ]; then
1029 # Package is installed, let's check the version.
1031 iver
="$($db_cmd -V btree $PKGFS_REGPKG_DB $pkgname)"
1032 if [ -n "$iver" ]; then
1034 # As shell only supports decimal arith expressions,
1035 # we simply remove anything except the numbers.
1036 # It's not optimal and may fail, but it is enough
1039 iver
="$(echo $iver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1040 if [ "$iver" -eq "$reqver" \
1041 -o "$iver" -gt "$reqver" ]; then
1051 # Checks the build depends db file and returns 0 if pkg has dependencies,
1052 # otherwise returns 1.
1054 check_build_depends_pkg
()
1058 [ -z $pkg -o ! -r $PKGFS_BUILD_DEPS_DB ] && return 1
1060 $db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev
/null
1065 # Installs a pkg by reading its build template file.
1072 local cur_tmpl
="$PKGFS_TEMPLATESDIR/$curpkgn.tmpl"
1073 if [ -z $cur_tmpl -o ! -f $cur_tmpl ]; then
1074 echo "*** ERROR: cannot find \`$cur_tmpl´ template file ***"
1080 pkg
="$curpkgn-$version"
1083 # If we are the originator package save the path this template in
1084 # other var for future use.
1086 [ -z "$origin_tmpl" ] && origin_tmpl
=$pkgname
1089 # Install xstow if it's not there.
1094 # We are going to install a new package.
1099 # Install dependencies required by this package.
1101 if [ -z "$doing_deps" ]; then
1102 install_dependencies_pkg
$pkg
1104 # At this point all required deps are installed, and
1105 # only remaining is the origin template; install it.
1113 # Fetch, extract, build and install into the destination directory.
1117 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1121 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1125 if [ ! -f "$PKGFS_BUILD_DONE" ]; then
1132 # Just announce that meta-template is installed and exit.
1134 if [ "$build_style" = "meta-template" ]; then
1135 register_pkg_handler register
$pkgname $version
1136 echo "==> Installed meta-template \`$pkg'."
1144 # Installs and stows the "xstow" package.
1148 [ -x "$PKGFS_XSTOW_CMD" ] && return 0
1150 echo "=> xstow application not found, will install it now."
1156 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1160 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1164 if [ ! -f "$PKGFS_BUILD_DONE" ]; then
1170 PKGFS_XSTOW_CMD
="$PKGFS_DESTDIR/$pkgname-$version/bin/xstow"
1171 stow_pkg
$pkgname-$version
1174 # Continue with package that called us.
1176 run_file
$PKGFS_TEMPLATESDIR/$origin_tmpl.tmpl
1180 # Lists all currently installed packages.
1184 if [ ! -r "$PKGFS_REGPKG_DB" ]; then
1185 echo "=> No packages registered or missing register db file."
1189 for i
in $
($db_cmd -K btree
$PKGFS_REGPKG_DB); do
1190 # Run file to get short_desc and print something useful
1191 run_file
$PKGFS_TEMPLATESDIR/$i.tmpl
1192 echo "$i-$version $short_desc"
1198 # Removes a currently installed package (unstow + removed from destdir).
1204 if [ -z "$pkg" ]; then
1205 echo "*** ERROR: unexistent package, aborting ***"
1209 if [ ! -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
1210 echo "*** ERROR: cannot find template file ***"
1214 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1217 # If it's a meta-template, just unregister it from the db.
1219 if [ "$build_style" = "meta-template" ]; then
1220 register_pkg_handler unregister
$pkgname $version
1222 echo "=> Removed meta-template \`$pkg'."
1226 if [ ! -d "$PKGFS_DESTDIR/$pkg-$version" ]; then
1227 echo "*** ERROR: cannot find package on $PKGFS_DESTDIR ***"
1232 $rm_cmd -rf $PKGFS_DESTDIR/$pkg-$version
1237 # Stows a currently installed package, i.e creates the links
1238 # on the master directory.
1243 local infodir_pkg
="share/info/dir"
1244 local infodir_master
="$PKGFS_MASTERDIR/share/info/dir"
1245 local real_xstowargs
="$xstow_args"
1246 local real_xstow_ignore
="$xstow_ignore_files"
1248 [ -z "$pkg" ] && return 2
1250 if [ -n "$stow_flag" ]; then
1251 pkg
=$PKGFS_TEMPLATESDIR/$pkg.tmpl
1253 pkg
=$pkgname-$version
1255 # You cannot stow a meta-template.
1257 [ "$build_style" = "meta-template" ] && return 0
1260 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" ]; then
1261 merge_infodir_tmpl
$pkg
1264 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" \
1265 -a -r "$infodir_master" ]; then
1266 xstow_args
="$xstow_args -i-file-in-dir $infodir_pkg"
1269 if [ -n "$ignore_files" ]; then
1270 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
1273 $PKGFS_XSTOW_CMD -ignore "${xstow_ignore_files}" ${xstow_args} \
1274 -pd-targets $PKGFS_MASTERDIR \
1275 -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
1277 if [ "$?" -ne 0 ]; then
1278 echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
1281 echo "==> Created \`$pkg' symlinks into master directory."
1284 register_pkg_handler register
$pkgname $version
1287 # Run template postinstall helpers if requested.
1289 if [ "$pkgname" != "${pkg%%-$version}" ]; then
1290 run_file
$PKGFS_TEMPLATESDIR/${pkg%%-$version}.tmpl
1293 for i
in ${postinstall_helpers}; do
1294 local pihf
="$PKGFS_TMPLHELPDIR/$i"
1295 [ -f "$pihf" ] && .
$pihf
1298 xstow_ignore_files
="$real_xstow_ignore"
1299 xstow_args
="$real_xstowargs"
1303 # Unstows a currently stowned package, i.e removes its links
1304 # from the master directory.
1309 local real_xstow_ignore
="$xstow_ignore_files"
1311 if [ -z "$pkg" ]; then
1312 echo "*** ERROR: template wasn't specified? ***"
1316 if [ "$pkg" = "xstow" ]; then
1317 echo "*** INFO: You aren't allowed to unstow \`$pkg'."
1321 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1324 # You cannot unstow a meta-template.
1326 [ "$build_style" = "meta-template" ] && return 0
1328 if [ -n "$ignore_files" ]; then
1329 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
1332 $PKGFS_XSTOW_CMD -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
1333 -D -i-file-in-dir share
/info
/dir
-ignore \
1334 "${xstow_ignore_files}" $PKGFS_DESTDIR/$pkgname-$version
1335 if [ $?
-ne 0 ]; then
1338 $rm_cmd -f $PKGFS_DESTDIR/$pkgname-$version/share
/info
/dir
1339 echo "==> Removed \`$pkg' symlinks from master directory."
1342 register_pkg_handler unregister
$pkgname $version
1344 xstow_ignore_files
="$real_xstow_ignore"
1350 args
=$
(getopt Cc $
*)
1351 [ "$?" -ne 0 ] && usage
1354 while [ "$#" -gt 0 ]; do
1360 config_file_specified
=yes
1361 PKGFS_CONFIG_FILE
="$2"
1372 [ "$#" -gt 2 ] && usage
1375 if [ -z "$target" ]; then
1376 echo "*** ERROR: missing target ***"
1381 # Check configuration vars before anyting else, and set defaults vars.
1391 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1392 extract_distfiles
$2
1395 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1396 configure_src_phase
$2
1403 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1404 extract_distfiles
$2
1406 configure_src_phase
$2
1411 extract_distfiles
$2
1440 echo "*** ERROR: invalid target \`$target' ***"