-
Notifications
You must be signed in to change notification settings - Fork 37
/
maybe-install-bash-lib
executable file
·70 lines (63 loc) · 1.52 KB
/
maybe-install-bash-lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
# maybe-install-bash-lib LIBS ..
#
# This utility can be used with other bash libraries that depend on bash-lib,
# as part of their own installation procuedure, to ensure that the bash-lib is
# installed.
#
# LIBS can be any of the files intalled as part of the bash-lib set.
#
# The file name can be given with, or without the ".sh" suffix, and with, or
# withou the leading directory. For example, as "sh-utils", "sh-utils.sh", or
# "$HOME/lib/sh-utils.sh"
talk(){ echo 1>&2 "$*" ; }
install_bash_lib() {
tmpdir=/tmp/bash-lib.$$
logdir=$tmpdir.log
local status
talk "Installing github.com/aks/bash-lib .."
if ( set -x
mkdir $tmpdir
cd $tmpdir
git clone https://github.com/aks/bash-lib.git
cd ./bash-lib
make install
) &> $logdir ; then
talk "github.com/aks/bash-lib installed"
status=0
else
status=$?
talk "An error occurred installing bash-lib."
fi
talk "See $logdir for details."
exit $status
}
# if file_paths_missing $PATH ; then
# install-files
# fi
#
# Return success (0) if PATH needs to be installed
file_paths_missing() {
local file prog
for prog in $@ ; do
case "$prog" in
/*.sh) file="$prog" ;;
/*) file="$prog.sh" ;;
*.sh) file="$HOME/lib/$prog" ;;
*) file="$HOME/lib/$prog.sh" ;;
esac
if [[ ! -f $file ]]; then
return 0
fi
done
return 1
}
if (( $# > 0 )); then
libs="$*"
else
libs="sh-utils list-utils"
fi
if file_paths_missing $libs ; then
install_bash_lib
fi
exit 0