@@ -606,7 +606,7 @@ _ensure_origin_key_present() {
606
606
# If the commands are not found, `exit_with` is called and the program is
607
607
# terminated.
608
608
_find_system_commands () {
609
- if exists stat; then
609
+ if exists stat; then
610
610
if stat -f ' %Su:%g' . 2> /dev/null 1> /dev/null; then
611
611
_stat_variant=" bsd"
612
612
elif stat -c ' %u:%g' . 2> /dev/null 1> /dev/null; then
@@ -675,6 +675,66 @@ _find_system_commands() {
675
675
fi
676
676
}
677
677
678
+ # **Internal** Return the path to the latest release of a package on stdout.
679
+ #
680
+ # ```
681
+ # _latest_installed_package acme/nginx
682
+ # # /hab/pkgs/acme/nginx/1.8.0/20150911120000
683
+ # _latest_installed_package acme/nginx/1.8.0
684
+ # # /hab/pkgs/acme/nginx/1.8.0/20150911120000
685
+ # _latest_installed_package acme/nginx/1.8.0/20150911120000
686
+ # # /hab/pkgs/acme/nginx/1.8.0/20150911120000
687
+ # ```
688
+ #
689
+ # Will return 0 if a package was found on disk, and 1 if a package cannot be
690
+ # found. A message will be printed to stderr explaining that no package was
691
+ # found.
692
+ _latest_installed_package () {
693
+ local result
694
+ if result=" $( $HAB_BIN pkg path " $1 " 2> /dev/null) " ; then
695
+ echo " $result "
696
+ return 0
697
+ else
698
+ warn " Could not find a suitable installed package for '$1 '"
699
+ return 1
700
+ fi
701
+ }
702
+
703
+ # **Internal** Returns the path to the desired package on stdout, using the
704
+ # constraints specified in `$pkg_deps` or `$pkg_build_deps`. If a package
705
+ # cannot be found locally on disk, and the `hab` CLI package is present,
706
+ # this program will attempt to install the package from a remote repository.
707
+ #
708
+ # ```
709
+ # _resolve_dependency acme/zlib
710
+ # # /hab/pkgs/acme/zlib/1.2.8/20151216221001
711
+ # _resolve_dependency acme/zlib/1.2.8
712
+ # # /hab/pkgs/acme/zlib/1.2.8/20151216221001
713
+ # _resolve_dependency acme/zlib/1.2.8/20151216221001
714
+ # # /hab/pkgs/acme/zlib/1.2.8/20151216221001
715
+ # ```
716
+ #
717
+ # Will return 0 if a package was found or installed on disk, and 1 if a package
718
+ # cannot be found or remotely installed. A message will be printed to stderr to
719
+ # provide context.
720
+ _resolve_dependency () {
721
+ local dep=" $1 "
722
+ local dep_path
723
+ if ! echo " $dep " | grep -q ' \/' > /dev/null; then
724
+ warn " Origin required for '$dep ' in plan '$pkg_origin /$pkg_name ' (example: acme/$dep )"
725
+ return 1
726
+ fi
727
+
728
+ if dep_path=$( _latest_installed_package " $dep " ) ; then
729
+ echo " ${dep_path} "
730
+ return 0
731
+ else
732
+ return 1
733
+ fi
734
+ }
735
+
736
+ # **Internal** Attempts to download a package dependency. If the value of the
737
+
678
738
# **Internal** Attempts to download a package dependency. If the value of the
679
739
# `$NO_INSTALL_DEPS` variable is set, then no package installation will occur.
680
740
# If an installation is attempted but there is an error, this function will
@@ -689,22 +749,29 @@ _install_dependency() {
689
749
local dep=" ${1} "
690
750
local origin
691
751
local channel=" $HAB_BLDR_CHANNEL "
692
- if [[ -z " ${NO_INSTALL_DEPS:- } " ]]; then
693
- origin=" $( echo " $dep " | cut -d " /" -f 1) "
694
- if [[ $origin == " core" ]]; then
695
- channel=" $HAB_REFRESH_CHANNEL "
696
- if [[ $HAB_PREFER_LOCAL_CHEF_DEPS == " false" ]]; then
697
- IGNORE_LOCAL=" --ignore-local"
698
- fi
699
- fi
752
+ if [[ -z " ${NO_INSTALL_DEPS:- } " || ${NO_INSTALL_DEPS} == " false " ]]; then
753
+ origin=" $( echo " $dep " | cut -d " /" -f 1) "
754
+ if [[ $origin == " core" ]]; then
755
+ channel=" $HAB_REFRESH_CHANNEL "
756
+ if [[ $HAB_PREFER_LOCAL_CHEF_DEPS == " false" ]]; then
757
+ IGNORE_LOCAL=" --ignore-local"
758
+ fi
759
+ fi
700
760
701
- $HAB_BIN pkg install -u $HAB_BLDR_URL --channel $channel ${IGNORE_LOCAL:- } " $@ " || {
702
- if [[ " $channel " != " $HAB_FALLBACK_CHANNEL " ]]; then
703
- build_line " Trying to install '$dep ' from '$HAB_FALLBACK_CHANNEL '"
704
- $HAB_BIN pkg install -u $HAB_BLDR_URL --channel " $HAB_FALLBACK_CHANNEL " ${IGNORE_LOCAL:- } " $@ " || true
705
- fi
706
- }
707
- fi
761
+ $HAB_BIN pkg install -u $HAB_BLDR_URL --channel $channel ${IGNORE_LOCAL:- } " $@ " || {
762
+ if [[ " $channel " != " $HAB_FALLBACK_CHANNEL " ]]; then
763
+ build_line " Trying to install '$dep ' from '$HAB_FALLBACK_CHANNEL '"
764
+ $HAB_BIN pkg install -u $HAB_BLDR_URL --channel " $HAB_FALLBACK_CHANNEL " ${IGNORE_LOCAL:- } " $@ " || true
765
+ fi
766
+ }
767
+ else
768
+ if resolved=$( _resolve_dependency " ${dep} " | sed " s|${HAB_PKG_PATH} [/]\?||g" ) ; then
769
+ echo " ${resolved} "
770
+ return 0
771
+ else
772
+ return 1
773
+ fi
774
+ fi
708
775
return 0
709
776
}
710
777
@@ -921,7 +988,7 @@ _attach_whereami() {
921
988
# * Otherwise `$_hab_cmd` is used, set in the `_find_system_commands()`
922
989
# function
923
990
_determine_hab_bin () {
924
- if [[ -n " ${NO_INSTALL_DEPS:- } " ]]; then
991
+ if [[ -n " ${NO_INSTALL_DEPS:- } " && " ${NO_INSTALL_DEPS} " != " false " ]]; then
925
992
build_line " NO_INSTALL_DEPS set: no package dependencies will be installed"
926
993
fi
927
994
0 commit comments