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" ] && return 1
150 [ ! -r "$PKGFS_MASTERDIR/share/info/dir" ] && return 1
151 [ ! -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.
172 if [ -z "$tmpl" -o ! -f "$PKGFS_TEMPLATESDIR/$tmpl.tmpl" ]; then
173 echo -n "*** ERROR: invalid template file \`$tmpl' ***"
174 echo ", aborting ***"
178 run_file
$PKGFS_TEMPLATESDIR/$tmpl.tmpl
180 echo "pkgname: $pkgname"
181 echo "version: $version"
182 for i
in "${distfiles}"; do
183 [ -n "$i" ] && echo "distfile: $i"
186 echo "maintainer: $maintainer"
187 [ -n $checksum ] && echo "checksum: $checksum"
188 echo "build_style: $build_style"
189 echo "short_desc: $short_desc"
192 check_build_depends_tmpl
$pkgname-$version
193 if [ "$?" -eq 0 ]; then
194 local list
="$($db_cmd -V btree $PKGFS_BUILD_DEPS_DB $pkgname)"
195 echo "This package requires the following dependencies to be built:"
203 # Applies to the build directory the patches specified by a template.
210 # If package needs some patches applied before building,
213 if [ -n "$patch_files" ]; then
214 for i
in ${patch_files}; do
215 patch="$PKGFS_TEMPLATESDIR/$i"
216 if [ ! -f "$patch" ]; then
217 echo "*** WARNING: unexistent patch '$i' ***"
221 $cp_cmd -f $patch $wrksrc
223 # Try to guess if its a compressed patch.
224 if $
(echo $patch|
$grep_cmd -q .gz
); then
225 $gunzip_cmd $wrksrc/$i
227 elif $
(echo $patch|
$grep_cmd -q .bz2
); then
228 $bunzip2_cmd $wrksrc/$i
230 elif $
(echo $patch|
$grep_cmd -q .
diff); then
233 echo "*** WARNING: unknown patch type '$i' ***"
237 cd $wrksrc && $patch_cmd < $patch 2>/dev
/null
238 if [ "$?" -eq 0 ]; then
239 echo "=> Patch applied: \`$i'."
241 echo -n "*** ERROR: couldn't apply patch '$i'"
242 echo ", aborting ***"
250 # Checks that all required variables specified in the configuration
251 # file are properly working.
257 if [ -z "$config_file_specified" ]; then
258 config_file_paths
="$PKGFS_CONFIG_FILE ./pkgfs.conf"
259 for f
in $config_file_paths; do
260 [ -f $f ] && PKGFS_CONFIG_FILE
=$f && \
263 if [ -z "$cffound" ]; then
264 echo -n "*** ERROR: config file not specified "
265 echo "and not in default location or current dir ***"
270 run_file
${PKGFS_CONFIG_FILE}
271 PKGFS_CONFIG_FILE
=$path_fixed
273 if [ ! -f "$PKGFS_CONFIG_FILE" ]; then
274 echo -n "*** ERROR: cannot find configuration file: "
275 echo "'$PKGFS_CONFIG_FILE' ***"
279 local PKGFS_VARS
="PKGFS_MASTERDIR PKGFS_DESTDIR PKGFS_BUILDDIR \
280 PKGFS_SRCDISTDIR PKGFS_SYSCONFDIR"
282 for f
in ${PKGFS_VARS}; do
284 if [ -z "$val" ]; then
285 echo -n "**** ERROR: '$f' not set in configuration "
286 echo "file, aborting ***"
290 if [ ! -d "$val" ]; then
292 if [ "$?" -ne 0 ]; then
293 echo -n "*** ERROR: couldn't create '$f'"
294 echo "directory, aborting ***"
302 # Resets all vars used by a template.
306 local TMPL_VARS
="pkgname extract_sufx distfiles url configure_args \
307 make_build_args make_install_args build_style \
308 short_desc maintainer long_desc checksum wrksrc \
309 patch_files configure_env make_cmd pkgconfig_override \
310 configure_env make_env run_stuff_before run_stuff_after \
311 run_stuff_before_configure_file run_stuff_before_build_file \
312 run_stuff_before_install_file run_stuff_after_install \
313 run_stuff_after_install_file make_build_target \
314 run_stuff_before_configure_cmd run_stuff_before_build_cmd \
315 run_stuff_before_install_cmd run_stuff_after_install_cmd \
316 make_install_target postinstall_helpers version \
319 for i
in ${TMPL_VARS}; do
325 # Checks some vars used in templates and sets $extract_cmd.
332 [ -z "$pkg" ] && return 1
334 # There's nothing of interest if we are a meta template.
336 [ "$build_style" = "meta-template" ] && return 0
338 REQ_VARS
="pkgname version extract_sufx url build_style"
340 # Check if required vars weren't set.
341 for i
in ${REQ_VARS}; do
343 if [ -z "$val" -o -z "$i" ]; then
344 echo -n "*** ERROR: $i not set (incomplete template"
345 echo " build file), aborting ***"
350 if [ -z "$distfiles" ]; then
351 dfile
="$pkgname-$version$extract_sufx"
352 elif [ -n "${distfiles}" ]; then
353 dfile
="$distfiles$extract_sufx"
355 echo "*** ERROR unsupported fetch state ***"
359 dfile
="$PKGFS_SRCDISTDIR/$dfile"
361 case "$extract_sufx" in
362 .
tar.bz2|.
tar.gz|.tgz|.tbz
)
363 extract_cmd
="$tar_cmd xfz $dfile -C $PKGFS_BUILDDIR"
366 extract_cmd
="$tar_cmd xf $dfile -C $PKGFS_BUILDDIR"
369 if [ -f "$PKGFS_TMPLHELPDIR/unzip-extraction.sh" ]; then
370 .
$PKGFS_TMPLHELPDIR/unzip-extraction.sh
372 # $extract_cmd set by the helper
375 echo -n "*** ERROR: unknown 'extract_sufx' argument in build "
383 # Verifies that a checksum of a distfile is correct.
390 [ -z "$file" ] && return 1
392 if [ -z "${distfiles}" ]; then
393 dfile
="$pkgname-$version$extract_sufx"
394 elif [ -n "${distfiles}" ]; then
395 dfile
="$distfiles$extract_sufx"
397 dfile
="$file$extract_sufx"
400 if [ -z "$checksum" ]; then
401 echo "*** ERROR: checksum unset in template file for \`$pkgname' ***"
406 dfile
="$PKGFS_SRCDISTDIR/$dfile"
407 filesum
="$($cksum_cmd $dfile | $awk_cmd '{print $4}')"
408 if [ "$origsum" != "$filesum" ]; then
409 echo "*** WARNING: checksum doesn't match (rmd160) ***"
413 echo "==> RMD160 checksum ok for \`$pkgname-$version'."
417 # Downloads the distfiles for a template from $url.
424 [ -z "$pkgname" ] && return 1
426 # There's nothing of interest if we are a meta template.
428 [ "$build_style" = "meta-template" ] && return 0
430 if [ -z "$distfiles" ]; then
431 file="$pkgname-$version"
437 file2
="$f$extract_sufx"
438 if [ -f "$PKGFS_SRCDISTDIR/$file2" ]; then
439 check_rmd160_cksum
$f
440 if [ "$?" -eq 0 ]; then
441 if [ -n "$only_fetch" ]; then
442 echo "=> checksum ok"
449 echo "==> Fetching \`$file2' source tarball."
451 cd $PKGFS_SRCDISTDIR && $fetch_cmd $url/$file2
452 if [ "$?" -ne 0 ]; then
453 if [ ! -f $PKGFS_SRCDISTDIR/$file2 ]; then
454 echo -n "*** ERROR: couldn't fetch '$file2', "
457 echo -n "*** ERROR: there was an error "
458 echo "fetching '$file2', aborting ***"
462 if [ -n "$only_fetch" ]; then
470 # Extracts contents of a distfile specified in a template into
471 # the build directory.
473 extract_tmpl_sources
()
475 [ -z "$pkgname" ] && return 1
478 # There's nothing of interest if we are a meta template.
480 [ "$build_style" = "meta-template" ] && return 0
482 echo "==> Extracting \`$pkgname-$version' into $PKGFS_BUILDDIR."
485 if [ "$?" -ne 0 ]; then
486 echo -n "*** ERROR: there was an error extracting the "
487 echo "distfile, aborting *** "
492 [ -n "$only_extract" ] && exit 0
497 local lt_file
="$wrksrc/libtool"
500 # If package has a libtool file replace it with ours, so that
501 # we use the master directory while relinking, all will be fine
502 # once the package is stowned.
504 if [ -f "$lt_file" -a -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
505 $rm_cmd -f $wrksrc/libtool
506 $rm_cmd -f $wrksrc/ltmain.sh
507 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
508 $ln_cmd -s $PKGFS_MASTERDIR/share
/libtool
/config
/ltmain.sh \
510 elif [ -f "$PKGFS_MASTERDIR/bin/libtool" ]; then
511 $ln_cmd -s $PKGFS_MASTERDIR/bin
/libtool
$lt_file
517 LDFLAGS
="-L$PKGFS_MASTERDIR/lib -Wl,-R$PKGFS_MASTERDIR/lib $LDFLAGS"
518 LDFLAGS
="-L$PKGFS_DESTDIR/$pkg/lib $LDFLAGS"
519 CFLAGS
="$CFLAGS $PKGFS_CFLAGS"
520 CXXFLAGS
="$CXXFLAGS $PKGFS_CXXFLAGS"
521 CPPFLAGS
="-I$PKGFS_MASTERDIR/include $CPPFLAGS"
522 PKG_CONFIG
="$PKGFS_MASTERDIR/bin/pkg-config"
524 export LDFLAGS
="$LDFLAGS" CFLAGS
="$CFLAGS" CXXFLAGS
="$CXXFLAGS"
525 export CPPFLAGS
="$CPPFLAGS" PKG_CONFIG
="$PKG_CONFIG"
530 unset LDFLAGS CFLAGS CXXFLAGS CPPFLAGS PKG_CONFIG
534 # Configures, builds and installs a package into the destination
539 local pkg
="$pkgname-$version"
541 [ -z "$pkgname" -o -z "$version" ] && return 1
543 # There's nothing of interest if we are a meta template.
545 [ "$build_style" = "meta-template" ] && return 0
547 if [ -n "$distfiles" -a -z "$wrksrc" ]; then
548 wrksrc
=$PKGFS_BUILDDIR/$distfiles
549 elif [ -z "$wrksrc" ]; then
550 wrksrc
=$PKGFS_BUILDDIR/$pkg
552 wrksrc
=$PKGFS_BUILDDIR/$wrksrc
555 if [ ! -d "$wrksrc" ]; then
556 echo "*** ERROR: unexistent build directory, aborting ***"
560 export PATH
="/bin:/sbin:/usr/bin:/usr/sbin:$PKGFS_MASTERDIR/bin:$PKGFS_MASTERDIR/sbin"
562 # Apply patches if requested by template file
565 echo "==> Building \`$pkg' (be patient, may take a while)"
567 # Run stuff before configure.
568 for i
in "$run_stuff_before"; do
569 if [ "$i" = "configure" ]; then
570 [ -f $run_stuff_before_configure_file ] && \
571 .
$run_stuff_before_configure_file
572 [ -n "$run_stuff_before_configure_cmd" ] && \
573 ${run_stuff_before_configure_cmd}
577 # Export configure_env vars.
578 for f
in ${configure_env}; do
583 # Packages using GNU autoconf
585 if [ "$build_style" = "gnu_configure" ]; then
589 # Pass consistent arguments to not have unexpected
593 --prefix="$PKGFS_MASTERDIR" \
594 --mandir="$PKGFS_DESTDIR/$pkg/man" \
595 --infodir="$PKGFS_DESTDIR/$pkg/share/info" \
596 --sysconfdir="$PKGFS_SYSCONFDIR" \
600 # Packages using propietary configure scripts.
602 elif [ "$build_style" = "configure" ]; then
604 if [ -n "$configure_script" ]; then
605 .
/$configure_script ${configure_args}
607 .
/configure
${configure_args}
610 # Packages that are perl modules and use Makefile.PL files.
611 # They are all handled by the helper perl-module.sh.
613 elif [ "$build_style" = "perl_module" ]; then
614 .
$PKGFS_TMPLHELPDIR/perl-module.sh
615 perl_module_build
$pkgname
618 # Packages with BSD or GNU Makefiles are easy, just skip
619 # the configure stage and proceed.
621 elif [ "$build_style" = "bsd_makefile" -o \
622 "$build_style" = "gnu_makefile" ]; then
626 # Unknown build_style type won't work :-)
629 echo "*** ERROR unknown build_style $build_style, aborting ***"
633 if [ "$build_style" != "perl_module" -a "$?" -ne 0 ]; then
634 echo "*** ERROR building (configure state) \`$pkg' ***"
638 # unset configure_env vars.
639 for f
in ${configure_env}; do
644 # Assume BSD make if make_cmd not set in template.
646 if [ -z "$make_cmd" ]; then
647 make_cmd
="/usr/bin/make"
650 # Fixup libtool script if necessary
654 # Run template stuff before building.
656 for i
in ${run_stuff_before}; do
657 if [ "$i" = "build" ]; then
658 [ -f $run_stuff_before_build_file ] && \
659 .
$run_stuff_before_build_file
660 [ -n "$run_stuff_before_build_cmd" ] && \
661 ${run_stuff_before_build_cmd}
665 [ -z "$make_build_target" ] && make_build_target
=
666 [ -n "$PKGFS_MAKEJOBS" ] && PKGFS_MAKEJOBS
="-j$PKGFS_MAKEJOBS"
668 # Export make_env vars.
669 for f
in ${make_env}; do
674 # Build package via make.
676 ${make_cmd} ${PKGFS_MAKEJOBS} ${make_build_args} ${make_build_target}
677 if [ "$?" -ne 0 ]; then
678 echo "*** ERROR building (make stage) \`$pkg' ***"
683 # Run template stuff before installing.
685 for i
in ${run_stuff_before}; do
686 if [ "$i" = "install" ]; then
687 [ -f $run_stuff_before_install_file ] && \
688 .
$run_stuff_before_install_file
689 [ -n "$run_stuff_before_install_cmd" ] && \
690 ${run_stuff_before_install_cmd}
694 [ -z "$make_install_target" ] && make_install_target
=install
697 # Install package via make.
699 ${make_cmd} ${make_install_args} ${make_install_target} \
700 prefix
="$PKGFS_DESTDIR/$pkg"
701 if [ "$?" -ne 0 ]; then
702 echo "*** ERROR instaling \`$pkg' ***"
706 # Unset make_env vars.
707 for f
in ${make_env}; do
712 # Run template stuff after installing.
714 for i
in ${run_stuff_after}; do
715 if [ "$i" = "install" ]; then
716 [ -f $run_stuff_after_install_file ] && \
717 .
$run_stuff_after_install_file
718 [ -n "$run_stuff_after_install_cmd" ] && \
719 ${run_stuff_after_install_cmd}
724 # Transform pkg-config files if requested by template.
726 for i
in ${pkgconfig_override}; do
727 local tmpf
="$PKGFS_DESTDIR/$pkg/lib/pkgconfig/$i"
729 [ -f $PKGFS_TMPLHELPDIR/pkg-config-transform.sh
] && \
730 .
$PKGFS_TMPLHELPDIR/pkg-config-transform.sh
&& \
731 pkgconfig_transform_file
$tmpf
737 echo "==> Installed \`$pkg' into $PKGFS_DESTDIR/$pkg."
740 # Remove $wrksrc if -C not specified.
742 if [ -d "$wrksrc" -a -z "$dontrm_builddir" ]; then
745 echo "=> Removed \`$pkg' build directory."
752 # Stows a currently installed package, i.e creates the links
753 # on the master directory.
758 local infodir_pkg
="share/info/dir"
759 local infodir_master
="$PKGFS_MASTERDIR/share/info/dir"
760 local real_xstowargs
="$xstow_args"
761 local real_xstow_ignore
="$xstow_ignore_files"
763 [ -z "$pkg" ] && return 2
765 if [ -n "$stow_flag" ]; then
766 pkg
=$PKGFS_TEMPLATESDIR/$pkg.tmpl
768 pkg
=$pkgname-$version
770 # You cannot stow a meta-template.
772 [ "$build_style" = "meta-template" ] && return 0
775 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" ]; then
776 merge_infodir_tmpl
$pkg
779 if [ -r "$PKGFS_DESTDIR/$pkg/$infodir_pkg" \
780 -a -r "$infodir_master" ]; then
781 xstow_args
="$xstow_args -i-file-in-dir $infodir_pkg"
784 if [ -n "$ignore_files" ]; then
785 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
788 $PKGFS_XSTOW_CMD -ignore "${xstow_ignore_files}" ${xstow_args} \
789 -pd-targets $PKGFS_MASTERDIR \
790 -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
792 if [ "$?" -ne 0 ]; then
793 echo "*** ERROR: couldn't create symlinks for \`$pkg' ***"
796 echo "==> Created \`$pkg' symlinks into master directory."
799 installed_tmpl_handler register
$pkgname $version
802 # Run template postinstall helpers if requested.
804 if [ "$pkgname" != "${pkg%%-$version}" ]; then
805 run_file
$PKGFS_TEMPLATESDIR/${pkg%%-$version}.tmpl
808 for i
in ${postinstall_helpers}; do
809 local pihf
="$PKGFS_TMPLHELPDIR/$i"
810 [ -f "$pihf" ] && .
$pihf
813 xstow_ignore_files
="$real_xstow_ignore"
814 xstow_args
="$real_xstowargs"
818 # Unstows a currently stowned package, i.e removes its links
819 # from the master directory.
824 local real_xstow_ignore
="$xstow_ignore_files"
826 if [ -z "$pkg" ]; then
827 echo "*** ERROR: template wasn't specified? ***"
831 if [ "$pkg" = "xstow" ]; then
832 echo "*** INFO: You aren't allowed to unstow \`$pkg'."
836 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
839 # You cannot unstow a meta-template.
841 [ "$build_style" = "meta-template" ] && return 0
843 if [ -n "$ignore_files" ]; then
844 xstow_ignore_files
="$xstow_ignore_files $ignore_files"
847 $PKGFS_XSTOW_CMD -dir $PKGFS_DESTDIR -target $PKGFS_MASTERDIR \
848 -D -i-file-in-dir share
/info
/dir
-ignore \
849 "${xstow_ignore_files}" $PKGFS_DESTDIR/$pkgname-$version
850 if [ "$?" -ne 0 ]; then
853 $rm_cmd -f $PKGFS_DESTDIR/$pkgname-$version/share
/info
/dir
854 echo "==> Removed \`$pkg' symlinks from master directory."
857 installed_tmpl_handler unregister
$pkgname $version
859 xstow_ignore_files
="$real_xstow_ignore"
863 # Recursive function that founds dependencies in all required
866 add_dependency_tolist
()
870 [ -z "$curpkg" ] && return 1
871 [ -n "$prev_pkg" ] && curpkg
=$prev_pkg
873 for i
in $
($db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${curpkg%-[0-9]*.*}); do
875 # Check if dep already installed.
877 if [ -r "$PKGFS_REGPKG_DB" ]; then
878 check_installed_tmpl
$i ${i##[aA-zZ]*-}
880 # If dep is already installed, put it on the
881 # installed deps list and continue.
883 if [ "$?" -eq 0 ]; then
884 installed_deps_list
="$i $installed_deps_list"
888 deps_list
="$i $deps_list"
889 [ -n "$prev_pkg" ] && unset prev_pkg
891 # Check if dependency needs more deps.
893 check_build_depends_tmpl
${i%-[0-9]*.*}
894 if [ "$?" -eq 0 ]; then
895 add_dependency_tolist
$i
903 # Removes duplicate deps in the installed or not installed list.
905 find_dupdeps_inlist
()
911 [ -z "$action" ] && return 1
915 list
=$installed_deps_list
926 if [ -z "$tmp_list" ]; then
929 for i
in $tmp_list; do
930 [ "$f" = "$i" ] && dup
=yes
933 [ -z "$dup" ] && tmp_list
="$tmp_list $f"
940 installed_deps_list
="$tmp_list"
943 deps_list
="$tmp_list"
952 # Installs all dependencies required by a package.
954 install_dependency_tmpl
()
960 [ -z "$pkg" ] && return 1
964 add_dependency_tolist
$pkg
965 find_dupdeps_inlist installed
966 find_dupdeps_inlist notinstalled
968 echo "==> Required dependencies for $(basename $pkg):"
969 for i
in ${installed_deps_list}; do
970 fpkg
="$($db_cmd -O '-' btree $PKGFS_REGPKG_DB ${i%-[0-9]*.*})"
971 echo " $i: found $fpkg."
974 for i
in ${deps_list}; do
975 echo " $i: not installed."
978 for i
in ${deps_list}; do
980 echo "=> Installing dependency: $i"
981 install_tmpl
${i%-[0-9].*}
984 unset installed_deps_list
989 # Installs and stows the "xstow" package.
993 [ -x "$PKGFS_XSTOW_CMD" ] && return 0
996 run_file
"$PKGFS_TEMPLATESDIR/xstow.tmpl"
997 check_tmpl_vars
$pkgname-$version
1001 PKGFS_XSTOW_CMD
="$PKGFS_DESTDIR/$pkgname-$version/bin/xstow"
1002 stow_tmpl
$pkgname-$version
1004 # Continue with origin package that called us.
1006 run_file
$origin_tmpl
1010 # Registers or unregisters a package from the db file.
1012 installed_tmpl_handler
()
1018 [ -z "$action" -o -z "$pkg" -o -z "$version" ] && return 1
1019 if [ "$action" = "register" ]; then
1020 $db_cmd -w btree
$PKGFS_REGPKG_DB $pkg $version 2>&1 >/dev
/null
1021 if [ "$?" -ne 0 ]; then
1022 echo -n "*** ERROR: couldn't register \`$pkg'"
1023 echo " in db file ***"
1026 elif [ "$action" = "unregister" ]; then
1027 $db_cmd -d btree
$PKGFS_REGPKG_DB $pkg 2>&1 >/dev
/null
1028 if [ "$?" -ne 0 ]; then
1029 echo -n "*** ERROR: \`$pkg' not registered "
1030 echo "in db file? ***"
1039 # Checks the registered pkgs db file and returns 0 if a pkg that satisfies
1040 # the minimal required version if there, or 1 otherwise.
1042 check_installed_tmpl
()
1048 [ -z "$pkg" -o -z "$reqver" ] && return 1
1050 run_file
$PKGFS_TEMPLATESDIR/${pkg%-[0-9]*.*}.tmpl
1052 reqver
="$(echo $reqver | $sed_cmd 's|\.||g;s|[aA-zZ]||g')"
1054 $db_cmd -K btree
$PKGFS_REGPKG_DB $pkgname 2>&1 >/dev
/null
1055 if [ "$?" -eq 0 ]; then
1057 # Package is installed, let's check the version.
1059 iver
="$($db_cmd -V btree $PKGFS_REGPKG_DB $pkgname)"
1060 if [ -n "$iver" ]; then
1062 # As shell only supports decimal arith expressions,
1063 # we simply remove anything except the numbers.
1064 # It's not optimal and may fail, but it is enough
1067 iver
="$(echo $iver | $sed_cmd 's|\.||g;s|[aA-zZ]||g')"
1068 if [ "$iver" -eq "$reqver" \
1069 -o "$iver" -gt "$reqver" ]; then
1079 # Checks the build depends db file and returns 0 if pkg has dependencies,
1080 # otherwise returns 1.
1082 check_build_depends_tmpl
()
1086 [ -z $pkg ] && return 1
1087 [ ! -r $PKGFS_BUILD_DEPS_DB ] && return 1
1089 $db_cmd -V btree
$PKGFS_BUILD_DEPS_DB ${pkg%-[0-9]*.*} 2>&1 >/dev
/null
1094 # Installs a pkg by reading its build template file.
1099 cur_tmpl
="$PKGFS_TEMPLATESDIR/$1.tmpl"
1100 if [ -z "$cur_tmpl" -o ! -f "$cur_tmpl" ]; then
1101 echo -n "*** ERROR: invalid template file '$cur_tmpl',"
1102 echo " aborting ***"
1111 # If we are the originator package save the path this template in
1112 # other var for future use.
1114 if [ -z "$origin_tmpl" ]; then
1115 origin_tmpl
=$path_fixed
1119 # Install xstow if it's not there.
1124 # Check vars for current template.
1126 check_tmpl_vars
$pkg
1129 # Install dependencies required by this package.
1131 check_build_depends_tmpl
$pkg
1132 if [ "$?" -eq 0 -a -z "$doing_deps" ]; then
1133 install_dependency_tmpl
$pkg
1135 # At this point all required deps are installed, and
1136 # only remaining is the origin template; install it.
1140 run_file
$origin_tmpl
1141 check_tmpl_vars
$pkgname-$version
1144 if [ -n "$only_build" ]; then
1150 # Fetch, extract, stow and reset vars for a template.
1153 extract_tmpl_sources
1157 # Just announce that meta-template is installed and exit.
1159 if [ "$build_style" = "meta-template" ]; then
1160 installed_tmpl_handler register
$pkgname $version
1161 echo "==> Installed meta-template \`$pkg'."
1166 # Do not stow the pkg if requested.
1168 [ -z "$only_install" ] && stow_tmpl
$pkg
1172 # Lists all currently installed packages.
1176 if [ ! -r "$PKGFS_REGPKG_DB" ]; then
1177 echo "=> No packages registered or missing register db file."
1181 for i
in $
($db_cmd -K btree
$PKGFS_REGPKG_DB); do
1182 # Run file to get short_desc and print something useful
1183 run_file
${PKGFS_TEMPLATESDIR}/$i.tmpl
1184 echo "$i-$version $short_desc"
1190 # Removes a currently installed package (unstow + removed from destdir).
1196 if [ -z "$pkg" ]; then
1197 echo "*** ERROR: unexistent package, aborting ***"
1201 if [ ! -f "$PKGFS_TEMPLATESDIR/$pkg.tmpl" ]; then
1202 echo "*** ERROR: cannot find template file ***"
1206 run_file
$PKGFS_TEMPLATESDIR/$pkg.tmpl
1209 # If it's a meta-template, just unregister it from the db.
1211 if [ "$build_style" = "meta-template" ]; then
1212 installed_tmpl_handler unregister
$pkgname $version
1214 echo "=> Removed meta-template \`$pkg'."
1218 if [ ! -d "$PKGFS_DESTDIR/$pkg-$version" ]; then
1219 echo "*** ERROR: cannot find package on $PKGFS_DESTDIR ***"
1224 $rm_cmd -rf $PKGFS_DESTDIR/$pkg-$version
1231 args
=$
(getopt bCc
:efi $
*)
1232 [ "$?" -ne 0 ] && usage
1235 while [ "$#" -gt 0 ]; do
1244 config_file_specified
=yes
1245 PKGFS_CONFIG_FILE
="$2"
1265 [ "$#" -gt 2 ] && usage
1268 if [ -z "$target" ]; then
1269 echo "*** ERROR missing target ***"
1274 # Check configuration vars before anyting else, and set defaults vars.
1301 echo "*** ERROR invalid target '$target' ***"