forked from lamamos/lamamos_installation_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_lamamos.sh
executable file
·361 lines (248 loc) · 8.3 KB
/
install_lamamos.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/bin/bash
#test if we are root
if [[ $EUID -ne 0 ]]; then
echo "You must be a root user" 2>&1
exit 1
fi
#taken from : https://people.debian.org/~schultmc/locales.html
echo -en "\ec"
echo "=====We are going to install the locals====="
cp locale.gen /etc/locale.gen
/usr/sbin/locale-gen
echo -en "\ec"
echo "=====We are going to install git====="
apt-get update
apt-get install -y git
echo -en "\ec"
echo "===We update the project==="
git pull origin master
echo "===We get the submodules of the project==="
git submodule init
git submodule update
function randomString {
# if a param was passed, it's the length of the string we want
if [[ -n $1 ]] && [[ "$1" -lt 100 ]]; then
local myStrLength=$1;
else
# otherwise set to default
local myStrLength=8;
fi
local mySeedNumber=$$`date +%N`; # seed will be the pid + nanoseconds
local myRandomString=$( echo $mySeedNumber | md5sum | md5sum );
# create our actual random string
myRandomResult="${myRandomString:2:myStrLength}"
}
function chooseHardDrive {
echo "===Choose the data disk==="
disks=`lsblk -r -o NAME,TYPE,SIZE,MOUNTPOINT|sed "1 d"`
avalable_disks=()
while IFS= read -r line
do
name=`echo $line|cut --delimiter=" " -f1`
type=`echo $line|cut --delimiter=" " -f2`
mount=`echo $line|cut --delimiter=" " -f4`
size=`echo $line|cut --delimiter=" " -f3`
if [ "$type" == "part" ] && [ -z "$mount" ];then
avalable_disks+=("$name ($size)")
fi
done < <(echo "$disks") #need to be here to create a process substitution, so the variable are not erased at the end
number_disks=${#avalable_disks[@]}
avalable_disks+=("Quit")
quit_number=${#avalable_disks[@]}
PS3='On which partition must I put the data (WARNING, this partition will be formatted): '
select opt in "${avalable_disks[@]}"
do
if [ "$REPLY" -eq "$quit_number" ]; then #if we choose to quit
exit
fi
if [ "$REPLY" -gt "0" ] && [ "$REPLY" -le "$number_disks" ]; then
break
else
echo "dafuk"
fi
done
opt=`echo $opt|cut --delimiter=" " -f1`
data_disk="/dev/$opt"
#we ask confirmation
echo "Your are going to format the partition $data_disk"
read -p "Are you sure? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
chooseHardDrive;
fi
}
function configureFirstServer {
echo -en "\ec"
echo "=== Configuration of lamamos ==="
echo "I am going to ask you a few questions in order to configure lamamos"
echo
echo
#ajouter un compteur sur le nombre de questions
echo -n "This server hostname should be (will be set) > "
read server1Hostname
echo -n "This server IP is (should be already set) > "
read server1IP
echo
echo
echo -n "The second server hostname should be (will be set) > "
read server2Hostname
echo -n "The second server IP is (should be already set) > "
read server2IP
echo
echo
echo -n "The IP that will be shared between the servers (must be different from the two previus ones) > "
read sharedIP
echo
echo
echo -n "The password protecting the administration pannel of the server > "
read -s adminPassw
adminPassw=`htpasswd -n -b admin $adminPassw`
echo
chooseHardDrive;
randomString 30;
}
function writeConfigToFile {
echo "=== writting the config to the file ==="
#just in case if the file already exists
rm lamamos/lamamos.conf
echo "%config = (" >> lamamos/lamamos.conf
echo "" >> lamamos/lamamos.conf
echo " 'drbdSharedSecret' => '$myRandomResult'," >> lamamos/lamamos.conf
echo " 'ddName' => '$data_disk'," >> lamamos/lamamos.conf
echo " 'OCFS2Init' => '0'," >> lamamos/lamamos.conf
echo " 'ddFormated' => '0'," >> lamamos/lamamos.conf
echo " 'firstServHostName' => '$server1Hostname'," >> lamamos/lamamos.conf
echo " 'firstServIP' => '$server1IP'," >> lamamos/lamamos.conf
echo " 'SeconServHostName' => '$server2Hostname'," >> lamamos/lamamos.conf
echo " 'SeconServIP' => '$server2IP'," >> lamamos/lamamos.conf
echo " 'sharedIP' => '$sharedIP'," >> lamamos/lamamos.conf
echo " 'adminPanelPassw' => '$adminPassw'," >> lamamos/lamamos.conf
echo ");" >> lamamos/lamamos.conf
echo "" >> lamamos/lamamos.conf
}
function getConfigFromFirstServer {
echo -n "What is the IP of the first server (to retrieve the configuration from it) > "
read firstServerIP
echo "downloading the config from the other server (you will be asked for the root password on this other server)"
scp root@$firstServerIP:/etc/lamamos/lamamos.conf lamamos/lamamos.conf
}
function validateConfiguration {
echo -en "\ec"
echo "=== Here is the configuration you just entered ==="
echo ""
echo "The hostname of this server : $server1Hostname"
echo "The IP of this server : $server1IP"
echo "The hostname of the second server : $server2Hostname"
echo "The IP of the second server : $server2IP"
echo "The partition that will be used for datas (will be formated) : $data_disk"
#we ask confirmation
read -p "Is this configuration correct? [y/n] " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
configNotValidated=0;
fi
}
function enterConfiguration {
echo "I am going to ask you a few questions in order to configure lamamos (7 questions)"
echo ""
echo ""
isFirstServer=0;
echo -n "Are you configurating the first server ? (if you already configured the first server, I can pull the config from it) [y/n] > "
read -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Nn]$ ]]
then
getConfigFromFirstServer;
isFirstServer=0;
else
isFirstServer=1;
configNotValidated=1;
while [ $configNotValidated -gt 0 ]
do
configureFirstServer;
validateConfiguration;
echo -en "\ec"
done
#write the configuration to a file
writeConfigToFile;
fi
}
echo -en "\ec"
echo "=== Configuration of lamamos ==="
#if we got a config file already in place
if [ -e "lamamos.conf" ]
then
#just in case if the file already exists
rm lamamos/lamamos.conf
cp lamamos.conf lamamos/lamamos.conf
#firstServerIP=`cat lamamos.conf | grep "firstServIP" | cut -d"'" -f4`;
firstServerName=`cat lamamos.conf | grep "firstServHostName" | cut -d"'" -f4`;
thisServerName=`cat /etc/hostname`
if [ "$firstServerName" = "$thisServerName" ]
then
isFirstServer=1;
else
isFirstServer=0;
fi
else
enterConfiguration;
fi
getConfigParameter(){
configParameter=`cat lamamos/lamamos.conf | grep "$1" | cut -d"'" -f4`;
}
##TODO : need to detect the right interface on wich we need to change the ip. Detect the network
#echo -en "\ec"
#echo "===We set the configured IP==="
#
#if [ $isFirstServer -gt 0 ]
#then
# getConfigParameter firstServIP;
#else
# getConfigParameter SeconServIP;
#fi
##add a apply configuration for the IP
#ïfconfig eth0 $configParameter
echo -en "\ec"
echo "===We set the configured hostname==="
if [ $isFirstServer -gt 0 ]
then
getConfigParameter firstServHostName;
else
getConfigParameter SeconServHostName;
fi
echo "$configParameter" > /etc/hostname
hostname $configParameter
echo -en "\ec"
echo "===Then we create a directory for lamamos configuration==="
mkdir /etc/lamamos
echo "===We copy the configuration of lamamos==="
cp -r lamamos/* /etc/lamamos/
echo "===We make the lamamos configuration editable by lamadmin==="
chown www-data:www-data /etc/lamamos/rex/Rexfile
echo "===We generate ssh key==="
ssh-keygen -f /root/.ssh/id_rsa -N ""
cp /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
echo -en "\ec"
echo "===We install rex==="
echo 'deb http://rex.linux-files.org/debian/ wheezy rex' >> /etc/apt/sources.list
wget -O - http://rex.linux-files.org/DPKG-GPG-KEY-REXIFY-REPO | apt-key add -
apt-get update
apt-get install -y rex libxml-libxml-perl
echo -en "\ec"
echo "===Formating the drive==="
#We install pv in order to be able to display a progress bar of the formatting
apt-get install pv
getConfigParameter ddName;
taille=`fdisk -l $configParameter | sed -n 2p | cut -d ' ' -f 5`
dd bs=4096 if=/dev/zero | pv --size $taille | dd bs=4096 of=$configParameter
echo -en "\ec"
echo "===Copy the launching file for lamamos (launch a configure at every boot)==="
cp lamamos/lamamos /etc/init.d/
chmod 755 /etc/init.d/lamamos
update-rc.d lamamos defaults
echo -en "\ec"
echo "===Finally we launch the first configuration using Rex==="
cd /etc/lamamos/rex/
rex configure