@@ -35,35 +35,54 @@ _install_tool() {
3535 bin=" ${4:- " ${tool} " } "
3636 func=" ${5:- " _install_${tool} " } "
3737
38- if [[ " ${OZONE_PREFER_LOCAL_TOOL} " == " true" ]] && which " $bin " >& /dev/null; then
38+ if [[ " ${OZONE_PREFER_LOCAL_TOOL} " == " true" ]] && which " ${ bin} " >& /dev/null; then
3939 echo " Skip installing $bin , as it's already available on PATH."
4040 return
4141 fi
4242
43- if [[ ! -d " ${dir} " ]] || ! which " $bin " >& /dev/null ; then
43+ if [[ ! -d " ${dir} " ]]; then
4444 mkdir -pv " ${dir} "
45- pushd " ${dir} "
46- if eval " ${func} " ; then
47- echo " Installed ${tool} in ${dir} "
48- else
49- msg=" Failed to install ${tool} "
50- echo " $msg " >&2
51- if [[ -n " ${REPORT_FILE} " ]]; then
52- echo " $msg " >> " ${REPORT_FILE} "
53- fi
54- exit 1
45+ _do_install " ${tool} " " ${dir} " " ${func} "
46+ fi
47+
48+ if [[ -n " ${bindir} " ]]; then
49+ _add_to_path " ${dir} " /" ${bindir} "
50+
51+ if ! which " ${bin} " >& /dev/null; then
52+ _do_install " ${tool} " " ${dir} " " ${func} "
53+ _add_to_path " ${dir} " /" ${bindir} "
5554 fi
55+ fi
56+ }
57+
58+ _do_install () {
59+ local tool=" $1 "
60+ local dir=" $2 "
61+ local func=" $3 "
62+
63+ pushd " ${dir} "
64+ if eval " ${func} " ; then
65+ echo " Installed ${tool} in ${dir} "
66+ popd
67+ else
5668 popd
69+ msg=" Failed to install ${tool} "
70+ echo " ${msg} " >&2
71+ if [[ -n " ${REPORT_FILE} " ]]; then
72+ echo " ${msg} " >> " ${REPORT_FILE} "
73+ fi
74+ exit 1
5775 fi
76+ }
5877
59- if [[ -n " ${bindir} " ]] ; then
60- bindir=" ${dir} " / " ${bindir} "
61- if [[ -d " ${bindir} " ]] ; then
62- if [[ " ${OZONE_PREFER_LOCAL_TOOL} " == " true " ]]; then
63- export PATH= " ${PATH} : ${bindir} "
64- else
65- export PATH= " ${bindir} : ${PATH} "
66- fi
78+ _add_to_path () {
79+ local bindir=" $1 "
80+
81+ if [[ -d " ${bindir} " ]]; then
82+ if [[ " ${OZONE_PREFER_LOCAL_TOOL} " == " true " ]] ; then
83+ export PATH= " ${PATH} : ${bindir} "
84+ else
85+ export PATH= " ${bindir} : ${PATH} "
6786 fi
6887 fi
6988}
0 commit comments