xentaur
view build-xenomips-image @ 39:54b7c7ae50ec
brodge-bridge link visualisation
author | igor |
---|---|
date | Fri Sep 28 13:35:54 2007 +0300 (2007-09-28) |
parents | 532f2ed25f70 |
children | 10444acb35f4 |
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=no
4 XENOMIPS_FS_BUILD=no
5 CONFIG_FS_BUILD=no
6 IOS_FS_BUILD=yes
8 XENOMIPS_DIR="files/"
9 XENOMIPS_IMAGES_DIR="/home/nata/xenomips-images/"
10 IOS_DIR="/home/nata/ios/"
11 SSH_OPEN_KEY=files/id_dsa.pub
13 #Xenomips FS
14 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
15 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
17 # Config FS
18 CONFIG_FS_SIZE=1000k
19 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
20 CONFIG_FS_NUMBER=5 # the number of the Xenomips instance
22 # IOS FS
23 IOS_FS_SIZE=2048k
24 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
26 DEBIAN_MIRROR=http://debian.org.ua/debian
27 DISTRO=sid
28 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump"
29 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
30 DYNAMIPS_BUILD_DIR=dynamips/
31 KERNEL_VERSION=`uname -r`
34 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
35 WORK_DIR2=/tmp/xenomips-build
37 myecho()
38 {
39 echo '**************************'
40 echo "$@"
41 echo '**************************'
42 }
44 build_and_install_dynamips()
45 {
46 OLD_PWD="`pwd`"
47 DESTDIR=${WORK_DIR}/usr
49 if echo $DYNAMIPS_BUILD | grep -qi ^y
50 then
51 rm -rf ${DYNAMIPS_BUILD_DIR}/
52 mkdir -p ${DYNAMIPS_BUILD_DIR}/
53 cd ${DYNAMIPS_BUILD_DIR}/
54 wget $DYNAMIPS_SOURCES
55 tar xfz dynamips*tar*
56 cd dynamips*/
57 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
58 make
59 else
60 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
61 fi
62 make install DESTDIR=${DESTDIR}
63 cd ${OLD_PWD}
64 }
66 myecho Preparing the Xenomips filesystem
67 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
68 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
69 mkdir -p ${WORK_DIR} ${WORK_DIR2}
70 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
71 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
72 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
73 unset LANG
74 apt-get -y --force-yes install ${PACKAGES}
75 /etc/init.d/ssh stop
76 cat <<FSTAB > /etc/fstab
77 proc /proc proc defaults 0 0
78 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
80 /dev/hda1 / ext3 ro 0 0
81 /dev/hda2 /xenomips/ios ext3 ro 0 0
82 /dev/hda3 /xenomips/config ext3 rw 0 0
83 FSTAB
84 mkdir -p /data/Cisco_IOS /xenomips
86 cat <<'INTERFACES' > /etc/network/interfaces
87 auto lo eth0
89 iface lo inet loopback
90 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
92 #iface eth0 inet dhcp
93 INTERFACES
95 echo /usr/local/bin/xenomips.sh > /etc/rc.local
96 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
97 rm /etc/rc2.d/S*quagga
99 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
100 mv /etc/quagga /etc/quagga.ORIG
101 ln -s /xenomips/config/etc/quagga /etc/quagga
103 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
105 cat <<PROFILE >> /root/.profile
106 TERM=linux
107 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
108 PROFILE
109 SCRIPT
111 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
112 do
113 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
114 done
116 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
117 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
118 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
120 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
121 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
123 build_and_install_dynamips
125 mv ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
126 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
127 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
128 umount ${WORK_DIR}
130 if echo $CONFIG_FS_BUILD | grep -qi ^y
131 then
132 myecho Preparing the Xenomips config filesystem
133 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
134 mkfs.ext3 -F ${CONFIG_FS_NAME}
136 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
137 mkdir -p ${WORK_DIR}/etc
138 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
139 umount ${WORK_DIR}
141 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
142 for i in `seq 1 $CONFIG_FS_NUMBER`
143 do
144 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
145 done
146 fi
149 if echo $IOS_FS_BUILD | grep -qi ^y
150 then
151 myecho Preparing the filesystem with the IOSes
152 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
153 mkfs.ext3 -F ${IOS_FS_NAME}
154 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
155 cp ${IOS_DIR}/* ${WORK_DIR}
156 umount ${WORK_DIR}
157 fi