xentaur

view build-xenomips-image @ 68:f652fab38c7a

ec2 parameters small fixes
author Igor Chubin <igor@chub.in>
date Mon Jan 11 19:36:56 2010 +0200 (2010-01-11)
parents 6471afbee150
children
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=yes
4 XENOMIPS_FS_BUILD=yes
5 CONFIG_FS_BUILD=yes
6 IOS_FS_BUILD=yes
8 process_args()
9 {
10 true
11 }
13 XENOMIPS_DIR="files/"
14 XENOMIPS_IMAGES_DIR="/xentaur/images/"
15 IOS_DIR="/xentaur/ios/"
16 SSH_OPEN_KEY=files/id_dsa.pub
18 #Xenomips FS
19 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
20 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
22 # Config FS
23 CONFIG_FS_SIZE=1000k
24 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
25 CONFIG_FS_NUMBER=10 # the number of the Xenomips instance
27 # IOS FS
28 IOS_FS_SIZE=2048k
29 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
31 DEBIAN_MIRROR=http://127.0.0.1:9999/debian
32 DISTRO=lenny
33 PACKAGES="udev openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntp nmap netcat socat"
34 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
35 DYNAMIPS_BUILD_DIR=dynamips/
36 PIXEMU_SOURCES=http://xgu.ru/download/pemu_public2007-07-02.tar.bz2
37 PIXEMU_BUILD_DIR=dynamips/
38 KERNEL_VERSION="2.6.26-2-xen-686 2.6.18-6-xen-686" #`uname -r`
40 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
41 WORK_DIR2=/tmp/xenomips-build
43 myecho()
44 {
45 echo '**************************'
46 echo "$@"
47 echo '**************************'
48 }
50 build_and_install_dynamips()
51 {
52 OLD_PWD="`pwd`"
53 DESTDIR=${WORK_DIR}/usr
55 if echo $DYNAMIPS_BUILD | grep -qi ^y
56 then
57 rm -rf ${DYNAMIPS_BUILD_DIR}/
58 mkdir -p ${DYNAMIPS_BUILD_DIR}/
59 cd ${DYNAMIPS_BUILD_DIR}/
60 wget $DYNAMIPS_SOURCES
61 tar xfz dynamips*tar*
62 cd dynamips*/
63 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
64 make
65 else
66 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
67 fi
68 make install DESTDIR=${DESTDIR}
69 cd ${OLD_PWD}
70 }
72 build_and_install_pixemu()
73 {
74 DESTDIR=${WORK_DIR}/usr/local/pixemu
75 mkdir -p $DESTDIR
76 cp /home/igor/pemu/pemu/* $DESTDIR
77 }
80 if [ $(id -u) != 0 ]
81 then
82 echo You are not root.
83 echo Please, log in as root or run the script with sudo
84 ecit 1
85 fi
88 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
89 then
90 myecho Preparing the Xenomips filesystem
91 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
92 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
93 mkdir -p ${WORK_DIR}
94 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
95 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
96 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
97 unset LANG
98 apt-get -y --force-yes install ${PACKAGES}
99 /etc/init.d/ssh stop
100 cat <<FSTAB > /etc/fstab
101 proc /proc proc defaults 0 0
102 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
104 /dev/hda1 / ext3 ro 0 0
105 /dev/hda2 /xenomips/ios ext3 ro 0 0
106 /dev/hda3 /xenomips/config ext3 rw 0 0
107 FSTAB
108 mkdir -p /data/Cisco_IOS /xenomips
110 cat <<EOF > /etc/sysctl.conf
111 net/ipv4/ip_forward=1
112 EOF
114 cat <<'INTERFACES' > /etc/network/interfaces
115 auto lo eth0
117 iface lo inet loopback
118 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
120 #iface eth0 inet dhcp
121 INTERFACES
123 cat <<EOF >> /etc/inittab
124 1h:2345:respawn:/sbin/getty 38400 hvc0
125 EOF
127 cat <<EOF >> /etc/modules
128 iptable_nat
129 EOF
131 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
132 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
133 rm /etc/rc2.d/S*quagga
134 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
135 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
136 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
137 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
138 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
139 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
140 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
142 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
143 mv /etc/quagga /etc/quagga.ORIG
144 ln -s /xenomips/config/etc/quagga /etc/quagga
146 mkdir -p /xenomips/{ios,config} /var/lib/xenomips /root/.ssh
148 cat <<PROFILE >> /root/.profile
149 TERM=linux
150 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
151 PROFILE
152 SCRIPT
154 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
155 do
156 cp -R /lib/modules/${kernel_version} ${WORK_DIR}/lib/modules
157 done
159 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
160 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
161 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
163 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
164 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
166 build_and_install_dynamips
167 #build_and_install_pixemu
168 kill $(lsof +D ${WORK_DIR} | awk '{print $2}' | grep -v PID)
169 pkill ntpd
170 umount ${WORK_DIR}
171 fi
174 if echo $CONFIG_FS_BUILD | grep -qi ^y
175 then
176 mkdir -p ${WORK_DIR}
177 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
178 mkdir -p ${WORK_DIR2}
179 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
180 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
181 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
182 cp -a ${WORK_DIR}/usr/local/pixemu ${WORK_DIR2}/pixemu
183 umount ${WORK_DIR}
185 myecho Preparing the Xenomips config filesystem
186 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
187 mkfs.ext3 -F ${CONFIG_FS_NAME}
189 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
190 mkdir -p ${WORK_DIR}/{dynamips,etc}
191 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
192 mv ${WORK_DIR2}/pixemu ${WORK_DIR}/
193 dd if=/dev/zero of=${WORK_DIR}/pixemu/FLASH bs=1k count=16k
194 umount ${WORK_DIR}
196 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
197 for i in `seq 0 $CONFIG_FS_NUMBER`
198 do
199 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
200 done
201 fi
204 if echo $IOS_FS_BUILD | grep -qi ^y
205 then
206 myecho Preparing the filesystem with the IOSes
207 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
208 mkfs.ext3 -F ${IOS_FS_NAME}
209 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
210 cp ${IOS_DIR}/* ${WORK_DIR}
211 umount ${WORK_DIR}
212 fi