-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathz-exec-virtualenv.sh
executable file
·61 lines (49 loc) · 1.45 KB
/
z-exec-virtualenv.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
#!/usr/bin/env bash
shell_run_path=$(cd `dirname $0`; pwd)
shell_now_path_folder=$(pwd | awk -F "/" '{print $(NF)}')
prod_virtualenv_name="${shell_now_path_folder}"
want_install_modules=(
pytest
)
checkFuncBack(){
if [ ! $? -eq 0 ]; then
echo -e "\033[;31mRun [ $1 ] error exit code 1\033[0m"
exit 1
# else
# echo -e "\033[;30mRun [ $1 ] success\033[0m"
fi
}
checkEnv(){
evn_checker=`which $1`
checkFuncBack "which $1"
if [ ! -n "evn_checker" ]; then
echo -e "\033[;31mCheck event [ $1 ] error exit\033[0m"
exit 1
# else
# echo -e "\033[;32mCli [ $1 ] event check success\033[0m\n-> \033[;34m$1 at Path: ${evn_checker}\033[0m"
fi
}
checkUserAsRoot(){
if [[ "$USER" != "root" ]]; then
echo -e "\033[;31mMust run as root\033[0m"
exit 1
fi
}
# checkUserAsRoot
checkEnv virtualenv
virtualenv ${prod_virtualenv_name}
checkFuncBack "virtualenv ${prod_virtualenv_name}"
#virtualenv --system-site-packages ${prod_virtualenv_name}
source ${prod_virtualenv_name}/bin/activate
if [ $# -eq 0 ]; then
echo -e "\033[;36m=> If want install module like ${want_install_modules}\nplease input any args\033[0m"
else
if [ -n "${want_install_modules}" ]; then
for module in ${want_install_modules[@]};
do
echo -e "\033[;34m-> now install module [ ${module} ]\033[0m"
pip install module
done
fi
fi
echo -e "\033[;32m=> Exec virtualenv [ ${prod_virtualenv_name} ] success\033[0m"