forked from luigifreda/pyslam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_utils.sh
104 lines (93 loc) · 2.33 KB
/
bash_utils.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# a collection of bash utils
# ====================================================
function get_after_last_slash(){
ret=$(echo $1 | sed 's:.*/::')
echo $ret
}
function get_virtualenv_name(){
cmd_out=$(printenv | grep VIRTUAL_ENV)
virtual_env_name=$(get_after_last_slash $cmd_out)
echo $virtual_env_name
}
function print_blue(){
printf "\033[34;1m"
printf "$@ \n"
printf "\033[0m"
}
function make_dir(){
if [ ! -d $1 ]; then
mkdir -p $1
fi
}
function make_buid_dir(){
make_dir build
}
function check_package(){
package_name=$1
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $package_name |grep "install ok installed")
#echo "checking for $package_name: $PKG_OK"
if [ "" == "$PKG_OK" ]; then
#echo "$package_name is not installed"
echo 1
else
echo 0
fi
}
function install_package(){
do_install=$(check_package $1)
if [ $do_install -eq 1 ] ; then
sudo apt-get install -y $1
fi
}
function check_pip_package(){
package_name=$1
PKG_OK=$(pip3 list --format=legacy |grep $package_name)
#echo "checking for $package_name: $PKG_OK"
if [ "" == "$PKG_OK" ]; then
#echo "$package_name is not installed"
echo 1
else
echo 0
fi
}
function check_pip_package2(){
package_name=$1
if python3 -c "import "$package_name &> /dev/null; then
echo 0
else
#echo "$package_name is not installed"
echo 1
fi
}
function install_pip_package(){
do_install=$(check_pip_package $1)
virtual_env=$(get_virtualenv_name)
if [ $do_install -eq 1 ] ; then
if [ "" == "$virtual_env" ]; then
pip3 install --user $1
else
pip3 install $1 # if you are in a virtual environment the option `--user` will install make pip3 install things outside the env
fi
fi
}
function install_pip_packages(){
for var in "$@"
do
install_pip_package "$var"
done
}
function set_git_modules() {
#print_blue "setting up git submodules"
git submodule init --
git submodule sync --recursive
git submodule update --recursive
}
function update_git_modules() {
git submodule update --recursive --remote
}
function pause(){
read -s -n 1 -p "Press any key to continue . . ."
echo ""
}
# ====================================================