-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buux.sh
executable file
·506 lines (437 loc) · 14.2 KB
/
Buux.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
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
#!/bin/bash
####################################################
# Developers notes
#
#
# Single # is used for commenting out code. i.e. code that is not yet functioning
# double # is used for Code Explain i.e. ##Download required files
# ##TODO is for planned implements
#
#
####################################################
##Version Check
Version="1.5"
latest=$(curl -s https://raw.githubusercontent.com/lonix/BUUX/master/version)
clear
if [ "$Version" != "$latest" ]; then
echo "New version is availble, newest version is $latest"
echo "you are running version $Version"
echo ""
echo "New this version: "
echo "-----------------------------------------"
curl "https://raw.githubusercontent.com/lonix/BUUX/master/changes"
echo "-----------------------------------------"
echo "To upgrade simple copy-paste this into your console:"
echo "-----------------------------------------"
echo "cd /boot && wget https://raw.githubusercontent.com/lonix/BUUX/master/Buux.sh -O Buux.sh && chmod +x Buux.sh"
echo "-----------------------------------------"
echo -n "Continue script running this version ? (y/n)"
read quit
if [ "$quit" != "y" ]; then
exit 0
fi
fi
##Set parameters and if read config
##Defaults
bridge="br0"
rootDir="/mnt/cache/VM"
##check for and read a configfile
if [ -f "Buux.conf" ]; then
source Buux.conf;
fi
##Functions
function manualSteps() {
echo "------------------------------------------"
read -p "Press [Enter] To Start your Installation"
echo "------------------------------------------"
xl create $rootDir/$domain/$domain.cfg -c
clear
echo "------------------------------------------"
echo "I Hope everything when well, ill continue
my work now"
echo "------------------------------------------"
}
function vmdk_Hack(){
VMDK=$1
FULLSIZE=`stat -c%s "$VMDK"`
VMDKFOOTER=$[$FULLSIZE - 0x400]
VMDKFOOTERVER=$[$VMDKFOOTER + 4]
case "`xxd -ps -s $VMDKFOOTERVER -l 1 \"$VMDK\"`" in
03)
echo -e "$VMDK is VMDK3.\n Patching to VMDK2."
echo -en '\x02' | dd conv=notrunc oflag=seek_bytes seek=$[VMDKFOOTERVER] of="$VMDK" 2> /dev/null || echo 'Patc$
;;
02)
echo -e "$VMDK is VMDK2.\n Patching to VMDK3."
echo -en '\x03' | dd conv=notrunc oflag=seek_bytes seek=$[VMDKFOOTERVER] of="$VMDK" 2> /dev/null || echo 'Patc$
;;
*) # default
echo "$VMDK is not VMDK3 or patched-VMDK3."
;;
esac
}
function create_Readme(){
readme="$rootDir"/"$domain"/README.md
touch "$readme"
echo "**$osName**" > $readme
echo "" >> $readme
echo "MAC: $mac" >> $readme
echo "" >> $readme
echo "* $cpuCount vCPUs" >> $readme
echo "* $memory MB RAM" >> $readme
echo "* $diskSize GB Sysdisk" >> $readme
}
function createDomain(){
## Create and enter domain
mkdir -p $rootDir/$domain
cd $rootDir/$domain
}
function configAsk() {
echo "
------------------------------------------
==========================================
BBBBB UU UU UU UU XX XX
BB B UU UU UU UU XX XX
BBBBBB UU UU UU UU XXXX
BB BB UU UU UU UU XX XX
BBBBBB UUUUU UUUUU XX XX
-----Bash Ubuntu unRAID/XEN-----
Written By Stian Larsen (aka. lonix)
------------------------------------------
We will Start by asking you some Questions:
RAM should be Defined in MB and the Power of 2
Disk should be Defined in GB
Note: If planning to install pre-imaged appliances.
disk size is ignored, but still required to enter.
------------------------------------------
"
echo -n "Domainname: "
read domain
echo -n "vCPUs: "
read cpuCount
echo -n "RAM(MB): "
read memory
echo -n "Disk(GB):"
read diskSize
echo -n "Autostart on Boot: (y/n): "
read autostart
echo ""
echo ""
echo "Currently Supported Operating System's are:"
echo "------------------------------------------"
echo "1. Ubuntu Server 12.04 LTS (ubuntu12)"
echo "2. Ubuntu Server 14.04 LTS (ubuntu14)"
echo "3. CentOS6.5 (cent65)"
echo "4. Debian 6 LTS (debian6)"
echo "5. Debian 7 (debian7)"
echo "6. IronicBadger's ArchVM v.5 (ibarch5)[RECOMMENDED]"
echo "7. Tretflix 1.3 (tretflix13)"
echo "8. Turnkey Owncloud (owncloud13)"
echo "9. Turnkey MySQL (mysql13)"
#echo "0. Blank disk and config with boot and install version"
echo "------------------------------------------"
echo -n "OperatingSystem: "
read osSelected
##TODO: There should probably be some sort of quality control here at a later stage
}
function config_General(){
mac=$(echo 00:16:3E$(hexdump -n3 -e '/1 ":%02X"' /dev/random))
touch $rootDir/$domain/$domain.cfg
echo "name = \"$domain\"" > $rootDir/$domain/$domain.cfg
echo "vcpus = '$cpuCount'" >> $rootDir/$domain/$domain.cfg
echo "memory = '$memory'" >> $rootDir/$domain/$domain.cfg
echo "vif = [ 'bridge=$bridge,mac=$mac' ]" >> $rootDir/$domain/$domain.cfg
echo "disk = ['file:$rootDir/$domain/$domain.img,xvda,w' ]" >> $rootDir/$domain/$domain.cfg
}
function xenman_Register(){
xenman register $rootDir/$domain/$domain.cfg
}
function xenman_Autostart() {
if [ "$autostart" == "y" ]; then
xenman autostart $domain
# echo "The domain has been configured to boot with $HOSTNAME"
fi
}
function create_Detached(){
sleep 3
xl create $rootDir/$domain/$domain.cfg
}
function attach_WhenDone(){
clear
echo "All Done, to attach to the console use [xl console $domain] on $HOSTNAME Console"
echo -n "Do you want to do that now ? (y/n)"
read attach
if [ $attach = y ] ; then xl console $domain; else echo "Bye bye... Enjoy and spread the word" ; fi
}
function disk_Create(){
truncate -s ${diskSize}G $domain.img
}
function disk_Format(){
mkfs ext4 -F $domain.img
}
function disk_Mount(){
mkdir /tmp/$domain
mount -o loop,rw,sync $domain.img /tmp/$domain
}
function disk_Umount(){
umount /tmp/$domain
rm -r $domain
}
function config_Add_Pygrub(){
echo "bootloader = \"pygrub\"" >> $rootDir/$domain/$domain.cfg
}
function config_Install_Ubuntu(){
echo "extra = \"debian-installer/exit/always_halt=true -- console=hvc0\"" >> $rootDir/$domain/$domain.cfg
echo "kernel = \"$rootDir/$domain/vmlinuz\"" >> $rootDir/$domain/$domain.cfg
echo "ramdisk = \"$rootDir/$domain/initrd.gz\"" >> $rootDir/$domain/$domain.cfg
}
function config_Install_Centos(){
echo "on_reboot = \"destroy\"" >> $rootDir/$domain/$Domain.cfg
echo "kernel = \"$rootDir/$domain/vmlinuz\"" >> $rootDir/$domain/$domain.cfg
echo "ramdisk = \"$rootDir/$domain/initrd.img\"" >> $rootDir/$domain/$domain.cfg
}
function config_Boot_Ubuntu(){
sed -i '/kernel = /d' $rootDir/$domain/$domain.cfg
sed -i '/ramdisk = /d' $rootDir/$domain/$domain.cfg
sed -i '/extra = /d' $rootDir/$domain/$domain.cfg
echo "bootloader = \"pygrub\"" >> $rootDir/$domain/$domain.cfg
}
function config_Boot_Centos(){
sed -i '/kernel = /d' $rootDir/$domain/$domain.cfg
sed -i '/ramdisk = /d' $rootDir/$domain/$domain.cfg
sed -i '/on_reboot = /d' $rootDir/$domain/$domain.cfg
echo "bootloader = \"pygrub\"" >> $rootDir/$domain/$domain.cfg
}
##Asks Questions to make up data of config
while [ "$configIsGood" != "y" ]
do
clear
configAsk
echo -n "Is this correct ?(y/n)"
read configIsGood
done
##Actions based of Selected OS.
case "$osSelected" in
1|ubuntu12)
#Creates folder
createDomain
#Set Name
osName="Ubuntu LTS 12.04"
#Compiles Initial Config
config_General
config_Install_Ubuntu
#Download section
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-amd64/current/images/netboot/xen/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/precise-updates/main/installer-amd64/current/images/netboot/xen/vmlinuz
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/ubuntu.png
cp ubuntu.png /boot/config/domains/$domain.png
##Create the Drive
disk_Create
#Allows manual parts of the installation in console
manualSteps
#Reconfigures domain.cfg to use grub rather than kernel
config_Boot_Ubuntu
#Creates README.md
create_Readme
#Registers VM with Xenman
xenman_Register
#start it upagain
create_Detached
#Ask to connect
attach_WhenDone
#Autostart if chosen
xenman_Autostart
#cleanup
rm initrd.gz
rm vmlinuz
;;
2|ubuntu14)
createDomain
osName="Ubuntu LTS 14.04"
config_General
config_Install_Ubuntu
wget http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/xen/initrd.gz
wget http://archive.ubuntu.com/ubuntu/dists/trusty/main/installer-amd64/current/images/netboot/xen/vmlinuz
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/ubuntu.png
cp ubuntu.png /boot/config/domains/$domain.png
disk_Create
manualSteps
config_Boot_Ubuntu
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm initrd.gz
rm vmlinuz
;;
3|cent65)
createDomain
osName="CentOS 6.5"
config_General
config_Install_Centos
wget http://mirror.symnds.com/CentOS/6.5/os/x86_64/images/pxeboot/initrd.img
wget http://mirror.symnds.com/CentOS/6.5/os/x86_64/images/pxeboot/vmlinuz
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/centos.png
cp centos.png /boot/config/domains/$domain.png
disk_Create
echo "When Prompted for a mirror to install from, you can use: "
echo "http://mirrors.sonic.net/centos/6/os/x86_64/"
manualSteps
config_Boot_Centos
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm initrd.img
rm vmlinuz
;;
4|debian6)
createDomain
osName="Debian 6 LTS"
config_General
config_Install_Ubuntu
wget http://ftp.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/netboot/xen/vmlinuz
wget http://ftp.debian.org/debian/dists/squeeze/main/installer-amd64/current/images/netboot/xen/initrd.gz
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/debian.png
cp debian.png /boot/config/domains/$domain.png
disk_Create
manualSteps
config_Boot_Ubuntu
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm initrd.gz
rm vmlinuz
;;
5|debian7)
createDomain
osName="Debian 7"
config_General
config_Install_Ubuntu
wget http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/vmlinuz
wget http://ftp.debian.org/debian/dists/wheezy/main/installer-amd64/current/images/netboot/xen/initrd.gz
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/debian.png
cp debian.png /boot/config/domains/$domain.png
disk_Create
manualSteps
config_Boot_Ubuntu
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm initrd.gz
rm vmlinuz
;;
ibarch4)
createDomain
osName="Ironic Badger's ArchVM v.4"
config_General
config_Add_Pygrub
if [[ ! -f ArchVM_v4.zip ]]; then wget https://lonix.me/mirror/archvm/ArchVM_v4.zip; fi
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/archlinux.png
unzip ArchVM_v4.zip
mv "ArchVM/arch.img" "$domain.img"
cp archlinux.png /boot/config/domains/$domain.png
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm -r ArchVM
;;
6|ibarch5)
createDomain
osName="Ironic Badger's ArchVM v.5"
config_General
config_Add_Pygrub
if [[ ! -f ArchVM_v5.zip ]]; then wget http://repo.ktz.me/archVM/ArchVM_v5.zip; fi
if [[ ! -f ArchVM_v5.zip ]]; then wget https://lonix.me/mirror/archvm/ArchVM_v5.zip; fi
wget https://raw.githubusercontent.com/lonix/BUUX/master/img/archlinux.png
unzip ArchVM_v5.zip
mv "ArchVM/arch.img" "$domain.img"
cp archlinux.png /boot/config/domains/$domain.png
create_Readme
xenman_Register
create_Detached
xenman_Autostart
attach_WhenDone
rm -r ArchVM
;;
7|tretflix13)
createDomain
osName="Tretflix 1.3"
config_General
config_Add_Pygrub
if [[ ! -f Tretflix-v1.3_x64-NAS.zip ]]; then wget https://lonix.me/mirror/tretflix/Tretflix-v1.3_x64-NAS.zip; fi
if [[ ! -f Tretflix-v1.3_x64-NAS.zip ]]; then wget http://repo.ktz.me/tretflix/Tretflix-v1.3_x64-NAS.zip; fi
if [[ ! -f ubuntu.png ]]; then wget https://raw.githubusercontent.com/lonix/BUUX/master/img/ubuntu.png; fi
unzip Tretflix-v1.3_x64-NAS.zip
tar xvf Tretflix-v1.3_x64-NAS.ova
if ! command -v xxd>/dev/null; then wget https://lonix.me/mirror/xxd.txz && installpkg xxd.txz; fi
vmdk_Hack Tretflix-v1.3_x64-NAS-disk1.vmdk
/usr/lib/xen/bin/qemu-img convert -f vmdk -O raw "Tretflix-v1.3_x64-NAS-disk1.vmdk" "$domain.img"
cp ubuntu.png /boot/config/domains/$domain.png
create_Readme
xenman_Register
create_Detached
xenman_Autostart
rm Tretflix-v1.3_x64-NAS*
if [[ -f xxd.txz ]]; then rm xxd.txz ; fi
attach_WhenDone
;;
8|owncloud13)
createDomain
osName="Turkey 13 - Owncloud"
config_General
config_Add_Pygrub
if [[ ! -f turnkey-owncloud-13.0-wheezy-amd64-vmdk.zip ]]; then wget http://downloads.sourceforge.net/project/turnkeylinux/vmdk/turnkey-owncloud-13.0-wheezy-amd64-vmdk.zip; fi
if [[ ! -f owncloud.png ]]; then wget https://raw.githubusercontent.com/lonix/BUUX/master/img/owncloud.png; fi
if ! command -v xxd>/dev/null; then wget https://lonix.me/mirror/xxd.txz && installpkg xxd.txz; fi
unzip turnkey-owncloud-13.0-wheezy-amd64-vmdk.zip
/usr/lib/xen/bin/qemu-img convert -f vmdk -O raw turnkey-owncloud-13.0-wheezy-amd64/turnkey-owncloud-13.0-wheezy-amd64.vmdk "$domain.img"
cp owncloud.png /boot/config/domains/$domain.png
create_Readme
xenman_Register
create_Detached
xenman_Autostart
rm -r turnkey-owncloud-13.0-wheezy-amd64*
if [[ -f xxd.txz ]]; then rm xxd.txz ; fi
attach_WhenDone
;;
9|mysql13)
createDomain
osName="Turkey 13 - MySQL"
config_General
config_Add_Pygrub
if [[ ! -f turnkey-mysql-13.0-wheezy-amd64-vmdk.zip ]]; then wget http://downloads.sourceforge.net/project/turnkeylinux/vmdk/turnkey-mysql-13.0-wheezy-amd64-vmdk.zip; fi
if [[ ! -f mysql.png ]]; then wget https://raw.githubusercontent.com/lonix/BUUX/master/img/mysql.png; fi
if ! command -v xxd>/dev/null; then wget https://lonix.me/mirror/xxd.txz && installpkg xxd.txz; fi
unzip turnkey-mysql-13.0-wheezy-amd64-vmdk.zip
/usr/lib/xen/bin/qemu-img convert -f vmdk -O raw turnkey-mysql-13.0-wheezy-amd64/turnkey-mysql-13.0-wheezy-amd64.vmdk "$domain.img"
cp mysql.png /boot/config/domains/$domain.png
create_Readme
xenman_Register
create_Detached
xenman_Autostart
rm -r turnkey-mysql-13.0-wheezy-amd64*
if [[ -f xxd.txz ]]; then rm xxd.txz ; fi
attach_WhenDone
;;
0|blank)
createDomain
osName="No Operatingsystem."
config_General
config_Boot_Ubuntu
mv $domain.cfg ${domain}-boot.cfg
config_General
config_Install_Ubuntu
mv $domain.cfg ${domain}-install.cfg
disk_Create
create_Readme
;;
esac