This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·137 lines (104 loc) · 3.57 KB
/
install.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/bin/bash
HEADER='\033[1;34m'
ERROR='\033[1;31m'
OK='\033[1;32m'
ENDC='\033[0m'
echo -e -n "${HEADER}"
echo "#######################################################"
echo "## Welcome to IMDEA Controls Python installer ##"
echo "#######################################################"
echo ""
echo -n "[++] Checking for dependencies..."
echo -e "${ENDC}"
echo -e "${HEADER}\t[+] Updating apt... please type your password...${ENDC}"
sudo apt-get update -qq
# TODO: check if python is python 2.7
echo -e -n "${HEADER}\t[+] Checking if python is installed...${ENDC}"
dpkg -s python2.7 >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e -n "${ERROR}FAIL\n${HEADER}\t\t[-] Installing python...${ENDC}"
sudo apt-get install -y python2.7 >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${OK}OK${ENDC}"
else
echo -e "${ERROR}ERROR${ENDC}"
fi
else
echo -e "${OK}OK${ENDC}"
fi
echo -e -n "${HEADER}\t[+] Checking if python-pip is installed...${ENDC}"
dpkg -s python-pip >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e -n "${ERROR}FAIL\n${HEADER}\t\t[-] Installing python-pip...${ENDC}"
sudo apt-get install -y python-pip >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${OK}OK${ENDC}"
else
echo -e "${ERROR}ERROR${ENDC}"
fi
else
echo -e "${OK}OK${ENDC}"
fi
echo -e -n "${HEADER}\t[+] Checking if python module requests is installed...${ENDC}"
python -c "import requests" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e -n "${ERROR}FAIL\n${HEADER}\t\t[-] Installing requests module...${ENDC}"
cat <<EOF > .virtualenv-test
import sys
if hasattr(sys, 'real_prefix'):
sys.exit(1)
EOF
python .virtualenv-test
if [ $? -eq 1 ]; then
pip install -r requeriments.txt >/dev/null 2>&1
else
pip install --user -r requeriments.txt >/dev/null 2>&1
fi
if [ $? -eq 0 ]; then
echo -e "${OK}OK${ENDC}"
else
echo -e "${ERROR}ERROR${ENDC}"
fi
rm .virtualenv-test
else
echo -e "${OK}OK${ENDC}"
fi
echo ""
echo -e "${HEADER}[++] Setting alias for control.py...${ENDC}"
alias_def="icp"
alias_long="imdea-control"
alias_final="" # to set with the final alias added in ~/.aliases
echo -e -n "${HEADER}\t[+] Checking if alias $alias_def already exists in ~/.aliases file...${ENDC}"
grep -Fx "alias $alias_def" ~/.aliases >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${ERROR}FAIL\n${HEADER}\t\t[-] Setting $alias_long as alias...${OK}OK${ENDC}"
echo "alias $alias_long='${PWD}/control.py'" >> ~/.aliases
alias_final=$alias_long
else
echo -e "${OK}OK\n${HEADER}\t\t[-] Setting $alias_def as alias...${OK}OK${ENDC}"
echo "alias $alias_def='${PWD}/control.py'" >> ~/.aliases
alias_final=$alias_def
fi
echo -e -n "${HEADER}\t[+] Checking if alias already exists in ~/.bashrc...${ENDC}"
grep -Fx "source ~/.aliases" ~/.bashrc >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${OK}OK${ENDC}"
else
echo -e $"${ERROR}FAIL\n${HEADER}\t\t[-] Adding alias to .bashrc...${OK}OK${ENDC}"
echo "source ~/.aliases" >> ~/.bashrc
fi
echo -e -n "${HEADER}\t[+] Checking if alias already exists in ~/.zshrc...${ENDC}"
grep -Fx "source ~/.aliases" ~/.zshrc >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo -e "${OK}OK${ENDC}"
else
echo -e "${ERROR}FAIL\n${HEADER}\t\t[-] Adding alias to .zshrc...${OK}OK${ENDC}"
echo "source ~/.aliases" >> ~/.zshrc
fi
echo -e "${HEADER}"
echo -e -n "Installation finished, run your script with \"$alias_final\" command"
echo -e "${ENDC}"
echo ""
echo -e "${HEADER}[++] Running './control.py -h' script...${ENDC}"
echo ""
python ${PWD}/control.py -h