3 # pkgfs - Builds source distribution files and stows/unstows them into
4 # a master directory, thanks to Xstow.
7 # Copyright (c) 2008 Juan Romero Pardines.
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # - Implement a routine that checks if installed version is sufficient
33 # to satisfy the required dependency... right now it's very prone
35 # - Multiple distfiles in a package.
36 # - Multiple URLs to download source distribution files.
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}
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"
79 if [ ! -d "$PKGFS_DEPSDIR" ]; then
80 echo "**** ERROR: cannot find $i, aborting ***"
89 $progname: [-bCefi] [-c <config_file>] <target> <tmplname>
92 info Show information about <tmplname>.
93 install Build and install package from <tmplname>.
94 list Lists and prints short description about installed packages.
95 remove Remove package completely (unstow and remove from destdir)
96 stow Create symlinks from <tmplname> in master directory.
97 unstow Remove symlinks from <tmplname> in master directory.
100 -b Only build the source distribution file(s), without
101 extracting or fetching before.
102 -C Do not remove build directory after successful build.
103 -c Path to global configuration file.
104 If not specified /usr/local/etc/pkgfs.conf is used.
105 -e Only extract the source distribution file(s).
106 -f Only fetch the source distribution file(s).
107 -i Only build and install the binary distribution file(s)
108 into the destdir directory, without stowning.
124 orig
="$topdir/${orig%/}"
140 # This function merges two GNU info dirs into one and puts the result
141 # into PKGFS_MASTERDIR/share/info/dir.
146 local merge_info_cmd
="$PKGFS_MASTERDIR/bin/merge-info"
148 [ -z "$pkgname" ] && return 1
149 [ ! -r "$PKGFS_MASTERDIR/share/info/dir" ] && return 1
150 [ ! -r "$PKGFS_DESTDIR/$pkgname/share/info/dir" ] && return 1
152 $merge_info_cmd -d $PKGFS_MASTERDIR/share
/info
/dir \
153 $PKGFS_DESTDIR/$pkgname/share
/info
/dir
-o \
154 $PKGFS_MASTERDIR/share
/info
/dir.new
155 if [ "$?" -ne 0 ]; then
156 echo -n "*** WARNING: there was an error merging info dir from"
157 echo " $pkgname, aborting ***"
161 $mv_cmd -f $PKGFS_MASTERDIR/share
/info
/dir.new \
162 $PKGFS_MASTERDIR/share
/info
/dir
166 # Shows info about a template.
171 if [ -z "$tmpl" -o ! -f "$PKGFS_TEMPLATESDIR/$tmpl.tmpl" ]; then
172 echo -n "*** ERROR: invalid template file \`$tmpl' ***"
173 echo ", aborting ***"
177 run_file
$PKGFS_TEMPLATESDIR/$tmpl.tmpl
179 echo "pkgname: $pkgname"
180 echo "version: $version"
181 for i
in "${distfiles}"; do
182 [ -n "$i" ] && echo "distfile: $i"
185 echo "maintainer: $maintainer"
186 [ -n $checksum ] && echo "checksum: $checksum"
187 echo "build_style: $build_style"
188 echo "short_desc: $short_desc"
191 check_build_depends_tmpl
$pkgname-$version
192 if [ "$?" -eq 0 ]; then
193 local list
="$($db_cmd -V btree $PKGFS_BUILD_DEPS_DB $pkgname)"
194 echo "This package requires the following dependencies to be built:"
202 # Applies to the build directory the patches specified by a template.
206 if [ -z "$PKGFS_TEMPLATESDIR" ]; then
207 echo -n "*** WARNING: PKGFS_TEMPLATESDIR is not set, "
208 echo "won't apply patches ***"
213 # If package needs some patches applied before building,
216 if [ -n "$patch_files" ]; then
217 for i
in ${patch_files}; do
218 patch="$PKGFS_TEMPLATESDIR/$i"
219 if [ ! -f "$patch" ]; then
220 echo "*** WARNING: unexistent patch '$i' ***"
224 # Try to guess if its a compressed patch.
225 if $
(echo $patch|
$grep_cmd -q .gz
); then
228 elif $
(echo $patch|
$grep_cmd -q .bz2
); then
231 elif $
(echo $patch|
$grep_cmd -q .
diff); then
234 echo "*** WARNING: unknown patch type '$i' ***"
238 cd $wrksrc && $patch_cmd < $patch 2>/dev
/null
239 if [ "$?" -eq 0 ]; then
240 echo "=> Patch applied: \`$i'."
242 echo -n "*** ERROR: couldn't apply patch '$i'"
243 echo ", aborting ***"
251 # Checks that all required variables specified in the configuration
252 # file are properly working.
258 if [ -z "$config_file_specified" ]; then
259 config_file_paths
="$PKGFS_CONFIG_FILE ./pkgfs.conf"
260 for f
in $config_file_paths; do
261 [ -f $f ] && PKGFS_CONFIG_FILE
=$f && \
264 if [ -z "$cffound" ]; then
265 echo -n "*** ERROR: config file not specified "
266 echo "and not in default location or current dir ***"
271 run_file
${PKGFS_CONFIG_FILE}
272 PKGFS_CONFIG_FILE
=$path_fixed
274 if [ ! -f "$PKGFS_CONFIG_FILE" ]; then
275 echo -n "*** ERROR: cannot find configuration file: "
276 echo "'$PKGFS_CONFIG_FILE' ***"
280 local PKGFS_VARS
="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
281 PKGFS_SRCDISTDIR PKGFS_SYSCONFDIR"
283 for f
in ${PKGFS_VARS}; do
285 if [ -z "$val" ]; then
286 echo -n "**** ERROR: '$f' not set in configuration "
287 echo "file, aborting ***"
291 if [ ! -d "$f" ]; then
293 if [ "$?" -ne 0 ]; then
294 echo -n "*** ERROR: couldn't create '$f'"
295 echo "directory, aborting ***"
303 # Resets all vars used by a template.
307 local TMPL_VARS
="pkgname extract_sufx distfiles url configure_args \
308 make_build_args make_install_args build_style \
309 short_desc maintainer long_desc checksum wrksrc \
310 patch_files configure_env make_cmd pkgconfig_override \
311 run_stuff_before run_stuff_after \
312 run_stuff_before_configure_file run_stuff_before_build_file \
313 run_stuff_before_install_file run_stuff_after_install \
314 run_stuff_after_install_file make_build_target \
315 run_stuff_before_configure_cmd run_stuff_before_build_cmd \
316 run_stuff_before_install_cmd run_stuff_after_install_cmd \
317 make_install_target postinstall_helpers version \
320 for i
in ${TMPL_VARS}; do
326 # Checks some vars used in templates and sets $extract_cmd.
333 [ -z "$pkg" ] && return 1
335 # There's nothing of interest if we are a meta template.
337 [ "$build_style" = "meta-template" ] && return 0
339 REQ_VARS
="pkgname version extract_sufx url build_style"
341 # Check if required vars weren't set.
342 for i
in ${REQ_VARS}; do
344 if [ -z "$val" -o -z "$i" ]; then
345 echo -n "*** ERROR: $i not set (incomplete template"
346 echo " build file), aborting ***"
351 if [ -z "$distfiles" ]; then
352 dfile
="$pkgname-$version$extract_sufx"
353 elif [ -n "${distfiles}" ]; then
354 dfile
="$distfiles$extract_sufx"
356 echo "*** ERROR unsupported fetch state ***"
360 dfile
="$PKGFS_SRCDISTDIR/$dfile"
362 case "$extract_sufx" in
363 .
tar.bz2|.
tar.gz|.tgz|.tbz
)
364 extract_cmd
="$tar_cmd xfz $dfile -C $PKGFS_BUILDDIR"
367 extract_cmd
="$tar_cmd xf $dfile -C $PKGFS_BUILDDIR"
370 if [ -f "$PKGFS_TMPLHELPDIR/unzip-extraction.sh" ]; then
371 .
$PKGFS_TMPLHELPDIR/unzip-extraction.sh
373 # $extract_cmd set by the helper
376 echo -n "*** ERROR: unknown 'extract_sufx' argument in build "
384 # Verifies that a checksum of a distfile is correct.
391 [ -z "$file" ] && return 1
393 if [ -z "${distfiles}" ]; then
394 dfile
="$pkgname-$version$extract_sufx"
395 elif [ -n "${distfiles}" ]; then
396 dfile
="$distfiles$extract_sufx"
398 dfile
="$file$extract_sufx"
401 if [ -z "$checksum" ]; then
402 echo "*** ERROR: checksum unset in template file for \`$pkgname' ***"
407 dfile
="$PKGFS_SRCDISTDIR/$dfile"
408 filesum
="$($cksum_cmd $dfile | $awk_cmd '{print $4}')"
409 if [ "$origsum" != "$filesum" ]; then
410 echo "*** WARNING: checksum doesn't match (rmd160) ***"
416 # Downloads the distfiles for a template from $url.
423 [ -z "$pkgname" ] && return 1
425 # There's nothing of interest if we are a meta template.
427 [ "$build_style" = "meta-template" ] && return 0
429 if [ -z "$distfiles" ]; then
430 file="$pkgname-$version"
436 file2
="$f$extract_sufx"
437 if [ -f "$PKGFS_SRCDISTDIR/$file2" ]; then
438 check_rmd160_cksum
$f
439 if [ "$?" -eq 0 ]; then
440 if [ -n "$only_fetch" ]; then
441 echo "=> checksum ok"
448 echo "==> Fetching \`$file2' source tarball"
450 cd $PKGFS_SRCDISTDIR && $fetch_cmd $url/$file2
451 if [ "$?" -ne 0 ]; then
452 if [ ! -f $PKGFS_SRCDISTDIR/$file2 ]; then
453 echo -n "*** ERROR: couldn't fetch '$file2', "
456 echo -n "*** ERROR: there was an error "
457 echo "fetching '$file2', aborting ***"
461 if [ -n "$only_fetch" ]; then
469 # Extracts contents of a distfile specified in a template into
470 # the build directory.
472 extract_tmpl_sources
()
474 [ -z "$pkgname" ] && return 1
477 # There's nothing of interest if we are a meta template.
479 [ "$build_style" = "meta-template" ] && return 0
481 echo "==> Extracting \`$pkgname-$version' into $PKGFS_BUILDDIR."
484 if [ "$?" -ne 0 ]; then
485 echo -n "*** ERROR: there was an error extracting the "
486 echo "distfile, aborting *** "
491 [ -n "$only_extract" ] && exit 0
496 local lt_file
="$wrksrc/libtool"
499 # If package has a libtool file replace it with ours, so that
500 # we use the master directory while relinking, all will be fine
501 # once the package is stowned.
503 if [ -f "$lt_file" -a -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
504 $rm_cmd -f $wrksrc/libtool
505 $rm_cmd -f $wrksrc/ltmain.sh
506 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
507 $ln_cmd -s $PKGFS_MASTERDIR/share
/libtool
/config
/ltmain.sh \
509 elif [ -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
510 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
515 # Configures, builds and installs a package into the destination
520 local pkg
="$pkgname-$version"
522 [ -z "$pkgname" -o -z "$version" ] && return 1
524 # There's nothing of interest if we are a meta template.
526 [ "$build_style" = "meta-template" ] && return 0
528 if [ -n "$distfiles" -a -z "$wrksrc" ]; then
529 wrksrc
=$PKGFS_BUILDDIR/$distfiles
530 elif [ -z "$wrksrc" ]; then
531 wrksrc
=$PKGFS_BUILDDIR/$pkg
533 wrksrc
=$PKGFS_BUILDDIR/$wrksrc
536 if [ ! -d "$wrksrc" ]; then
537 echo "*** ERROR: unexistent build directory, aborting ***"
541 export PATH
="/bin:/sbin:/usr/bin:/usr/sbin:$PKGFS_MASTERDIR/bin:$PKGFS_MASTERDIR/sbin"
543 # Apply patches if requested by template file
546 echo "==> Building \`$pkg' (be patient, may take a while)"
549 # For now, just set them through the environment.
551 LDFLAGS
="-L$PKGFS_MASTERDIR/lib -Wl,-R$PKGFS_MASTERDIR/lib $LDFLAGS"
552 export LDFLAGS
="-L$PKGFS_DESTDIR/$pkg/lib $LDFLAGS"
553 export CFLAGS
="$CFLAGS $PKGFS_CFLAGS"
554 export CXXFLAGS
="$CXXFLAGS $PKGFS_CXXFLAGS"
555 export CPPFLAGS
="-I$PKGFS_MASTERDIR/include $CPPFLAGS"
556 export PKG_CONFIG
="$PKGFS_MASTERDIR/bin/pkg-config"
558 # Run stuff before configure.
559 for i
in "$run_stuff_before"; do
560 if [ "$i" = "configure" ]; then
561 [ -f $run_stuff_before_configure_file ] && \
562 .
$run_stuff_before_configure_file
563 [ -n "$run_stuff_before_configure_cmd" ] && \
564 ${run_stuff_before_configure_cmd}
569 # Packages using GNU autoconf
571 if [ "$build_style" = "gnu_configure" ]; then
572 for i
in ${configure_env}; do
573 [ -n "$i" ] && export $i
577 # Pass consistent arguments to not have unexpected
580 .
/configure
--prefix="$PKGFS_MASTERDIR" \
581 --mandir="$PKGFS_DESTDIR/$pkg/man" \
582 --infodir="$PKGFS_DESTDIR/$pkg/share/info" \
583 --sysconfdir="$PKGFS_SYSCONFDIR" \
587 # Packages using propietary configure scripts.
589 elif [ "$build_style" = "configure" ]; then
591 if [ -n "$configure_script" ]; then
592 .
/$configure_script ${configure_args}
594 .
/configure
${configure_args}
597 # Packages that are perl modules and use Makefile.PL files.
598 # They are all handled by the helper perl-module.sh.
600 elif [ "$build_style" = "perl_module" ]; then
601 .
$PKGFS_TMPLHELPDIR/perl-module.sh
602 perl_module_build
$pkgname
605 # Packages with BSD or GNU Makefiles are easy, just skip
606 # the configure stage and proceed.
608 elif [ "$build_style" = "bsd_makefile" -o \
609 "$build_style" = "gnu_makefile" ]; then
613 # Unknown build_style type won't work :-)
616 echo "*** ERROR unknown build_style $build_style, aborting ***"
620 if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
621 echo "*** ERROR building (configure state) \`$pkg' ***"
626 # Assume BSD make if make_cmd not set in template.
628 if [ -z "$make_cmd" ]; then
629 make_cmd
="/usr/bin/make"
632 # Fixup libtool script if necessary
636 # Run template stuff before building.
638 for i
in ${run_stuff_before}; do
639 if [ "$i" = "build" ]; then
640 [ -f $run_stuff_before_build_file ] && \
641 .
$run_stuff_before_build_file
642 [ -n "$run_stuff_before_build_cmd" ] && \
643 ${run_stuff_before_build_cmd}
647 [ -z "$make_build_target" ] && make_build_target
=
648 [ -n "$PKGFS_MAKEJOBS" ] && PKGFS_MAKEJOBS
="-j$PKGFS_MAKEJOBS"
650 # Build package via make.
652 ${make_cmd} ${PKGFS_MAKEJOBS} ${make_build_args} ${make_build_target}
653 if [ "$?" -ne 0 ]; then
654 echo "*** ERROR building (make stage) \`$pkg' ***"
659 # Run template stuff before installing.
661 for i
in ${run_stuff_before}; do
662 if [ "$i" = "install" ]; then
663 [ -f $run_stuff_before_install_file ] && \
664 .
$run_stuff_before_install_file
665 [ -n "$run_stuff_before_install_cmd" ] && \
666 ${run_stuff_before_install_cmd}
670 [ -z "$make_install_target" ] && make_install_target
=install
673 # Install package via make.
675 ${make_cmd} ${make_install_args} ${make_install_target} \
676 prefix
="$PKGFS_DESTDIR/$pkg"
677 if [ "$?" -ne 0 ]; then
678 echo "*** ERROR instaling \`$pkg' ***"
683 # Run template stuff after installing.
685 for i
in ${run_stuff_after}; do
686 if [ "$i" = "install" ]; then
687 [ -f $run_stuff_after_install_file ] && \
688 .
$run_stuff_after_install_file
689 [ -n "$run_stuff_after_install_cmd" ] && \
690 ${run_stuff_after_install_cmd}
695 # Transform pkg-config files if requested by template.
697 for i
in ${pkgconfig_override}; do
698 local tmpf
="$PKGFS_DESTDIR/$pkg/lib/pkgconfig/$i"
700 [ -f $PKGFS_TMPLHELPDIR/pkg-config-transform.sh
] && \
701 .
$PKGFS_TMPLHELPDIR/pkg-config-transform.sh
&& \
702 pkgconfig_transform_file
$tmpf
706 echo "==> Installed \`$pkg' into $PKGFS_DESTDIR/$pkg."
709 # Once all work has been done, unset compilation vars.
711 unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS PKG_CONFIG
714 # Remove $wrksrc if -C not specified.
716 if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
719 echo "=> Removed \`$pkg' build directory."
726 # Stows a currently installed package, i.e creates the links
727 # on the master directory.
732 local infodir_pkg
="share/info/dir"
733 local infodir_master
="$PKGFS_MASTERDIR/share/info/dir"
734 local real_xstowargs
="$xstow_args"
735 local real_xstow_ignore
="$xstow_ignore_files"
737 [ -z "$pkg" ] && return 2
739 if [ -n "$stow_flag" ]; then
740 pkg
=$PKGFS_TEMPLATESDIR/$pkg.tmpl
742 pkg
=$pkgname-$version
744 # You cannot stow a meta-template.
746 [ "$build_style" = "meta-template" ] && return 0
749 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" ]; then
750 merge_infodir_tmpl
$pkg
753 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" \
754 -a -r "$infodir_master" ]; then
755 xstow_args
="$xstow_args -i-file-in-dir $infodir_pkg"
758 if [ -n "$ignore_files" ]; then
759 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
762 $PKGFS_XSTOW_CMD -ignore "${xstow_ignore_files}" ${xstow_args} \
763 -pd-targets $PKGFS_MASTERDIR \
764 -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
766 if [ "$?" -ne 0 ]; then
767 echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
770 echo "==> Created \`$pkg' symlinks into master directory."
773 installed_tmpl_handler register
$pkgname $version
776 # Run template postinstall helpers if requested.
778 if [ "$pkgname" != "${pkg%%-$version}" ]; then
779 run_file
$PKGFS_TEMPLATESDIR/${pkg%%-$version}.tmpl
782 for i
in ${postinstall_helpers}; do
783 local pihf
="$PKGFS_TMPLHELPDIR/$i"
784 [ -f "$pihf" ] && .
$pihf
787 xstow_ignore_files
="$real_xstow_ignore"
788 xstow_args
="$real_xstowargs"
792 # Unstows a currently stowned package, i.e removes its links
793 # from the master directory.
798 local real_xstow_ignore
="$xstow_ignore_files"
800 if [ -z "$pkg" ]; then
801 echo "*** ERROR: template wasn't specified? ***"
805 if [ "$pkg" = "xstow" ]; then
806 echo "*** INFO: You aren't allowed to unstow \`$pkg'."
810 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
813 # You cannot unstow a meta-template.
815 [ "$build_style" = "meta-template" ] && return 0
817 if [ -n "$ignore_files" ]; then
818 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
821 $PKGFS_XSTOW_CMD -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
822 -D -i-file-in-dir share
/info
/dir
-ignore \
823 "${xstow_ignore_files}" $PKGFS_DESTDIR/$pkgname-$version
824 if [ "$?" -ne 0 ]; then
827 $rm_cmd -f $PKGFS_DESTDIR/$pkgname-$version/share
/info
/dir
828 echo "==> Removed \`$pkg' symlinks from master directory."
831 installed_tmpl_handler unregister
$pkgname $version
833 xstow_ignore_files
="$real_xstow_ignore"
837 # Recursive function that founds dependencies in all required
840 add_dependency_tolist
()
844 [ -z "$curpkg" ] && return 1
845 [ -n "$prev_pkg" ] && curpkg
=$prev_pkg
847 for i
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do
849 # Check if dep already installed.
851 if [ -r "$PKGFS_REGPKG_DB" ]; then
852 check_installed_tmpl
$i ${i##[aA-zZ]*-}
854 # If dep is already installed, put it on the
855 # installed deps list and continue.
857 if [ "$?" -eq 0 ]; then
858 installed_deps_list
="$i $installed_deps_list"
862 deps_list
="$i $deps_list"
863 [ -n "$prev_pkg" ] && unset prev_pkg
865 # Check if dependency needs more deps.
867 check_build_depends_tmpl
${i%-[0-9]*.*}
868 if [ "$?" -eq 0 ]; then
869 add_dependency_tolist
$i
877 # Removes duplicate deps in the installed or not installed list.
879 find_dupdeps_inlist
()
885 [ -z "$action" ] && return 1
889 list
=$installed_deps_list
900 if [ -z "$tmp_list" ]; then
903 for i
in $tmp_list; do
904 [ "$f" = "$i" ] && dup
=yes
907 [ -z "$dup" ] && tmp_list
="$tmp_list $f"
914 installed_deps_list
="$tmp_list"
917 deps_list
="$tmp_list"
926 # Installs all dependencies required by a package.
928 install_dependency_tmpl
()
934 [ -z "$pkg" ] && return 1
938 add_dependency_tolist
$pkg
939 find_dupdeps_inlist installed
940 find_dupdeps_inlist notinstalled
942 echo "==> Required dependencies for $(basename $pkg):"
943 for i
in ${installed_deps_list}; do
944 fpkg
="$($db_cmd -O '-' btree $PKGFS_REGPKG_DB ${i%-[0-9]*.*})"
945 echo " $i: found $fpkg."
948 for i
in ${deps_list}; do
949 echo " $i: not installed."
952 for i
in ${deps_list}; do
954 echo "=> Installing dependency: $i"
955 install_tmpl
${i%-[0-9].*}
958 unset installed_deps_list
963 # Installs and stows the "xstow" package.
967 [ -x "$PKGFS_XSTOW_CMD" ] && return 0
970 run_file
"$PKGFS_TEMPLATESDIR/xstow.tmpl"
971 check_tmpl_vars
$pkgname-$version
975 PKGFS_XSTOW_CMD
="$PKGFS_DESTDIR/$pkgname-$version/bin/xstow"
976 stow_tmpl
$pkgname-$version
978 # Continue with origin package that called us.
980 run_file
$origin_tmpl
984 # Registers or unregisters a package from the db file.
986 installed_tmpl_handler
()
992 [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1
993 if [ "$action" = "register" ]; then
994 $db_cmd -w btree
$PKGFS_REGPKG_DB $pkg $version 2>&1 >/dev
/null
995 if [ "$?" -ne 0 ]; then
996 echo -n "*** ERROR: couldn't register \`$pkg'"
997 echo " in db file ***"
1000 elif [ "$action" = "unregister" ]; then
1001 $db_cmd -d btree
$PKGFS_REGPKG_DB $pkg 2>&1 >/dev
/null
1002 if [ "$?" -ne 0 ]; then
1003 echo -n "*** ERROR: \`$pkg' not registered "
1004 echo "in db file? ***"
1013 # Checks the registered pkgs db file and returns 0 if a pkg that satisfies
1014 # the minimal required version if there, or 1 otherwise.
1016 check_installed_tmpl
()
1022 [ -z "$pkg" -o -z "$reqver" ] && return 1
1024 run_file
$PKGFS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
1026 reqver
="$(echo $reqver | $sed_cmd 's|\.||g;s|[aA-zZ]||g')"
1028 $db_cmd -K btree
$PKGFS_REGPKG_DB $pkgname 2>&1 >/dev
/null
1029 if [ "$?" -eq 0 ]; then
1031 # Package is installed, let's check the version.
1033 iver
="$($db_cmd -V btree $PKGFS_REGPKG_DB $pkgname)"
1034 if [ -n "$iver" ]; then
1036 # As shell only supports decimal arith expressions,
1037 # we simply remove anything except the numbers.
1038 # It's not optimal and may fail, but it is enough
1041 iver
="$(echo $iver | $sed_cmd 's|\.||g;s|[aA-zZ]||g')"
1042 if [ "$iver" -eq "$reqver" \
1043 -o "$iver" -gt "$reqver" ]; then
1053 # Checks the build depends db file and returns 0 if pkg has dependencies,
1054 # otherwise returns 1.
1056 check_build_depends_tmpl
()
1060 [ -z $pkg ] && return 1
1061 [ ! -r $PKGFS_BUILD_DEPS_DB ] && return 1
1063 $db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev
/null
1068 # Installs a pkg by reading its build template file.
1073 cur_tmpl
="$PKGFS_TEMPLATESDIR/$1.tmpl"
1074 if [ -z "$cur_tmpl" -o ! -f "$cur_tmpl" ]; then
1075 echo -n "*** ERROR: invalid template file '$cur_tmpl',"
1076 echo " aborting ***"
1085 # If we are the originator package save the path this template in
1086 # other var for future use.
1088 if [ -z "$origin_tmpl" ]; then
1089 origin_tmpl
=$path_fixed
1093 # Install xstow if it's not there.
1098 # Check vars for current template.
1100 check_tmpl_vars
$pkg
1103 # Install dependencies required by this package.
1105 check_build_depends_tmpl
$pkg
1106 if [ "$?" -eq 0 -a -z "$doing_deps" ]; then
1107 install_dependency_tmpl
$pkg
1109 # At this point all required deps are installed, and
1110 # only remaining is the origin template; install it.
1114 run_file
$origin_tmpl
1115 check_tmpl_vars
$pkgname-$version
1118 if [ -n "$only_build" ]; then
1124 # Fetch, extract, stow and reset vars for a template.
1127 extract_tmpl_sources
1131 # Just announce that meta-template is installed and exit.
1133 if [ "$build_style" = "meta-template" ]; then
1134 installed_tmpl_handler register
$pkgname $version
1135 echo "==> Installed meta-template \`$pkg'."
1140 # Do not stow the pkg if requested.
1142 [ -z "$only_install" ] && stow_tmpl
$pkg
1146 # Lists all currently installed packages.
1150 if [ ! -r "$PKGFS_REGPKG_DB" ]; then
1151 echo "=> No packages registered or missing register db file."
1155 for i
in $
($db_cmd -K btree
$PKGFS_REGPKG_DB); do
1156 # Run file to get short_desc and print something useful
1157 run_file
${PKGFS_TEMPLATESDIR}/$i.tmpl
1158 echo "$i-$version $short_desc"
1164 # Removes a currently installed package (unstow + removed from destdir).
1170 if [ -z "$pkg" ]; then
1171 echo "*** ERROR: unexistent package, aborting ***"
1175 if [ ! -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
1176 echo "*** ERROR: cannot find template file ***"
1180 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1183 # If it's a meta-template, just unregister it from the db.
1185 if [ "$build_style" = "meta-template" ]; then
1186 installed_tmpl_handler unregister
$pkgname $version
1188 echo "=> Removed meta-template \`$pkg'."
1192 if [ ! -d "$PKGFS_DESTDIR/$pkg-$version" ]; then
1193 echo "*** ERROR: cannot find package on $PKGFS_DESTDIR ***"
1198 $rm_cmd -rf $PKGFS_DESTDIR/$pkg-$version
1205 args
=$
(getopt bCc
:efi $
*)
1206 [ "$?" -ne 0 ] && usage
1209 while [ "$#" -gt 0 ]; do
1218 config_file_specified
=yes
1219 PKGFS_CONFIG_FILE
="$2"
1239 [ "$#" -gt 2 ] && usage
1242 if [ -z "$target" ]; then
1243 echo "*** ERROR missing target ***"
1248 # Check configuration vars before anyting else, and set defaults vars.
1275 echo "*** ERROR invalid target '$target' ***"