rev |
line source |
igor@0
|
1 #!/bin/sh
|
igor@0
|
2
|
nata@31
|
3 DYNAMIPS_BUILD=no
|
igor@43
|
4 XENOMIPS_FS_BUILD=no
|
igor@45
|
5 CONFIG_FS_BUILD=no
|
igor@45
|
6 IOS_FS_BUILD=yes
|
igor@0
|
7
|
igor@7
|
8 XENOMIPS_DIR="files/"
|
igor@40
|
9 XENOMIPS_IMAGES_DIR="/xen/images/"
|
igor@40
|
10 IOS_DIR="ios/"
|
igor@15
|
11 SSH_OPEN_KEY=files/id_dsa.pub
|
igor@7
|
12
|
igor@0
|
13 #Xenomips FS
|
igor@0
|
14 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
|
igor@7
|
15 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
|
igor@0
|
16
|
igor@0
|
17 # Config FS
|
igor@7
|
18 CONFIG_FS_SIZE=1000k
|
igor@18
|
19 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
|
igor@43
|
20 CONFIG_FS_NUMBER=10 # the number of the Xenomips instance
|
igor@0
|
21
|
igor@0
|
22 # IOS FS
|
igor@0
|
23 IOS_FS_SIZE=2048k
|
igor@7
|
24 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
|
igor@0
|
25
|
igor@42
|
26 DEBIAN_MIRROR=ftp://debian.org.ua/debian
|
igor@42
|
27 DISTRO=etch
|
igor@41
|
28 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 openntpd"
|
igor@0
|
29 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
|
igor@0
|
30 DYNAMIPS_BUILD_DIR=dynamips/
|
igor@0
|
31 KERNEL_VERSION=`uname -r`
|
igor@0
|
32
|
igor@0
|
33
|
igor@0
|
34 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
|
igor@7
|
35 WORK_DIR2=/tmp/xenomips-build
|
igor@0
|
36
|
igor@17
|
37 myecho()
|
igor@17
|
38 {
|
igor@17
|
39 echo '**************************'
|
igor@17
|
40 echo "$@"
|
igor@17
|
41 echo '**************************'
|
igor@17
|
42 }
|
igor@17
|
43
|
igor@0
|
44 build_and_install_dynamips()
|
igor@0
|
45 {
|
igor@0
|
46 OLD_PWD="`pwd`"
|
igor@20
|
47 DESTDIR=${WORK_DIR}/usr
|
igor@0
|
48
|
igor@0
|
49 if echo $DYNAMIPS_BUILD | grep -qi ^y
|
igor@0
|
50 then
|
igor@0
|
51 rm -rf ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
52 mkdir -p ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
53 cd ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
54 wget $DYNAMIPS_SOURCES
|
igor@0
|
55 tar xfz dynamips*tar*
|
igor@0
|
56 cd dynamips*/
|
igor@0
|
57 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
|
igor@0
|
58 make
|
igor@0
|
59 else
|
igor@0
|
60 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
|
igor@0
|
61 fi
|
igor@20
|
62 make install DESTDIR=${DESTDIR}
|
igor@0
|
63 cd ${OLD_PWD}
|
igor@0
|
64 }
|
igor@0
|
65
|
igor@43
|
66 if [ $(id -u) != 0 ]
|
igor@43
|
67 then
|
igor@43
|
68 echo You are not root.
|
igor@43
|
69 echo Please, log in as root or run the script with sudo
|
igor@43
|
70 ecit 1
|
igor@43
|
71 fi
|
igor@43
|
72
|
igor@43
|
73
|
igor@43
|
74 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
|
igor@43
|
75 then
|
igor@43
|
76 myecho Preparing the Xenomips filesystem
|
igor@43
|
77 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
|
igor@43
|
78 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
|
igor@43
|
79 mkdir -p ${WORK_DIR}
|
igor@43
|
80 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
|
igor@43
|
81 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
|
igor@43
|
82 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
|
igor@0
|
83 unset LANG
|
igor@0
|
84 apt-get -y --force-yes install ${PACKAGES}
|
igor@0
|
85 /etc/init.d/ssh stop
|
igor@0
|
86 cat <<FSTAB > /etc/fstab
|
igor@11
|
87 proc /proc proc defaults 0 0
|
igor@11
|
88 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
|
igor@11
|
89
|
igor@0
|
90 /dev/hda1 / ext3 ro 0 0
|
igor@0
|
91 /dev/hda2 /xenomips/ios ext3 ro 0 0
|
igor@0
|
92 /dev/hda3 /xenomips/config ext3 rw 0 0
|
igor@0
|
93 FSTAB
|
igor@0
|
94 mkdir -p /data/Cisco_IOS /xenomips
|
igor@0
|
95
|
igor@40
|
96 cat <<EOF > /etc/sysctl.conf
|
igor@40
|
97 net/ipv4/ip_forward=1
|
igor@40
|
98 EOF
|
igor@40
|
99
|
igor@0
|
100 cat <<'INTERFACES' > /etc/network/interfaces
|
igor@0
|
101 auto lo eth0
|
igor@0
|
102
|
igor@0
|
103 iface lo inet loopback
|
igor@0
|
104 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
|
igor@0
|
105
|
igor@13
|
106 #iface eth0 inet dhcp
|
igor@0
|
107 INTERFACES
|
igor@0
|
108
|
igor@0
|
109 echo /usr/local/bin/xenomips.sh > /etc/rc.local
|
igor@0
|
110 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
|
igor@0
|
111 rm /etc/rc2.d/S*quagga
|
igor@0
|
112
|
igor@7
|
113 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
|
igor@7
|
114 mv /etc/quagga /etc/quagga.ORIG
|
igor@7
|
115 ln -s /xenomips/config/etc/quagga /etc/quagga
|
igor@0
|
116
|
igor@7
|
117 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
|
igor@0
|
118
|
igor@7
|
119 cat <<PROFILE >> /root/.profile
|
igor@7
|
120 TERM=linux
|
igor@0
|
121 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
|
igor@7
|
122 PROFILE
|
igor@0
|
123 SCRIPT
|
igor@0
|
124
|
igor@43
|
125 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
|
igor@43
|
126 do
|
igor@43
|
127 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
|
igor@43
|
128 done
|
igor@0
|
129
|
igor@43
|
130 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
|
igor@43
|
131 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
|
igor@43
|
132 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
|
igor@0
|
133
|
igor@43
|
134 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@43
|
135 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@0
|
136
|
igor@43
|
137 build_and_install_dynamips
|
igor@43
|
138 umount ${WORK_DIR}
|
igor@43
|
139 fi
|
igor@0
|
140
|
igor@0
|
141
|
igor@0
|
142 if echo $CONFIG_FS_BUILD | grep -qi ^y
|
igor@0
|
143 then
|
igor@43
|
144 mkdir -p ${WORK_DIR}
|
igor@43
|
145 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
|
igor@43
|
146 mkdir -p ${WORK_DIR2}
|
igor@43
|
147 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
|
igor@43
|
148 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
|
igor@43
|
149 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
|
igor@43
|
150 umount ${WORK_DIR}
|
igor@43
|
151
|
igor@18
|
152 myecho Preparing the Xenomips config filesystem
|
igor@41
|
153 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
|
igor@0
|
154 mkfs.ext3 -F ${CONFIG_FS_NAME}
|
igor@14
|
155
|
igor@14
|
156 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
|
igor@14
|
157 mkdir -p ${WORK_DIR}/etc
|
igor@14
|
158 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
|
igor@14
|
159 umount ${WORK_DIR}
|
igor@14
|
160
|
igor@18
|
161 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
|
igor@18
|
162 for i in `seq 1 $CONFIG_FS_NUMBER`
|
igor@18
|
163 do
|
igor@18
|
164 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
|
igor@18
|
165 done
|
igor@0
|
166 fi
|
igor@0
|
167
|
igor@0
|
168
|
igor@0
|
169 if echo $IOS_FS_BUILD | grep -qi ^y
|
igor@0
|
170 then
|
igor@18
|
171 myecho Preparing the filesystem with the IOSes
|
igor@18
|
172 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
|
igor@0
|
173 mkfs.ext3 -F ${IOS_FS_NAME}
|
igor@0
|
174 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
|
igor@0
|
175 cp ${IOS_DIR}/* ${WORK_DIR}
|
igor@0
|
176 umount ${WORK_DIR}
|
igor@0
|
177 fi
|
igor@0
|
178
|