-
Notifications
You must be signed in to change notification settings - Fork 7
/
installer.sh
executable file
·183 lines (157 loc) · 4.67 KB
/
installer.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# To be used for checking dependencies
# Consider the deps to be not present
DOCKER_INSTALLED=0
PIP_INSTALLED=0
FLASK_INSTALLED=0
GIT_INSTALLED=0
user_interrupt(){
echo -e "\n\nKeyboard Interrupt detected."
echo -e "Cleaning Up and terminating..."
if [ -d $DIRECTORY ]; then
rm -rf $DIRECTORY
fi
exit
}
trap user_interrupt SIGINT
trap user_interrupt SIGTSTP
setup_env(){
if [ -d $DIRECTORY ]; then
echo "cleaning up traces of last installation.."
rm -rf $DIRECTORY
fi
if [ -f configuration ]; then
source configuration
else
echo "Config file 'configuration' doesn't exist"
exit
fi
echo $CONTAINER_COUNT
if [[ -z $DC_HOST ]]; then
echo "export DC_HOST='"$SERVER_HOSTNAME"'" >> $HOME/.bashrc
echo "export DC_PORT='"$SERVER_PORT"'" >> $HOME/.bashrc
# either source it or set it for current session
export DC_HOST=$SERVER_HOSTNAME
export DC_PORT=$SERVER_PORT
fi
}
check_docker(){
DOCKER_CMD=$(which docker)
if [[ ! -z $DOCKER_CMD ]]; then
DOCKER_INSTALLED=1 # Docker is installed
echo "Docker is already installed"
fi
}
check_pip(){
PIP_CMD=$(which pip2)
if [[ ! -z $PIP_CMD ]]; then
PIP_INSTALLED=1 # pip is installed
echo "pip is already installed"
fi
}
check_flask(){
FLASK_CMD=$(python -c "try: import flask; print
except: print 1")
if [[ -z $FLASK_CMD ]]; then
FLASK_INSTALLED=1 # flask is installed
echo "flask is already installed"
fi
}
check_git(){
GIT_CMD=$(which git)
if [[ ! -z $GIT_CMD ]]; then
GIT_INSTALLED=1 # git is installed
echo "Git is already installed"
fi
}
check_deps(){
check_docker
check_pip
check_flask
check_git
}
setup_deps(){
check_deps
if [ $GIT_INSTALLED -eq 1 ] && [ $DOCKER_INSTALLED -eq 1 ] \
&& [ $PIP_INSTALLED -eq 1 ] && [ $FLASK_INSTALLED -eq 1 ];
then
echo "All dependencies are statisfied."
return
else
echo "Need to install dependencies which are currently not installed on your system"
echo "Please enter password for "$USER".."
fi
YUM_CMD=$(which yum)
APT_GET_CMD=$(which apt-get)
# OTHER_CMD=$(which <other installer>)
if [[ ! -z $YUM_CMD ]]; then
command="sudo yum -y install" # rpm based
elif [[ ! -z $APT_GET_CMD ]]; then
command="sudo apt-get install -y" # deb based
# elif [[ ! -z $OTHER_CMD ]]; then
# $OTHER_CMD <proper arguments>
else
echo "error can't install package $PACKAGE."
echo "kindly edit this script to add your package manager in 'OTHER_CMD='"
exit 1;
fi
if [ $GIT_INSTALLED -eq 0 ]; then # install git
git_install=$command" git"
eval $git_install
fi
if [ $PIP_INSTALLED -eq 0 ]; then # install pip
pip_install=$command" python-pip"
eval $pip_install
fi
if [ $FLASK_INSTALLED -eq 0 ]; then # install flask
sudo pip install flask
fi
if [ $DOCKER_INSTALLED -eq 0 ]; then # install docker
if [[ ! -z $APT_GET_CMD ]]; then # deb based
docker_install=$command" docker.io"
eval $docker_install
sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker
sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.io
source /etc/bash_completion.d/docker.io
fi
if [[ ! -z $YUM_CMD ]]; then # rpm based
docker_install=$command" docker-io"
eval $docker_install
sudo systemctl start docker
sudo systemctl enable docker
fi
fi
}
setup_app(){
cd $HOME
git clone https://github.com/arcolife/dockerComp.git $DIRECTORY
cd $DIRECTORY
# remove server side code, useless for normal users
git config core.sparseCheckout true
echo src/client/ > .git/info/sparse-checkout
git checkout master
cd src/client/scripts/
echo -e "launching workers.."
./launch_workers $CONTAINER_COUNT
echo -e "testing connection to server.."
./test_server_conn
# # copy the client daemon from here
# cp ./scripts/slave_manager $HOME/
# echo -e "\n..cleaning up and removing "$DIRECTORY
# rm -rf $DIRECTORY
# cd $HOME
echo -e "\n starting the client task manager daemon now.."
nohup ./slave_manager &
}
setup_env
setup_deps
if [[ -z $(cat /etc/group | grep docker | grep $USER) ]]; then
echo 'need sudo to add $USER to "docker" group.'
sudo usermod -a -G docker $USER
echo
echo "..added user to docker group."
echo "..this script will stop executing now, run it again."
newgrp docker
else
setup_app
fi