-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_image.sh
executable file
·102 lines (88 loc) · 1.82 KB
/
create_image.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
#!/bin/bash
usage()
{
echo "Usage: $0 -n vm_number -m memory_size -b backup -d disk_space_added -s ssd"
exit
}
while getopts n:m:b:d:s: option
do
case $option in
n)
NUMBER=$OPTARG
;;
m)
MEMORY=$OPTARG
;;
b)
BACKUP=$OPTARG
;;
d)
DISK=$OPTARG
;;
s)
SSD=$OPTARG
;;
*) usage
;;
esac
done
if [[ -z $MEMORY ]]
then
MEMORY=1024
fi
if [[ -z $SSH ]]
then
SSH=0
fi
if [[ -z $BACKUP ]]
then
BACKUP=0
fi
if [[ -z $DISK ]]
then
DISK=0
fi
if [[ -z $SSD ]]
then
SSD=0
fi
DISK=${DISK}Gb
PASSWORD=$(pwgen -s 12 1)
DB_PASSWORD=$(pwgen -s 12 1)
MURMUR_PASSWORD=$(pwgen -s 12 1)
HOST="vm${NUMBER}"
# Reglage de la gateway
DOMU_IP="10.10.10.${NUMBER}"
GATEWAY=$(echo $DOMU_IP | awk -F. '{print $1"."$2"."$3"."$4 + 127}')
VM_MEMORY=${MEMORY}Mb
RETOUR=$(xen-create-image \
--install-method=tar \
--install-source=/etc/xen-tools/base.tar \
--hostname=$HOST \
--ip=$DOMU_IP \
--arch=amd64 \
--dist=squeeze \
--gateway=$GATEWAY \
--role=minecraft-hook \
--role-args="$(mkpasswd ${PASSWORD}) $MEMORY $DOMU_IP $BACKUP $DB_PASSWORD $MURMUR_PASSWORD $SSD" \
--size=$DISK \
--memory=$VM_MEMORY)
ROOT_PASS=$(echo $RETOUR | egrep -o 'Root Password.*' | awk '{print $4}')
echo "${ROOT_PASS}"
echo "${PASSWORD}"
echo "${DB_PASSWORD}"
echo "${MURMUR_PASSWORD}"
FILE=/etc/xen/${HOST}.cfg
if [[ -e /dev/vg_ssd && $SSD -gt 0 ]]
then
lvcreate -L ${SSD}G -n ${HOST}-ssd vg_ssd >>/dev/null 2>&1
mkfs.ext3 /dev/vg_ssd/${HOST}-ssd >>/dev/null 2>&1
sed -i "19a 'phy:/dev/vg_ssd/${HOST}-ssd,xvda3,w'," ${FILE} >>/dev/null 2>&1
mkdir -p /mnt/ssd-install
mount /dev/vg_ssd/${HOST}-ssd /mnt/ssd-install/
chown -R 1000:1000 /mnt/ssd-install/
umount /mnt/ssd-install
fi
xm create ${FILE} >>/dev/null 2>&1
touch /opt/firewall/vm/${NUMBER}
/opt/firewall/firewall.sh restart >>/dev/null 2>&1