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"
80 if [ ! -d "$val" ]; then
81 echo "**** ERROR: cannot find $i, aborting ***"
90 $progname: [-bCefi] [-c <config_file>] <target> <tmplname>
93 info Show information about <tmplname>.
94 install Build and install package from <tmplname>.
95 list Lists and prints short description about installed packages.
96 remove Remove package completely (unstow and remove from destdir)
97 stow Create symlinks from <tmplname> in master directory.
98 unstow Remove symlinks from <tmplname> in master directory.
101 -b Only build the source distribution file(s), without
102 extracting or fetching before.
103 -C Do not remove build directory after successful build.
104 -c Path to global configuration file.
105 If not specified /usr/local/etc/pkgfs.conf is used.
106 -e Only extract the source distribution file(s).
107 -f Only fetch the source distribution file(s).
108 -i Only build and install the binary distribution file(s)
109 into the destdir directory, without stowning.
125 orig
="$topdir/${orig%/}"
141 # This function merges two GNU info dirs into one and puts the result
142 # into PKGFS_MASTERDIR/share/info/dir.
147 local merge_info_cmd
="$PKGFS_MASTERDIR/bin/merge-info"
149 [ -z "$pkgname" -o ! -r "$PKGFS_MASTERDIR/share/info/dir" \
150 -o ! -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.
209 # If package needs some patches applied before building,
212 if [ -n "$patch_files" ]; then
213 for i
in ${patch_files}; do
214 patch="$PKGFS_TEMPLATESDIR/$i"
215 if [ ! -f "$patch" ]; then
216 echo "*** WARNING: unexistent patch '$i' ***"
220 $cp_cmd -f $patch $wrksrc
222 # Try to guess if its a compressed patch.
223 if $
(echo $patch|
$grep_cmd -q .gz
); then
224 $gunzip_cmd $wrksrc/$i
226 elif $
(echo $patch|
$grep_cmd -q .bz2
); then
227 $bunzip2_cmd $wrksrc/$i
229 elif $
(echo $patch|
$grep_cmd -q .
diff); then
232 echo "*** WARNING: unknown patch type '$i' ***"
236 cd $wrksrc && $patch_cmd < $patch 2>/dev
/null
237 if [ "$?" -eq 0 ]; then
238 echo "=> Patch applied: \`$i'."
240 echo -n "*** ERROR: couldn't apply patch '$i'"
241 echo ", aborting ***"
249 # Checks that all required variables specified in the configuration
250 # file are properly working.
256 if [ -z "$config_file_specified" ]; then
257 config_file_paths
="$PKGFS_CONFIG_FILE ./pkgfs.conf"
258 for f
in $config_file_paths; do
259 [ -f $f ] && PKGFS_CONFIG_FILE
=$f && \
262 if [ -z "$cffound" ]; then
263 echo -n "*** ERROR: config file not specified "
264 echo "and not in default location or current dir ***"
269 run_file
${PKGFS_CONFIG_FILE}
270 PKGFS_CONFIG_FILE
=$path_fixed
272 if [ ! -f "$PKGFS_CONFIG_FILE" ]; then
273 echo -n "*** ERROR: cannot find configuration file: "
274 echo "'$PKGFS_CONFIG_FILE' ***"
278 local PKGFS_VARS
="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
279 PKGFS_SRCDISTDIR PKGFS_SYSCONFDIR"
281 for f
in ${PKGFS_VARS}; do
283 if [ -z "$val" ]; then
284 echo -n "**** ERROR: '$f' not set in configuration "
285 echo "file, aborting ***"
289 if [ ! -d "$val" ]; then
291 if [ "$?" -ne 0 ]; then
292 echo -n "*** ERROR: couldn't create '$f'"
293 echo "directory, aborting ***"
301 # Resets all vars used by a template.
305 local TMPL_VARS
="pkgname extract_sufx distfiles url configure_args \
306 make_build_args make_install_args build_style \
307 short_desc maintainer long_desc checksum wrksrc \
308 patch_files configure_env make_cmd pkgconfig_override \
309 configure_env make_env run_stuff_before run_stuff_after \
310 run_stuff_before_configure_file run_stuff_before_build_file \
311 run_stuff_before_install_file run_stuff_after_install \
312 run_stuff_after_install_file make_build_target \
313 run_stuff_before_configure_cmd run_stuff_before_build_cmd \
314 run_stuff_before_install_cmd run_stuff_after_install_cmd \
315 make_install_target postinstall_helpers version \
318 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) ***"
414 echo "==> RMD160 checksum ok for \`$pkgname-$version'."
418 # Downloads the distfiles for a template from $url.
425 [ -z "$pkgname" ] && return 1
427 # There's nothing of interest if we are a meta template.
429 [ "$build_style" = "meta-template" ] && return 0
431 if [ -z "$distfiles" ]; then
432 file="$pkgname-$version"
438 file2
="$f$extract_sufx"
439 if [ -f "$PKGFS_SRCDISTDIR/$file2" ]; then
440 check_rmd160_cksum
$f
441 if [ "$?" -eq 0 ]; then
442 if [ -n "$only_fetch" ]; then
443 echo "=> checksum ok"
450 echo "==> Fetching \`$file2' source tarball."
452 cd $PKGFS_SRCDISTDIR && $fetch_cmd $url/$file2
453 if [ "$?" -ne 0 ]; then
454 if [ ! -f $PKGFS_SRCDISTDIR/$file2 ]; then
455 echo -n "*** ERROR: couldn't fetch '$file2', "
458 echo -n "*** ERROR: there was an error "
459 echo "fetching '$file2', aborting ***"
463 if [ -n "$only_fetch" ]; then
471 # Extracts contents of a distfile specified in a template into
472 # the build directory.
474 extract_tmpl_sources
()
476 [ -z "$pkgname" ] && return 1
479 # There's nothing of interest if we are a meta template.
481 [ "$build_style" = "meta-template" ] && return 0
483 echo "==> Extracting \`$pkgname-$version' into $PKGFS_BUILDDIR."
486 if [ "$?" -ne 0 ]; then
487 echo -n "*** ERROR: there was an error extracting the "
488 echo "distfile, aborting *** "
493 [ -n "$only_extract" ] && exit 0
498 local lt_file
="$wrksrc/libtool"
501 # If package has a libtool file replace it with ours, so that
502 # we use the master directory while relinking, all will be fine
503 # once the package is stowned.
505 if [ -f "$lt_file" -a -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
506 $rm_cmd -f $wrksrc/libtool
507 $rm_cmd -f $wrksrc/ltmain.sh
508 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
509 $ln_cmd -s $PKGFS_MASTERDIR/share
/libtool
/config
/ltmain.sh \
511 elif [ -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
512 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
518 LDFLAGS
="-L$PKGFS_MASTERDIR/lib -Wl,-R$PKGFS_MASTERDIR/lib $LDFLAGS"
519 LDFLAGS
="-L$PKGFS_DESTDIR/$pkg/lib $LDFLAGS"
520 CFLAGS
="$CFLAGS $PKGFS_CFLAGS"
521 CXXFLAGS
="$CXXFLAGS $PKGFS_CXXFLAGS"
522 CPPFLAGS
="-I$PKGFS_MASTERDIR/include $CPPFLAGS"
523 PKG_CONFIG
="$PKGFS_MASTERDIR/bin/pkg-config"
525 export LDFLAGS
="$LDFLAGS" CFLAGS
="$CFLAGS" CXXFLAGS
="$CXXFLAGS"
526 export CPPFLAGS
="$CPPFLAGS" PKG_CONFIG
="$PKG_CONFIG"
531 unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS PKG_CONFIG
535 # Configures, builds and installs a package into the destination
540 local pkg
="$pkgname-$version"
542 [ -z "$pkgname" -o -z "$version" ] && return 1
544 # There's nothing of interest if we are a meta template.
546 [ "$build_style" = "meta-template" ] && return 0
548 if [ -n "$distfiles" -a -z "$wrksrc" ]; then
549 wrksrc
=$PKGFS_BUILDDIR/$distfiles
550 elif [ -z "$wrksrc" ]; then
551 wrksrc
=$PKGFS_BUILDDIR/$pkg
553 wrksrc
=$PKGFS_BUILDDIR/$wrksrc
556 if [ ! -d "$wrksrc" ]; then
557 echo "*** ERROR: unexistent build directory: \`$wrksrc' ***"
561 export PATH
="/bin:/sbin:/usr/bin:/usr/sbin:$PKGFS_MASTERDIR/bin:$PKGFS_MASTERDIR/sbin"
563 # Apply patches if requested by template file
566 echo "==> Building \`$pkg' (be patient, may take a while)"
568 # Run stuff before configure.
569 for i
in "$run_stuff_before"; do
570 if [ "$i" = "configure" ]; then
571 [ -f $run_stuff_before_configure_file ] && \
572 .
$run_stuff_before_configure_file
573 [ -n "$run_stuff_before_configure_cmd" ] && \
574 ${run_stuff_before_configure_cmd}
578 # Export configure_env vars.
579 for f
in ${configure_env}; do
584 # Packages using GNU autoconf
586 if [ "$build_style" = "gnu_configure" ]; then
590 # Pass consistent arguments to not have unexpected
594 --prefix="$PKGFS_MASTERDIR" \
595 --mandir="$PKGFS_DESTDIR/$pkg/man" \
596 --infodir="$PKGFS_DESTDIR/$pkg/share/info" \
597 --sysconfdir="$PKGFS_SYSCONFDIR" \
601 # Packages using propietary configure scripts.
603 elif [ "$build_style" = "configure" ]; then
605 if [ -n "$configure_script" ]; then
606 .
/$configure_script ${configure_args}
608 .
/configure
${configure_args}
611 # Packages that are perl modules and use Makefile.PL files.
612 # They are all handled by the helper perl-module.sh.
614 elif [ "$build_style" = "perl_module" ]; then
615 .
$PKGFS_TMPLHELPDIR/perl-module.sh
616 perl_module_build
$pkgname
619 # Packages with BSD or GNU Makefiles are easy, just skip
620 # the configure stage and proceed.
622 elif [ "$build_style" = "bsd_makefile" -o \
623 "$build_style" = "gnu_makefile" ]; then
627 # Unknown build_style type won't work :-)
630 echo "*** ERROR unknown build_style \`$build_style' ***"
634 if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
635 echo "*** ERROR building (configure state) \`$pkg' ***"
639 # unset configure_env vars.
640 for f
in ${configure_env}; do
645 # Assume BSD make if make_cmd not set in template.
647 if [ -z "$make_cmd" ]; then
648 make_cmd
="/usr/bin/make"
651 # Fixup libtool script if necessary
655 # Run template stuff before building.
657 for i
in ${run_stuff_before}; do
658 if [ "$i" = "build" ]; then
659 [ -f $run_stuff_before_build_file ] && \
660 .
$run_stuff_before_build_file
661 [ -n "$run_stuff_before_build_cmd" ] && \
662 ${run_stuff_before_build_cmd}
666 [ -z "$make_build_target" ] && make_build_target
=
667 [ -n "$PKGFS_MAKEJOBS" ] && PKGFS_MAKEJOBS
="-j$PKGFS_MAKEJOBS"
669 # Export make_env vars.
670 for f
in ${make_env}; do
675 # Build package via make.
677 ${make_cmd} ${PKGFS_MAKEJOBS} ${make_build_args} ${make_build_target}
678 if [ "$?" -ne 0 ]; then
679 echo "*** ERROR building (make stage) \`$pkg' ***"
684 # Run template stuff before installing.
686 for i
in ${run_stuff_before}; do
687 if [ "$i" = "install" ]; then
688 [ -f $run_stuff_before_install_file ] && \
689 .
$run_stuff_before_install_file
690 [ -n "$run_stuff_before_install_cmd" ] && \
691 ${run_stuff_before_install_cmd}
695 [ -z "$make_install_target" ] && make_install_target
=install
698 # Install package via make.
700 ${make_cmd} ${make_install_args} ${make_install_target} \
701 prefix
="$PKGFS_DESTDIR/$pkg"
702 if [ "$?" -ne 0 ]; then
703 echo "*** ERROR instaling \`$pkg' ***"
707 # Unset make_env vars.
708 for f
in ${make_env}; do
713 # Run template stuff after installing.
715 for i
in ${run_stuff_after}; do
716 if [ "$i" = "install" ]; then
717 [ -f $run_stuff_after_install_file ] && \
718 .
$run_stuff_after_install_file
719 [ -n "$run_stuff_after_install_cmd" ] && \
720 ${run_stuff_after_install_cmd}
725 # Transform pkg-config files if requested by template.
727 for i
in ${pkgconfig_override}; do
728 local tmpf
="$PKGFS_DESTDIR/$pkg/lib/pkgconfig/$i"
730 [ -f $PKGFS_TMPLHELPDIR/pkg-config-transform.sh
] && \
731 .
$PKGFS_TMPLHELPDIR/pkg-config-transform.sh
&& \
732 pkgconfig_transform_file
$tmpf
738 echo "==> Installed \`$pkg' into $PKGFS_DESTDIR."
741 # Remove $wrksrc if -C not specified.
743 if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
746 echo "=> Removed \`$pkg' build directory."
753 # Stows a currently installed package, i.e creates the links
754 # on the master directory.
759 local infodir_pkg
="share/info/dir"
760 local infodir_master
="$PKGFS_MASTERDIR/share/info/dir"
761 local real_xstowargs
="$xstow_args"
762 local real_xstow_ignore
="$xstow_ignore_files"
764 [ -z "$pkg" ] && return 2
766 if [ -n "$stow_flag" ]; then
767 pkg
=$PKGFS_TEMPLATESDIR/$pkg.tmpl
769 pkg
=$pkgname-$version
771 # You cannot stow a meta-template.
773 [ "$build_style" = "meta-template" ] && return 0
776 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" ]; then
777 merge_infodir_tmpl
$pkg
780 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" \
781 -a -r "$infodir_master" ]; then
782 xstow_args
="$xstow_args -i-file-in-dir $infodir_pkg"
785 if [ -n "$ignore_files" ]; then
786 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
789 $PKGFS_XSTOW_CMD -ignore "${xstow_ignore_files}" ${xstow_args} \
790 -pd-targets $PKGFS_MASTERDIR \
791 -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
793 if [ "$?" -ne 0 ]; then
794 echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
797 echo "==> Created \`$pkg' symlinks into master directory."
800 installed_tmpl_handler register
$pkgname $version
803 # Run template postinstall helpers if requested.
805 if [ "$pkgname" != "${pkg%%-$version}" ]; then
806 run_file
$PKGFS_TEMPLATESDIR/${pkg%%-$version}.tmpl
809 for i
in ${postinstall_helpers}; do
810 local pihf
="$PKGFS_TMPLHELPDIR/$i"
811 [ -f "$pihf" ] && .
$pihf
814 xstow_ignore_files
="$real_xstow_ignore"
815 xstow_args
="$real_xstowargs"
819 # Unstows a currently stowned package, i.e removes its links
820 # from the master directory.
825 local real_xstow_ignore
="$xstow_ignore_files"
827 if [ -z "$pkg" ]; then
828 echo "*** ERROR: template wasn't specified? ***"
832 if [ "$pkg" = "xstow" ]; then
833 echo "*** INFO: You aren't allowed to unstow \`$pkg'."
837 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
840 # You cannot unstow a meta-template.
842 [ "$build_style" = "meta-template" ] && return 0
844 if [ -n "$ignore_files" ]; then
845 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
848 $PKGFS_XSTOW_CMD -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
849 -D -i-file-in-dir share
/info
/dir
-ignore \
850 "${xstow_ignore_files}" $PKGFS_DESTDIR/$pkgname-$version
851 if [ "$?" -ne 0 ]; then
854 $rm_cmd -f $PKGFS_DESTDIR/$pkgname-$version/share
/info
/dir
855 echo "==> Removed \`$pkg' symlinks from master directory."
858 installed_tmpl_handler unregister
$pkgname $version
860 xstow_ignore_files
="$real_xstow_ignore"
864 # Recursive function that founds dependencies in all required
867 add_dependency_tolist
()
871 [ -z "$curpkg" ] && return 1
872 [ -n "$prev_pkg" ] && curpkg
=$prev_pkg
874 for i
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do
876 # Check if dep already installed.
878 if [ -r "$PKGFS_REGPKG_DB" ]; then
879 check_installed_tmpl
$i ${i##[aA-zZ]*-}
881 # If dep is already installed, put it on the
882 # installed deps list and continue.
884 if [ "$?" -eq 0 ]; then
885 installed_deps_list
="$i $installed_deps_list"
889 deps_list
="$i $deps_list"
890 [ -n "$prev_pkg" ] && unset prev_pkg
892 # Check if dependency needs more deps.
894 check_build_depends_tmpl
${i%-[0-9]*.*}
895 if [ "$?" -eq 0 ]; then
896 add_dependency_tolist
$i
904 # Removes duplicate deps in the installed or not installed list.
906 find_dupdeps_inlist
()
912 [ -z "$action" ] && return 1
916 list
=$installed_deps_list
927 if [ -z "$tmp_list" ]; then
930 for i
in $tmp_list; do
931 [ "$f" = "$i" ] && dup
=yes
934 [ -z "$dup" ] && tmp_list
="$tmp_list $f"
941 installed_deps_list
="$tmp_list"
944 deps_list
="$tmp_list"
953 # Installs all dependencies required by a package.
955 install_dependency_tmpl
()
961 [ -z "$pkg" ] && return 1
965 add_dependency_tolist
$pkg
966 find_dupdeps_inlist installed
967 find_dupdeps_inlist notinstalled
969 echo "==> Required dependencies for $(basename $pkg):"
970 for i
in ${installed_deps_list}; do
971 fpkg
="$($db_cmd -O '-' btree $PKGFS_REGPKG_DB ${i%-[0-9]*.*})"
972 echo " $i: found $fpkg."
975 for i
in ${deps_list}; do
976 echo " $i: not installed."
979 for i
in ${deps_list}; do
981 echo "=> Installing dependency: $i"
982 install_tmpl
${i%-[0-9]*.*}
985 unset installed_deps_list
990 # Installs and stows the "xstow" package.
994 [ -x "$PKGFS_XSTOW_CMD" ] && return 0
997 run_file
"$PKGFS_TEMPLATESDIR/xstow.tmpl"
998 check_tmpl_vars
$pkgname-$version
1000 extract_tmpl_sources
1002 PKGFS_XSTOW_CMD
="$PKGFS_DESTDIR/$pkgname-$version/bin/xstow"
1003 stow_tmpl
$pkgname-$version
1005 # Continue with origin package that called us.
1007 run_file
$origin_tmpl
1011 # Registers or unregisters a package from the db file.
1013 installed_tmpl_handler
()
1019 [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1
1021 if [ "$action" = "register" ]; then
1022 $db_cmd -w btree
$PKGFS_REGPKG_DB $pkg $version 2>&1 >/dev
/null
1023 if [ "$?" -ne 0 ]; then
1024 echo -n "*** ERROR: couldn't register \`$pkg'"
1025 echo " in db file ***"
1028 elif [ "$action" = "unregister" ]; then
1029 $db_cmd -d btree
$PKGFS_REGPKG_DB $pkg 2>&1 >/dev
/null
1030 if [ "$?" -ne 0 ]; then
1031 echo -n "*** ERROR: \`$pkg' not registered "
1032 echo "in db file? ***"
1041 # Checks the registered pkgs db file and returns 0 if a pkg that satisfies
1042 # the minimal required version is there, or 1 otherwise.
1044 check_installed_tmpl
()
1050 [ -z "$pkg" -o -z "$reqver" ] && return 1
1052 run_file
$PKGFS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
1054 reqver
="$(echo $reqver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1056 $db_cmd -K btree
$PKGFS_REGPKG_DB $pkgname 2>&1 >/dev
/null
1057 if [ "$?" -eq 0 ]; then
1059 # Package is installed, let's check the version.
1061 iver
="$($db_cmd -V btree $PKGFS_REGPKG_DB $pkgname)"
1062 if [ -n "$iver" ]; then
1064 # As shell only supports decimal arith expressions,
1065 # we simply remove anything except the numbers.
1066 # It's not optimal and may fail, but it is enough
1069 iver
="$(echo $iver | $sed_cmd 's|[[:punct:]]||g;s|[[:alpha:]]||g')"
1070 if [ "$iver" -eq "$reqver" \
1071 -o "$iver" -gt "$reqver" ]; then
1081 # Checks the build depends db file and returns 0 if pkg has dependencies,
1082 # otherwise returns 1.
1084 check_build_depends_tmpl
()
1088 [ -z $pkg -o ! -r $PKGFS_BUILD_DEPS_DB ] && return 1
1090 $db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev
/null
1095 # Installs a pkg by reading its build template file.
1100 cur_tmpl
="$PKGFS_TEMPLATESDIR/$1.tmpl"
1101 if [ -z "$cur_tmpl" -o ! -f "$cur_tmpl" ]; then
1102 echo -n "*** ERROR: invalid template file '$cur_tmpl',"
1103 echo " aborting ***"
1112 # If we are the originator package save the path this template in
1113 # other var for future use.
1115 if [ -z "$origin_tmpl" ]; then
1116 origin_tmpl
=$path_fixed
1120 # Install xstow if it's not there.
1125 # Check vars for current template.
1127 check_tmpl_vars
$pkg
1130 # Install dependencies required by this package.
1132 check_build_depends_tmpl
$pkg
1133 if [ "$?" -eq 0 -a -z "$doing_deps" ]; then
1134 install_dependency_tmpl
$pkg
1136 # At this point all required deps are installed, and
1137 # only remaining is the origin template; install it.
1141 run_file
$origin_tmpl
1142 check_tmpl_vars
$pkgname-$version
1145 if [ -n "$only_build" ]; then
1151 # Fetch, extract, stow and reset vars for a template.
1154 extract_tmpl_sources
1158 # Just announce that meta-template is installed and exit.
1160 if [ "$build_style" = "meta-template" ]; then
1161 installed_tmpl_handler register
$pkgname $version
1162 echo "==> Installed meta-template \`$pkg'."
1167 # Do not stow the pkg if requested.
1169 [ -z "$only_install" ] && stow_tmpl
$pkg
1173 # Lists all currently installed packages.
1177 if [ ! -r "$PKGFS_REGPKG_DB" ]; then
1178 echo "=> No packages registered or missing register db file."
1182 for i
in $
($db_cmd -K btree
$PKGFS_REGPKG_DB); do
1183 # Run file to get short_desc and print something useful
1184 run_file
${PKGFS_TEMPLATESDIR}/$i.tmpl
1185 echo "$i-$version $short_desc"
1191 # Removes a currently installed package (unstow + removed from destdir).
1197 if [ -z "$pkg" ]; then
1198 echo "*** ERROR: unexistent package, aborting ***"
1202 if [ ! -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
1203 echo "*** ERROR: cannot find template file ***"
1207 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1210 # If it's a meta-template, just unregister it from the db.
1212 if [ "$build_style" = "meta-template" ]; then
1213 installed_tmpl_handler unregister
$pkgname $version
1215 echo "=> Removed meta-template \`$pkg'."
1219 if [ ! -d "$PKGFS_DESTDIR/$pkg-$version" ]; then
1220 echo "*** ERROR: cannot find package on $PKGFS_DESTDIR ***"
1225 $rm_cmd -rf $PKGFS_DESTDIR/$pkg-$version
1232 args
=$
(getopt bCc
:efi $
*)
1233 [ "$?" -ne 0 ] && usage
1236 while [ "$#" -gt 0 ]; do
1245 config_file_specified
=yes
1246 PKGFS_CONFIG_FILE
="$2"
1266 [ "$#" -gt 2 ] && usage
1269 if [ -z "$target" ]; then
1270 echo "*** ERROR missing target ***"
1275 # Check configuration vars before anyting else, and set defaults vars.
1302 echo "*** ERROR invalid target \`$target' ***"