xentaur

view build-xenomips-image @ 57:548bd71dc5fb

+ example
author igor
date Sat Nov 10 20:00:12 2007 +0200 (2007-11-10)
parents 129c08025d07
children 6471afbee150
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=no
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="/xen/images/"
15 IOS_DIR="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=ftp://debian.org.ua/debian
32 DISTRO=etch
33 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntpd nmap netcat socat"
34 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
35 DYNAMIPS_BUILD_DIR=dynamips/
36 KERNEL_VERSION=`uname -r`
39 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
40 WORK_DIR2=/tmp/xenomips-build
42 myecho()
43 {
44 echo '**************************'
45 echo "$@"
46 echo '**************************'
47 }
49 build_and_install_dynamips()
50 {
51 OLD_PWD="`pwd`"
52 DESTDIR=${WORK_DIR}/usr
54 if echo $DYNAMIPS_BUILD | grep -qi ^y
55 then
56 rm -rf ${DYNAMIPS_BUILD_DIR}/
57 mkdir -p ${DYNAMIPS_BUILD_DIR}/
58 cd ${DYNAMIPS_BUILD_DIR}/
59 wget $DYNAMIPS_SOURCES
60 tar xfz dynamips*tar*
61 cd dynamips*/
62 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
63 make
64 else
65 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
66 fi
67 make install DESTDIR=${DESTDIR}
68 cd ${OLD_PWD}
69 }
71 if [ $(id -u) != 0 ]
72 then
73 echo You are not root.
74 echo Please, log in as root or run the script with sudo
75 ecit 1
76 fi
79 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
80 then
81 myecho Preparing the Xenomips filesystem
82 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
83 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
84 mkdir -p ${WORK_DIR}
85 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
86 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
87 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
88 unset LANG
89 apt-get -y --force-yes install ${PACKAGES}
90 /etc/init.d/ssh stop
91 cat <<FSTAB > /etc/fstab
92 proc /proc proc defaults 0 0
93 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
95 /dev/hda1 / ext3 ro 0 0
96 /dev/hda2 /xenomips/ios ext3 ro 0 0
97 /dev/hda3 /xenomips/config ext3 rw 0 0
98 FSTAB
99 mkdir -p /data/Cisco_IOS /xenomips
101 cat <<EOF > /etc/sysctl.conf
102 net/ipv4/ip_forward=1
103 EOF
105 cat <<'INTERFACES' > /etc/network/interfaces
106 auto lo eth0
108 iface lo inet loopback
109 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
111 #iface eth0 inet dhcp
112 INTERFACES
114 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
115 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
116 rm /etc/rc2.d/S*quagga
117 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
118 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
119 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
120 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
121 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
122 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
123 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
125 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
126 mv /etc/quagga /etc/quagga.ORIG
127 ln -s /xenomips/config/etc/quagga /etc/quagga
129 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
131 cat <<PROFILE >> /root/.profile
132 TERM=linux
133 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
134 PROFILE
135 SCRIPT
137 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
138 do
139 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
140 done
142 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
143 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
144 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
146 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
147 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
149 build_and_install_dynamips
150 umount ${WORK_DIR}
151 fi
154 if echo $CONFIG_FS_BUILD | grep -qi ^y
155 then
156 mkdir -p ${WORK_DIR}
157 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
158 mkdir -p ${WORK_DIR2}
159 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
160 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
161 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
162 umount ${WORK_DIR}
164 myecho Preparing the Xenomips config filesystem
165 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
166 mkfs.ext3 -F ${CONFIG_FS_NAME}
168 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
169 mkdir -p ${WORK_DIR}/etc
170 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
171 umount ${WORK_DIR}
173 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
174 for i in `seq 1 $CONFIG_FS_NUMBER`
175 do
176 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
177 done
178 fi
181 if echo $IOS_FS_BUILD | grep -qi ^y
182 then
183 myecho Preparing the filesystem with the IOSes
184 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
185 mkfs.ext3 -F ${IOS_FS_NAME}
186 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
187 cp ${IOS_DIR}/* ${WORK_DIR}
188 umount ${WORK_DIR}
189 fi