forked from zstackio/zstack-vyos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkvyos.sh
110 lines (92 loc) · 2.44 KB
/
mkvyos.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
#!/bin/bash
export LIBGUESTFS_BACKEND=direct
which guestfish > /dev/null
if [ $? -ne 0 ]; then
echo "guestfish is not installed"
exit 1
fi
which qemu-img > /dev/null
if [ $? -ne 0 ]; then
echo "qemu-img is not installed"
exit 1
fi
usage() {
echo "
USAGE:
$0 path_to_image path_to_zvr_tar"
}
if [ -z $1 ]; then
echo "missing parameter path_to_image"
usage
exit 1
fi
if [ ! -f $1 ]; then
echo "cannot find the image"
exit 1
fi
if [ -z $2 ]; then
echo "missing parameter path_to_zvr_tar"
usage
exit 1
fi
if [ ! -f $2 ]; then
echo "cannot find the zvr.tar.gz"
exit 1
fi
imgfile=$1
isVmdk=0
if echo $1 | grep -q -i '\.vmdk$'; then
isVmdk=1
imgfile=${1%%.vmdk}.qcow2
qemu-img convert -f vmdk -O qcow2 "$1" "$imgfile"
fi
set -e
tmpdir=$(mktemp -d)
atexit() {
/bin/rm -fr $tmpdir
[ $isVmdk -eq 1 ] && /bin/rm -f $imgfile || true
}
trap atexit EXIT SIGHUP SIGINT SIGTERM
tar xzf $2 -C $tmpdir
ZVR=$tmpdir/zvr
ZVRBOOT=$tmpdir/zvrboot
ZVRSCRIPT=$tmpdir/zstack-virtualrouteragent
HAPROXY=$tmpdir/haproxy
SBIN_DIR=/opt/vyatta/sbin
VERSION=`date +%Y%m%d`
guestfish <<_EOF_
add $imgfile
run
mount /dev/sda1 /
write /etc/version $VERSION
upload $ZVR $SBIN_DIR/zvr
upload $ZVRBOOT $SBIN_DIR/zvrboot
upload $ZVRSCRIPT /etc/init.d/zstack-virtualrouteragent
upload $HAPROXY $SBIN_DIR/haproxy
upload -<<END /opt/vyatta/etc/config/scripts/vyatta-postconfig-bootup.script
#!/bin/bash
chmod +x $SBIN_DIR/zvrboot
chmod +x $SBIN_DIR/zvr
chmod +x /etc/init.d/zstack-virtualrouteragent
chmod +x $SBIN_DIR/haproxy
mkdir -p /home/vyos/zvr
chown vyos:users /home/vyos/zvr
chown vyos:users $SBIN_DIR/zvr
chown vyos:users $SBIN_DIR/haproxy
$SBIN_DIR/zvrboot >/home/vyos/zvr/zvrboot.log 2>&1 < /dev/null &
exit 0
END
download /boot/grub/grub.cfg /tmp/grub.cfg
! sed -e 's/^set[[:space:]]\+timeout[[:space:]]*=[[:space:]]*[[:digit:]]\+/set timeout=0/g' -e '/^echo.*Grub menu/,/^fi$/d' /tmp/grub.cfg > /tmp/grub.cfg.new
upload /tmp/grub.cfg.new /boot/grub/grub.cfg
download /etc/security/limits.conf /tmp/limits.conf
! grep -w "vyos" /tmp/limits.conf | grep soft || echo "vyos soft nofile 1000000" >> /tmp/limits.conf
! grep -w "vyos" /tmp/limits.conf | grep hard || echo "vyos hard nofile 1000000" >> /tmp/limits.conf
upload /tmp/limits.conf /etc/security/limits.conf
_EOF_
/bin/rm -rf $tmpdir
if [ $isVmdk -eq 1 ]; then
/bin/rm -f "$1"
qemu-img convert -f qcow2 -O vmdk "$imgfile" "$1"
fi
echo "successfully installed $2 to vyos image $1"