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 support for packages that need personalized installation.
32 # - Implement a chroot target that builds packages as root on it, for
33 # packages that need it (setuid, setgid).
34 # - More robust and fast dependency checking.
35 # - Multiple distfiles in a package, personalized stuff to unpack them.
36 # - Multiple URLs to download source distribution files, aliases, etc.
38 # Default path to configuration file, can be overriden
39 # via the environment or command line.
41 : ${PKGFS_CONFIG_FILE:=/usr/local/etc/pkgfs.conf}
43 : ${progname:=$(basename $0)}
44 : ${topdir:=$(/bin/pwd -P 2>/dev/null)}
45 : ${fetch_cmd:=/usr/bin/ftp -a}
46 : ${cksum_cmd:=/usr/bin/cksum -a rmd160}
47 : ${awk_cmd:=/usr/bin/awk}
48 : ${mkdir_cmd:=/bin/mkdir -p}
49 : ${tar_cmd:=/usr/bin/tar}
53 : ${sed_cmd=/usr/bin/sed}
54 : ${grep_cmd=/usr/bin/grep}
55 : ${gunzip_cmd:=/usr/bin/gunzip}
56 : ${bunzip2_cmd:=/usr/bin/bunzip2}
57 : ${patch_cmd:=/usr/bin/patch}
58 : ${find_cmd:=/usr/bin/find}
59 : ${file_cmd:=/usr/bin/file}
61 : ${chmod_cmd:=/bin/chmod}
62 : ${db_cmd:=/usr/bin/db -q}
63 : ${chmod_cmd:=/bin/chmod}
64 : ${touch_cmd:=/usr/bin/touch}
67 : ${xstow_ignore_files:=perllocal.pod} # XXX For now ignore them.
72 : ${PKGFS_TEMPLATESDIR:=$PKGFS_DISTRIBUTIONDIR/templates}
73 : ${PKGFS_DEPSDIR:=$PKGFS_DISTRIBUTIONDIR/dependencies}
74 : ${PKGFS_BUILD_DEPS_DB:=$PKGFS_DEPSDIR/build-depends.db}
75 : ${PKGFS_TMPLHELPDIR:=$PKGFS_DISTRIBUTIONDIR/helper-templates}
76 : ${PKGFS_REGPKG_DB:=$PKGFS_DESTDIR/.pkgfs-registered-pkgs.db}
78 local DDIRS
="PKGFS_DEPSDIR PKGFS_TEMPLATESDIR PKGFS_TMPLHELPDIR"
81 if [ ! -d "$val" ]; then
82 echo "**** ERROR: cannot find $i, aborting ***"
91 $progname: [-C] [-c <config_file>] <target> [package_name]
94 build Builds a package, only build phase is done.
95 configure Configure a package, only configure phase is done.
96 extract Extract distribution file(s) into build directory.
97 fetch Download distribution file(s).
98 info Show information about <package_name>.
99 install-destdir build + configure + install into destdir.
100 install Same than \`install-destdir´ but also stows package.
101 list Lists all currently \`stowned´ packages.
102 remove Remove package completely (unstow + remove data)
103 listfiles Lists files installed from <package_name>.
104 stow Create links in master directory.
105 unstow Remove links in master directory.
108 -C Do not remove build directory after successful installation.
109 -c Path to global configuration file:
110 if not specified /usr/local/etc/pkgfs.conf is used.
126 orig
="$topdir/${orig%/}"
142 # This function merges two GNU info dirs into one and puts the result
143 # into PKGFS_MASTERDIR/share/info/dir.
148 local merge_info_cmd
="$PKGFS_MASTERDIR/bin/merge-info"
150 [ -z "$pkgname" -o ! -r "$PKGFS_MASTERDIR/share/info/dir" \
151 -o ! -r "$PKGFS_DESTDIR/$pkgname/share/info/dir" ] && return 1
153 $merge_info_cmd -d $PKGFS_MASTERDIR/share
/info
/dir \
154 $PKGFS_DESTDIR/$pkgname/share
/info
/dir
-o \
155 $PKGFS_MASTERDIR/share
/info
/dir.new
156 if [ $?
-ne 0 ]; then
157 echo -n "*** WARNING: there was an error merging info dir from"
158 echo " $pkgname, aborting ***"
162 $mv_cmd -f $PKGFS_MASTERDIR/share
/info
/dir.new \
163 $PKGFS_MASTERDIR/share
/info
/dir
167 # Shows info about a template.
171 echo "pkgname: $pkgname"
172 echo "version: $version"
173 for i
in "${distfiles}"; do
174 [ -n "$i" ] && echo "distfile: $i"
177 echo "maintainer: $maintainer"
178 [ -n $checksum ] && echo "checksum: $checksum"
179 echo "build_style: $build_style"
180 echo "short_desc: $short_desc"
183 check_build_depends_pkg
$pkgname-$version
184 if [ $?
-eq 0 ]; then
185 local list
="$($db_cmd -V btree $PKGFS_BUILD_DEPS_DB $pkgname)"
186 echo "This package requires the following dependencies to be built:"
194 # Checks that all required variables specified in the configuration
195 # file are properly working.
201 if [ -z "$config_file_specified" ]; then
202 config_file_paths
="$PKGFS_CONFIG_FILE ./pkgfs.conf"
203 for f
in $config_file_paths; do
204 [ -f $f ] && PKGFS_CONFIG_FILE
=$f && \
207 if [ -z "$cffound" ]; then
208 echo -n "*** ERROR: config file not specified "
209 echo "and not in default location or current dir ***"
214 run_file
${PKGFS_CONFIG_FILE}
215 PKGFS_CONFIG_FILE
=$path_fixed
217 if [ ! -f "$PKGFS_CONFIG_FILE" ]; then
218 echo -n "*** ERROR: cannot find configuration file: "
219 echo "'$PKGFS_CONFIG_FILE' ***"
223 local PKGFS_VARS
="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
224 PKGFS_SRCDISTDIR PKGFS_SYSCONFDIR"
226 for f
in ${PKGFS_VARS}; do
228 if [ -z "$val" ]; then
229 echo -n "**** ERROR: '$f' not set in configuration "
230 echo "file, aborting ***"
234 if [ ! -d "$val" ]; then
236 if [ "$?" -ne 0 ]; then
237 echo -n "*** ERROR: couldn't create '$f'"
238 echo "directory, aborting ***"
246 # Resets all vars used by a template.
250 local TMPL_VARS
="pkgname extract_sufx distfiles url configure_args \
251 make_build_args make_install_args build_style \
252 short_desc maintainer long_desc checksum wrksrc \
253 patch_files configure_env make_cmd pkgconfig_override \
254 configure_env make_env 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 local rbcf
="$PKGFS_TEMPLATESDIR/$pkgname-runstuff-before-configure.sh"
596 [ -f $rbcf ] && .
$rbcf
597 [ -n "$run_stuff_before_configure_cmd" ] && \
598 ${run_stuff_before_configure_cmd}
600 # Export configure_env vars.
601 for f
in ${configure_env}; do
608 # Packages using GNU autoconf
610 if [ "$build_style" = "gnu_configure" ]; then
613 # Pass consistent arguments to not have unexpected
617 --prefix="$PKGFS_MASTERDIR" \
618 --mandir="$PKGFS_DESTDIR/$pkgname-$version/man" \
619 --infodir="$PKGFS_DESTDIR/$pkgname-$version/share/info" \
620 --sysconfdir="$PKGFS_SYSCONFDIR" \
624 # Packages using propietary configure scripts.
626 elif [ "$build_style" = "configure" ]; then
628 if [ -n "$configure_script" ]; then
629 .
/$configure_script ${configure_args}
631 .
/configure
${configure_args}
634 # Packages that are perl modules and use Makefile.PL files.
635 # They are all handled by the helper perl-module.sh.
637 elif [ "$build_style" = "perl_module" ]; then
638 .
$PKGFS_TMPLHELPDIR/perl-module.sh
639 perl_module_build
$pkgname
642 # Packages with BSD or GNU Makefiles are easy, just skip
643 # the configure stage and proceed.
645 elif [ "$build_style" = "bsd_makefile" -o \
646 "$build_style" = "gnu_makefile" ]; then
650 # Unknown build_style type won't work :-)
653 echo "*** ERROR unknown build_style \`$build_style' ***"
657 if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
658 echo "*** ERROR building (configure state) \`$pkg' ***"
662 # unset configure_env vars.
663 for f
in ${configure_env}; do
667 $touch_cmd -f $PKGFS_CONFIGURE_DONE
671 # Runs the "build" phase for a pkg. This builds the binaries and other
677 local pkg
="$pkgname-$version"
679 [ -z $pkgparam ] && [ -z $pkgname -o -z $version ] && return 1
682 # There's nothing of interest if we are a meta template.
684 [ "$build_style" = "meta-template" ] && return 0
686 if [ ! -d $wrksrc ]; then
687 echo "*** ERROR: unexistent build directory \`$wrksrc' ***"
693 echo "=> Running \`\`build´´ phase for \`$pkg'."
696 # Assume BSD make if make_cmd not set in template.
698 if [ -z "$make_cmd" ]; then
699 make_cmd
="/usr/bin/make"
702 # Fixup libtool script if necessary
706 # Run template stuff before building.
708 local rbbf
="$PKGFS_TEMPLATESDIR/$pkgname-runstuff-before-build.sh"a
709 [ -f $rbbf ] && .
$rbbf
710 [ -n "$run_stuff_before_build_cmd" ] && ${run_stuff_before_build_cmd}
713 [ -z "$make_build_target" ] && make_build_target
=
714 [ -n "$PKGFS_MAKEJOBS" ] && PKGFS_MAKEJOBS
="-j$PKGFS_MAKEJOBS"
716 # Export make_env vars.
717 for f
in ${make_env}; do
722 # Build package via make.
724 ${make_cmd} ${PKGFS_MAKEJOBS} ${make_build_args} ${make_build_target}
725 if [ "$?" -ne 0 ]; then
726 echo "*** ERROR building (make stage) \`$pkg' ***"
731 # Run template stuff before installing.
733 local rbif
="$PKGFS_TEMPLATESDIR/$pkgname-runstuff-before-install.sh"
734 [ -f $rbif ] && .
$rbif
735 [ -n "$run_stuff_before_install_cmd" ] && ${run_stuff_before_install_cmd}
737 $touch_cmd -f $PKGFS_BUILD_DONE
741 # Runs the "install" phase for a pkg. This consists in installing package
742 # into the destination directory.
748 [ -z $pkg ] && [ -z $pkgname ] && return 1
750 [ -z "$make_install_target" ] && make_install_target
=install
753 # There's nothing we can do if we are a meta template.
755 [ "$build_style" = "meta-template" ] && return 0
757 if [ ! -d $wrksrc ]; then
758 echo "*** ERROR: unexistent build directory \`$wrksrc' ***"
764 echo "=> Running \`\`install´´ phase for: \`$pkgname-$version´."
767 # Install package via make.
769 ${make_cmd} ${make_install_args} ${make_install_target} \
770 prefix
="$PKGFS_DESTDIR/$pkgname-$version"
771 if [ "$?" -ne 0 ]; then
772 echo "*** ERROR instaling \`$pkgname-$version' ***"
776 # Unset make_env vars.
777 for f
in ${make_env}; do
782 # Run template stuff after installing.
784 local raif
="$PKGFS_TEMPLATESDIR/$pkgname-runstuff-after-install.sh"
785 [ -f $raif ] && .
$raif
786 [ -n "$run_stuff_after_install_cmd" ] && ${run_stuff_after_install_cmd}
789 # Transform pkg-config files if requested by template.
791 for i
in ${pkgconfig_override}; do
792 local tmpf
="$PKGFS_DESTDIR/$pkgname-$version/lib/pkgconfig/$i"
794 [ -f $PKGFS_TMPLHELPDIR/pkg-config-transform.sh
] && \
795 .
$PKGFS_TMPLHELPDIR/pkg-config-transform.sh
&& \
796 pkgconfig_transform_file
$tmpf
802 echo "==> Installed \`$pkgname-$version' into $PKGFS_DESTDIR."
804 $touch_cmd -f $PKGFS_INSTALL_DONE
807 # Remove $wrksrc if -C not specified.
809 if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
812 echo "=> Removed \`$pkgname-$version' build directory."
819 # Registers or unregisters a package from the db file.
821 register_pkg_handler
()
827 [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1
829 if [ "$action" = "register" ]; then
830 $db_cmd -w btree
$PKGFS_REGPKG_DB $pkg $version 2>&1 >/dev
/null
831 if [ "$?" -ne 0 ]; then
832 echo -n "*** ERROR: couldn't register \`$pkg'"
833 echo " in db file ***"
836 elif [ "$action" = "unregister" ]; then
837 $db_cmd -d btree
$PKGFS_REGPKG_DB $pkg 2>&1 >/dev
/null
838 if [ "$?" -ne 0 ]; then
839 echo -n "*** ERROR: \`$pkg' not registered "
840 echo "in db file? ***"
849 # Recursive function that founds dependencies in all required
852 add_dependency_tolist
()
856 [ -z "$curpkg" ] && return 1
857 [ -n "$prev_pkg" ] && curpkg
=$prev_pkg
859 for i
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do
861 # Check if dep already installed.
863 if [ -r "$PKGFS_REGPKG_DB" ]; then
864 check_installed_pkg
$i ${i##[aA-zZ]*-}
866 # If dep is already installed, put it on the
867 # installed deps list and continue.
869 if [ $?
-eq 0 ]; then
870 installed_deps_list
="$i $installed_deps_list"
874 deps_list
="$i $deps_list"
875 [ -n "$prev_pkg" ] && unset prev_pkg
877 # Check if dependency needs more deps.
879 check_build_depends_pkg
${i%-[0-9]*.*}
880 if [ $?
-eq 0 ]; then
881 add_dependency_tolist
$i
889 # Removes duplicate deps in the installed or not installed list.
891 find_dupdeps_inlist
()
897 [ -z "$action" ] && return 1
901 list
=$installed_deps_list
912 if [ -z "$tmp_list" ]; then
915 for i
in $tmp_list; do
916 [ "$f" = "$i" ] && dup
=yes
919 [ -z "$dup" ] && tmp_list
="$tmp_list $f"
926 installed_deps_list
="$tmp_list"
929 deps_list
="$tmp_list"
938 # Installs all dependencies required by a package.
940 install_dependencies_pkg
()
946 [ -z "$pkg" ] && return 1
950 add_dependency_tolist
$pkg
951 find_dupdeps_inlist installed
952 find_dupdeps_inlist notinstalled
954 [ -z "$deps_list" -a -z "$installed_deps_list" ] && return 0
956 echo "==> Required dependencies for $(basename $pkg):"
957 for i
in ${installed_deps_list}; do
958 fpkg
="$($db_cmd -O '-' btree $PKGFS_REGPKG_DB ${i%-[0-9]*.*})"
959 echo " $i: found $fpkg."
962 for i
in ${deps_list}; do
963 echo " $i: not installed."
966 for i
in ${deps_list}; do
968 check_installed_pkg
$i ${i##[aA-zZ]*-}
969 [ $?
-eq 0 ] && continue
970 # continue installing deps
971 echo "==> Installing \`$pkg´ dependency: \`$i´."
972 install_pkg
${i%-[0-9]*.*}
975 unset installed_deps_list
979 install_builddeps_required_pkg
()
983 [ -z "$pkg" ] && return 1
985 for dep
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*}); do
986 check_installed_pkg
$dep ${dep##[aA-zZ]*-}
987 if [ $?
-ne 0 ]; then
988 echo "==> Installing \`$pkg´ dependency: $dep."
989 install_pkg
${dep%-[0-9]*.*}
995 # Checks the registered pkgs db file and returns 0 if a pkg that satisfies
996 # the minimal required version is there, or 1 otherwise.
998 check_installed_pkg
()
1004 [ -z "$pkg" -o -z "$reqver" -o ! -r $PKGFS_REGPKG_DB ] && return 1
1006 run_file
$PKGFS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
1008 reqver
="$(echo $reqver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1010 $db_cmd -K btree
$PKGFS_REGPKG_DB $pkgname 2>&1 >/dev
/null
1011 if [ $?
-eq 0 ]; then
1013 # Package is installed, let's check the version.
1015 iver
="$($db_cmd -V btree $PKGFS_REGPKG_DB $pkgname)"
1016 if [ -n "$iver" ]; then
1018 # As shell only supports decimal arith expressions,
1019 # we simply remove anything except the numbers.
1020 # It's not optimal and may fail, but it is enough
1023 iver
="$(echo $iver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1024 if [ "$iver" -eq "$reqver" \
1025 -o "$iver" -gt "$reqver" ]; then
1035 # Checks the build depends db file and returns 0 if pkg has dependencies,
1036 # otherwise returns 1.
1038 check_build_depends_pkg
()
1042 [ -z $pkg -o ! -r $PKGFS_BUILD_DEPS_DB ] && return 1
1044 $db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev
/null
1049 # Installs a pkg by reading its build template file.
1056 local cur_tmpl
="$PKGFS_TEMPLATESDIR/$curpkgn.tmpl"
1057 if [ -z $cur_tmpl -o ! -f $cur_tmpl ]; then
1058 echo "*** ERROR: cannot find \`$cur_tmpl´ template file ***"
1064 pkg
="$curpkgn-$version"
1067 # If we are the originator package save the path this template in
1068 # other var for future use.
1070 [ -z "$origin_tmpl" ] && origin_tmpl
=$pkgname
1073 # Install xstow if it's not there.
1078 # We are going to install a new package.
1083 # Install dependencies required by this package.
1085 if [ -z "$doing_deps" ]; then
1086 install_dependencies_pkg
$pkg
1088 # At this point all required deps are installed, and
1089 # only remaining is the origin template; install it.
1097 # Fetch, extract, build and install into the destination directory.
1101 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1105 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1109 if [ ! -f "$PKGFS_BUILD_DONE" ]; then
1116 # Just register meta-template and exit.
1118 if [ "$build_style" = "meta-template" ]; then
1119 register_pkg_handler register
$pkgname $version
1120 echo "==> Installed meta-template \`$pkg'."
1125 # Do not stow package if it wasn't requested.
1127 [ -z "$install_destdir_target" ] && stow_pkg
$pkg
1131 # Installs and stows the "xstow" package.
1135 [ -x "$PKGFS_XSTOW_CMD" ] && return 0
1137 echo "=> xstow application not found, will install it now."
1143 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1147 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1151 if [ ! -f "$PKGFS_BUILD_DONE" ]; then
1157 PKGFS_XSTOW_CMD
="$PKGFS_DESTDIR/$pkgname-$version/bin/xstow"
1158 stow_pkg
$pkgname-$version
1161 # Continue with package that called us.
1163 run_file
$PKGFS_TEMPLATESDIR/$origin_tmpl.tmpl
1167 # Lists all currently installed packages.
1171 if [ ! -r "$PKGFS_REGPKG_DB" ]; then
1172 echo "=> No packages registered or missing register db file."
1176 for i
in $
($db_cmd -K btree
$PKGFS_REGPKG_DB); do
1177 # Run file to get short_desc and print something useful
1178 run_file
$PKGFS_TEMPLATESDIR/$i.tmpl
1179 echo "$i-$version $short_desc"
1185 # Lists files installed by a package.
1191 if [ -z $pkg ]; then
1192 echo "*** ERROR: unexistent package, aborting ***"
1196 if [ ! -d "$PKGFS_DESTDIR/$pkg" ]; then
1197 echo "*** ERROR: cannot find \`$pkg' in $PKGFS_DESTDIR ***"
1201 for f
in $
($find_cmd $PKGFS_DESTDIR/$pkg -type f
-print |
sort -u); do
1202 echo "${f##$PKGFS_DESTDIR/$pkg/}"
1207 # Removes a currently installed package (unstow + removed from destdir).
1213 if [ -z "$pkg" ]; then
1214 echo "*** ERROR: unexistent package, aborting ***"
1218 if [ ! -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
1219 echo "*** ERROR: cannot find template file ***"
1223 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1226 # If it's a meta-template, just unregister it from the db.
1228 if [ "$build_style" = "meta-template" ]; then
1229 register_pkg_handler unregister
$pkgname $version
1231 echo "=> Removed meta-template \`$pkg'."
1235 if [ ! -d "$PKGFS_DESTDIR/$pkg-$version" ]; then
1236 echo "*** ERROR: cannot find package on $PKGFS_DESTDIR ***"
1241 $rm_cmd -rf $PKGFS_DESTDIR/$pkg-$version
1246 # Stows a currently installed package, i.e creates the links
1247 # on the master directory.
1252 local infodir_pkg
="share/info/dir"
1253 local infodir_master
="$PKGFS_MASTERDIR/share/info/dir"
1254 local real_xstowargs
="$xstow_args"
1255 local real_xstow_ignore
="$xstow_ignore_files"
1257 [ -z "$pkg" ] && return 2
1259 if [ -n "$stow_flag" ]; then
1260 pkg
=$PKGFS_TEMPLATESDIR/$pkg.tmpl
1262 pkg
=$pkgname-$version
1264 # You cannot stow a meta-template.
1266 [ "$build_style" = "meta-template" ] && return 0
1269 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" ]; then
1270 merge_infodir_tmpl
$pkg
1273 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" \
1274 -a -r "$infodir_master" ]; then
1275 xstow_args
="$xstow_args -i-file-in-dir $infodir_pkg"
1278 if [ -n "$ignore_files" ]; then
1279 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
1282 $PKGFS_XSTOW_CMD -ignore "${xstow_ignore_files}" ${xstow_args} \
1283 -pd-targets $PKGFS_MASTERDIR \
1284 -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
1286 if [ "$?" -ne 0 ]; then
1287 echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
1290 echo "==> Created \`$pkg' symlinks into master directory."
1293 register_pkg_handler register
$pkgname $version
1296 # Run template postinstall helpers if requested.
1298 if [ "$pkgname" != "${pkg%%-$version}" ]; then
1299 run_file
$PKGFS_TEMPLATESDIR/${pkg%%-$version}.tmpl
1302 for i
in ${postinstall_helpers}; do
1303 local pihf
="$PKGFS_TMPLHELPDIR/$i"
1304 [ -f "$pihf" ] && .
$pihf
1307 xstow_ignore_files
="$real_xstow_ignore"
1308 xstow_args
="$real_xstowargs"
1312 # Unstows a currently stowned package, i.e removes its links
1313 # from the master directory.
1318 local real_xstow_ignore
="$xstow_ignore_files"
1320 if [ -z "$pkg" ]; then
1321 echo "*** ERROR: template wasn't specified? ***"
1325 if [ "$pkg" = "xstow" ]; then
1326 echo "*** INFO: You aren't allowed to unstow \`$pkg'."
1330 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1333 # You cannot unstow a meta-template.
1335 [ "$build_style" = "meta-template" ] && return 0
1337 if [ -n "$ignore_files" ]; then
1338 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
1341 $PKGFS_XSTOW_CMD -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
1342 -D -i-file-in-dir share
/info
/dir
-ignore \
1343 "${xstow_ignore_files}" $PKGFS_DESTDIR/$pkgname-$version
1344 if [ $?
-ne 0 ]; then
1347 $rm_cmd -f $PKGFS_DESTDIR/$pkgname-$version/share
/info
/dir
1348 echo "==> Removed \`$pkg' symlinks from master directory."
1351 register_pkg_handler unregister
$pkgname $version
1353 xstow_ignore_files
="$real_xstow_ignore"
1359 args
=$
(getopt Cc $
*)
1360 [ "$?" -ne 0 ] && usage
1363 while [ "$#" -gt 0 ]; do
1369 config_file_specified
=yes
1370 PKGFS_CONFIG_FILE
="$2"
1381 [ "$#" -gt 2 ] && usage
1384 if [ -z "$target" ]; then
1385 echo "*** ERROR: missing target ***"
1390 # Check configuration vars before anyting else, and set defaults vars.
1400 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1401 extract_distfiles
$2
1404 if [ ! -f "$PKGFS_CONFIGURE_DONE" ]; then
1405 configure_src_phase
$2
1412 if [ ! -f "$PKGFS_EXTRACT_DONE" ]; then
1413 extract_distfiles
$2
1415 configure_src_phase
$2
1420 extract_distfiles
$2
1431 install_destdir_target
=yes
1456 echo "*** ERROR: invalid target \`$target' ***"