-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaooi
507 lines (414 loc) · 13.2 KB
/
aooi
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
#!/bin/sh
#
# Atomic Offline OS installer (AOOI)
# install CentOS to a running system
# Due to the network in 1and1, we cant do a normal ks install, we need to drop off the CD to the local disk
#
# probably want to store on sdb2, so sda can be wiped. Followup in %post to finish creating the RAID
# initial tests caused problems with booting on a raid. Probably too large.
# network or local
VERSION="2.0.2"
DISTVERSION="6.5" # CentOS version
# Apparently debian doesnt support -i?
#ARCH=`uname -i` # What ARCH are we on
M_ARCH=`arch`
if [ "$M_ARCH" == "x86_64" ]; then
ARCH=x86_64
else
ARCH=i386
fi
function check_input {
message=$1
validate=$2
default=$3
while [ $? -ne 1 ]; do
echo -n "$message "
read INPUTTEXT < /dev/tty
if [ "$INPUTTEXT" == "" -a "$default" != "" ]; then
INPUTTEXT=$default
return 1
fi
echo $INPUTTEXT | egrep -q "$validate" && return 1
echo "Invalid input"
done
}
echo
echo "Atomic Offline OS Installer (AOOI)"
echo "by Scott R. Shinn <[email protected]>"
echo "Version $VERSION"
echo
echo "Credits: "
echo "www.gnuker.com"
echo "www.nefw.net"
echo "www.orionhost.net"
echo "www.protechone.com"
echo "Robinet at 1and1.fr"
echo "Igor at CloudLinux"
echo
echo "AOOI is designed to re-image a server with either CentOS or Cloudlinux."
echo "This installer does not back up your data, if for "
echo "any reason it fails you will need to reimage the system."
echo
echo "Hit enter if you accept this risk and wish to continue,"
echo "otherwise hit Ctrl-C to quit"
read < /dev/tty
echo
echo
echo "Turtle power."
sleep 2
echo
echo
echo
check_input "Would you like to re-image the system with CentOS $DISTVERSION or Cloudlinux $DISTVERSION (centos/cloudlinux) [Default: centos]" "centos|cloudlinux" "centos"
INSTALL_DIST=$INPUTTEXT
echo
echo "Selected $INSTALL_DIST"
echo
if [ "$INSTALL_DIST" == "cloudlinux" ]; then
MIRRORSITE="http://repo.cloudlinux.com/cloudlinux/"
ISOS="CloudLinux-$DISTVERSION-$ARCH-CD1.iso CloudLinux-$DISTVERSION-$ARCH-CD2.iso"
FIRSTISO="CloudLinux-$DISTVERSION-$ARCH-CD1.iso"
else
MIRRORSITE="http://mirrors.kernel.org/centos/"
ISOS="CentOS-$DISTVERSION-$ARCH-minimal.iso"
FIRSTISO="CentOS-$DISTVERSION-$ARCH-minimal.iso"
fi
## OS checks
# Detect if we're on debian
if egrep -q "Debian|Ubuntu" /etc/issue; then
DEBIAN=1
# Debian doesnt come with strings?
if [ ! -f /usr/bin/strings ]; then
apt-get -y --force-yes install binutils
fi
if [ $? -gt 0 ]; then
echo " There appears to have been a problem with apt. Attempting to resolve..."
sleep 2
apt-get update
apt-get -y --force-yes install binutils
fi
else
# Guess what? 1and1 can break centos too.
if [ ! -f /usr/bin/strings ]; then
yum -y install binutils
fi
fi
# More debian fixes, uname -i returns unknown.
if [ "$ARCH" == "unknown" ]; then
ARCH=x86_64
fi
# Detect if we're on SuSE
if [ -f /etc/SuSE-release ]; then
SUSE=1
fi
LOCALSERVER=$1 # Pull the ISO from localhost
## Get network variables
#if [ "$DEBIAN" == "1" ] ; then
IPADDR=`ifconfig eth0 | sed 's/:/ /' | awk '/inet addr/ {print $3}'`
NETMASK=`ifconfig eth0 | sed 's/:/ /g' | awk '/inet addr/ {print $7}'`
GATEWAY=`route -n |grep UG | awk '{print $2}'`
DNS=`grep nameserver /etc/resolv.conf |head -n 1 | awk '{print $2}'`
#else
# # load network settings into our config, and figure out our DNS server
# if [ -f /etc/sysconfig/network-scripts/ifcfg-eth0 ]; then
# . /etc/sysconfig/network-scripts/ifcfg-eth0
# fi
#fi
## Figure out what bootloader we're using.
DEVICES="hda hdb hdc hdd hde sda sdb sdc sdd sde"
echo > /tmp/disk.out
for i in $DEVICES; do
dd if=/dev/$i bs=512 count=1 2>/dev/null |strings >> /tmp/disk.out
done
NOGRUBBY=0
if grep -q GRUB /tmp/disk.out ; then
LOADER=GRUB
# Check for grubby
if [ ! -x /sbin/grubby ]; then
echo "Error: /sbin/grubby not detected, This is probably debian. Trying an alternate method"
NOGRUBBY=1
fi
GRUB=`which grub`
fi
if grep -q LILO /tmp/disk.out ; then
if [ -f /sbin/lilo ]; then
LOADER=LILO
else
echo "Error: LILO was detected as the boot loader, but /sbin/lilo was not detected. This is most likely a customized distribution. Exiting..."
exit 1
fi
fi
if [ "$LOADER" == "" ]; then
echo "Error: Couldn't determine boot loader"
exit 1
fi
# Network Install function
function netinstall {
INSTALL=NETWORK
if [ -d /boot ]; then
cd /boot
# grab the iso boot images
wget --no-cache -O - $MIRRORSITE/$DISTVERSION/os/$ARCH/isolinux/vmlinuz > /boot/vmlinuz.atomic || exit 1
wget --no-cache -O - $MIRRORSITE/$DISTVERSION/os/$ARCH/isolinux/initrd.img > /boot/initrd.img.atomic || exit 1
# add them to the bootloader
addkernel
else
echo "Error: Could not determine where to store boot image, exiting"
exit 1
fi
}
function localinstall {
INSTALL=LOCAL
# if [ "$ARCH" == "x86_64" ]; then
# else
# ISOS="CentOS-$DISTVERSION-$ARCH-bin-1of7.iso"
# FIRSTISO=$ISOS
# fi
# Do we have sfdisk?
if [ ! -x /sbin/sfdisk ]; then
echo "sfdisk not detected. Exiting"
exit 1
fi
# Are we at 1and1?
if grep -q onlinehome /etc/yum.conf; then
# echo "Detected broken 1and1 configuration "
# mv /etc/yum.conf /etc/yum.conf.broken
# cd /etc
# wget -q http://3es.atomicrocketturtle.com/tests/config/yum.conf
# yum clean all
BOOTLOADER=1AND1
fi
# Check for mkfs.vfat
if [ ! -x /sbin/mkfs.vfat ]; then
if [ "$DEBIAN" == "1" ]; then
apt-get install dosfstools
elif [ "$SUSE" == "1" ]; then
echo "mkfs.vfat not detected. This appears to be a SUSE system"
echo "Attempting to install dosfstools through yast, this can take a very long time"
echo
echo "Please be patient"
echo
echo "Hit any key to continue "
read foo < /dev/tty
yast -i dosfstools
if [ ! -d /mnt ]; then
mkdir /mnt
fi
else
echo "mkfs.vfat not detected. Attempting to resolve with: yum -y install dosfstools"
yum -y install dosfstools || exit 1
fi
fi
# disable swap, this gets tricky with multiple swap partitions
echo -n "Transferring image to swap: "
/sbin/swapoff -a
# Yes. This is ugly.
DEVS="sda sdb sdc sdd sde sdf hda hdb hdc hdd hde hdf"
PARTS="1 2 3 4 5 6 7 8"
count=0
# extract all the swap partitions
for data in `grep swap /etc/fstab |awk -Fdev/ '{print $2}' |awk '{print $1}'`; do
echo "$data" > /tmp/swap.out
# Test device name against the array to split this up for sfdisk
for i in $DEVS; do
for y in $PARTS; do
if grep -q $i$y /tmp/swap.out; then
# we do this on all swap partitions, just to make sure we dont zap them on a raid
SFSWAP="/dev/$i $y"
SWAP="/dev/$i$y"
# Make the fs vfat, and then set the disklabel
# except 1and1 doesnt do vfat any more.
# this is annoying, the first time we'll set this to ext3. Vfat the 2nd pass.
if [ $count -lt 1 ]; then
/sbin/mkfs.ext3 $SWAP
count=`expr $count + 1`
else
/sbin/mkfs.vfat $SWAP > /dev/null 2>/dev/null
if [ "$SUSE" == "1" ]; then
/sbin/mkfs.ext3 $SWAP
fi
fi
# Set the partition flag to vfat. Not that this helped protect the partition from anaconda. :P
/sbin/sfdisk --force --change-id $SFSWAP 7
# If KSDEV isnt defined, assign it, otherwise skip it
if [ ! $KSDEV ]; then
KSDEV="$i$y"
# We only need to mount the first swap partition we detect
/bin/mount $SWAP /mnt/
echo
fi
fi
done
done
done
if [ "$SFSWAP" == "" ]; then
echo "Error: could not parse the swap partition. Report the output of /etc/fstab to [email protected]"
echo
exit 1
fi
cd /mnt
echo
# Create the ISO's to grab array
for i in $ISOS; do
DETECTED=0
if [ -f $i ]; then
DETECTED=1
else
# populate the array with what to get
DOWNLOAD="$DOWNLOAD $i "
fi
done
# Download ISO's
if [ $DETECTED -eq 1 ]; then
echo "CentOS-$DISTVERSION-$ARCH all ISOS detected"
else
echo -n "Getting CentOS ISO: "
if [ "$LOCALSERVER" == "" ]; then
for l in $DOWNLOAD; do
wget $MIRRORSITE/$DISTVERSION/isos/$ARCH/$l
done
else
# this is probably never going to work again
wget http://localhost/CentOS-$DISTVERSION.ServerCD-$ARCH.iso
fi
echo "Done."
fi
# Look for the first ISO
if [ ! -f $FIRSTISO ]; then
echo "Error: Cannot find the CentOS server image"
exit 1
fi
# Grab the ISO kernel
echo -n "Setting up installer kernel: "
# mkdir 1
# /bin/mount -o loop $FIRSTISO 1/
# cp 1/isolinux/vmlinuz /boot/vmlinuz.atomic
# cp 1/isolinux/initrd.img /boot/initrd.img.atomic
wget --no-cache -O - $MIRRORSITE/$DISTVERSION/os/$ARCH/isolinux/vmlinuz > /boot/vmlinuz.atomic
wget --no-cache -O - $MIRRORSITE/$DISTVERSION/os/$ARCH/isolinux/initrd.img > /boot/initrd.img.atomic
echo "Done"
# do the ks.cfg
# drop this off in / instead of /boot on a 1and1 system
cd /mnt
if [ "$LOADER" == "LILO" ]; then
# 1and1 detection isnt so hot on older rh9/fc2 systems. Especially if they've been ASL'd
# Added to get this on a second run
BOOTLOADER=1AND1
if [ "$BOOTLOADER" == "1AND1" ]; then
# 1and1 x86_64 config
wget http://www.atomicorp.com/installers/AOOI/ks-1and1-$ARCH.cfg >/dev/null 2>&1
echo "ks path is hd:$KSDEV:ks-1and1$ARCH.cfg"
# write config to lilo
cat >> /etc/lilo.conf << EOF
image=/boot/vmlinuz.atomic
label=atomic
initrd=/boot/initrd.img.atomic
append="ks=hd:$KSDEV:ks-1and1-$ARCH.cfg console=ttyS0,57600n8 ksdevice=eth0"
EOF
else
#wget
echo "This part of the installer, for lilo using non-1and1 systems isnt done yet"
echo "Use a net install"
exit 1
fi
# write to lilo
if [ -f /sbin/lilo ]; then
/sbin/lilo
else
echo "Error: lilo was detected as the bootloader, but /sbin/lilo was not detected."
exit 1
fi
# set the temp boot
echo "Setting the next reboot to use the ISO image"
/sbin/lilo -R atomic
else
# We're using grub, Add kernel to boot
addkernel
fi
}
# this is easier on a net install, no vars needed
function addkernel {
if [ "$LOADER" == "GRUB" ]; then
# were using grub
echo "Detected Grub, adding atomic entry"
# if we're in network mode
if [ "$INSTALL" == "NETWORK" ]; then
if [ $NOGRUBBY -gt 0 ]; then
# an expiremental fix for debian since they dont have grubby
# we hose their grub config until a better way can be determined.
cat << EOF > /boot/grub/menu.lst
default=0
timeout=5
title Atomic
root (hd0,0)
kernel /boot/vmlinuz.atomic ks=http://www.atomicorp.com/installers/AOOI/ks-$ARCH.cfg ip=$IPADDR netmask=$NETMASK gateway=$GATEWAY dns=$DNS ksdevice=eth0
initrd /boot/initrd.img.atomic
EOF
else
/sbin/grubby --add-kernel=/boot/vmlinuz.atomic --initrd /boot/initrd.img.atomic --title "Atomic" \
--copy-default --args="ks=http://www.atomicorp.com/installers/AOOI/ks-$ARCH.cfg ip=$IPADDR netmask=$NETMASK gateway=$GATEWAY dns=$DNS"
fi
else
# if we're in local mode
cd /mnt
wget http://www.atomicorp.com/installers/AOOI/ks-1and1-$ARCH.cfg >/dev/null 2>&1
/sbin/grubby --add-kernel=/boot/vmlinuz.atomic --initrd /boot/initrd.img.atomic --title "Atomic" \
--copy-default --args="ks=hd:$KSDEV:ks-1and1-$ARCH.cfg ip=$IPADDR netmask=$NETMASK gateway=$GATEWAY dns=$DNS"
fi
# Boot only once
echo "Setting grub to boot the atomic entry *once*"
/sbin/grub --batch <<EOF
savedefault --default=0 --once
EOF
else
# We're using lilo
echo "Detected Lilo, adding atomic entry"
cat >> /etc/lilo.conf << EOF
image=/boot/vmlinuz.atomic
label=atomic
initrd=/boot/initrd.img.atomic
append="ks=http://www.atomicorp.com/installers/AOOI/ks-$ARCH.cfg ip=$IPADDR netmask=$NETMASK gateway=$GATEWAY dns=$DNS console=tty0 console=tty1 console=ttyS0,57600n8"
EOF
#Set lilo to boot it once
echo "Setting lilo to boot the atomic entry *once*"
/sbin/lilo
/sbin/lilo -R atomic
fi
}
function check_input {
message=$1
validate=$2
default=$3
while [ $? -ne 1 ]; do
echo -n "$message "
read INPUTTEXT < /dev/tty
if [ "$INPUTTEXT" == "" -a "$default" != "" ]; then
INPUTTEXT=$default
return 1
fi
echo $INPUTTEXT | egrep -q "$validate" && return 1
echo "Invalid input, expecting ($validate)"
echo
done
}
# Logic for Network or Local install
echo
echo "Do you want to perform an installation over the network, or from a locally"
echo "cached ISO. Local installations may be required if for some reason the"
echo "installation kernel cannot work correctly with your network card. For most"
echo "installations, choose network."
echo
check_input "Network or Local installation (network/local) [Default: network] ?" "network|local" "network"
if [ "$INPUTTEXT" == "network" ]; then
netinstall
else
localinstall
fi
echo
echo
echo "Done"
echo
echo
echo "The installer has been configured, back up your data including your /etc/psa/psa.key, and reboot the system."
echo "Root password has been temporarily set to: atomic555"
echo