rev |
line source |
igor@0
|
1 #!/bin/sh
|
igor@0
|
2
|
igor@0
|
3 DYNAMIPS_BUILD=yes
|
igor@0
|
4 XENOMIPS_FS_BUILD=yes
|
igor@15
|
5 CONFIG_FS_BUILD=yes
|
igor@15
|
6 IOS_FS_BUILD=yes
|
igor@0
|
7
|
igor@7
|
8 XENOMIPS_DIR="files/"
|
igor@15
|
9 XENOMIPS_IMAGES_DIR="../xenomips-images/"
|
igor@15
|
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@18
|
20 CONFIG_FS_NUMBER=5 # 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@0
|
26 DEBIAN_MIRROR=http://debian.org.ua/debian
|
igor@0
|
27 DISTRO=sid
|
igor@18
|
28 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump"
|
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@18
|
66 myecho Preparing the Xenomips filesystem
|
igor@17
|
67 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
|
igor@0
|
68 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
|
igor@7
|
69 mkdir -p ${WORK_DIR} ${WORK_DIR2}
|
igor@0
|
70 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
|
igor@0
|
71 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
|
igor@0
|
72 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
|
igor@0
|
73 unset LANG
|
igor@0
|
74 apt-get -y --force-yes install ${PACKAGES}
|
igor@0
|
75 /etc/init.d/ssh stop
|
igor@0
|
76 cat <<FSTAB > /etc/fstab
|
igor@11
|
77 proc /proc proc defaults 0 0
|
igor@11
|
78 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
|
igor@11
|
79
|
igor@0
|
80 /dev/hda1 / ext3 ro 0 0
|
igor@0
|
81 /dev/hda2 /xenomips/ios ext3 ro 0 0
|
igor@0
|
82 /dev/hda3 /xenomips/config ext3 rw 0 0
|
igor@0
|
83 FSTAB
|
igor@0
|
84 mkdir -p /data/Cisco_IOS /xenomips
|
igor@0
|
85
|
igor@0
|
86 cat <<'INTERFACES' > /etc/network/interfaces
|
igor@0
|
87 auto lo eth0
|
igor@0
|
88
|
igor@0
|
89 iface lo inet loopback
|
igor@0
|
90 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
|
igor@0
|
91
|
igor@13
|
92 #iface eth0 inet dhcp
|
igor@0
|
93 INTERFACES
|
igor@0
|
94
|
igor@0
|
95 echo /usr/local/bin/xenomips.sh > /etc/rc.local
|
igor@0
|
96 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
|
igor@0
|
97 rm /etc/rc2.d/S*quagga
|
igor@0
|
98
|
igor@7
|
99 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
|
igor@7
|
100 mv /etc/quagga /etc/quagga.ORIG
|
igor@7
|
101 ln -s /xenomips/config/etc/quagga /etc/quagga
|
igor@0
|
102
|
igor@7
|
103 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
|
igor@0
|
104
|
igor@7
|
105 cat <<PROFILE >> /root/.profile
|
igor@7
|
106 TERM=linux
|
igor@0
|
107 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
|
igor@7
|
108 PROFILE
|
igor@0
|
109 SCRIPT
|
igor@0
|
110
|
igor@11
|
111 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
|
igor@11
|
112 do
|
igor@11
|
113 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
|
igor@11
|
114 done
|
igor@0
|
115
|
igor@0
|
116 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
|
igor@0
|
117 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
|
igor@0
|
118 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
|
igor@0
|
119
|
igor@0
|
120 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@0
|
121 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@0
|
122
|
igor@0
|
123 build_and_install_dynamips
|
igor@0
|
124
|
igor@9
|
125 mv ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
|
igor@11
|
126 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
|
igor@11
|
127 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
|
igor@0
|
128 umount ${WORK_DIR}
|
igor@0
|
129
|
igor@0
|
130 if echo $CONFIG_FS_BUILD | grep -qi ^y
|
igor@0
|
131 then
|
igor@18
|
132 myecho Preparing the Xenomips config filesystem
|
igor@0
|
133 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
|
igor@0
|
134 mkfs.ext3 -F ${CONFIG_FS_NAME}
|
igor@14
|
135
|
igor@14
|
136 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
|
igor@14
|
137 mkdir -p ${WORK_DIR}/etc
|
igor@14
|
138 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
|
igor@14
|
139 umount ${WORK_DIR}
|
igor@14
|
140
|
igor@18
|
141 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
|
igor@18
|
142 for i in `seq 1 $CONFIG_FS_NUMBER`
|
igor@18
|
143 do
|
igor@18
|
144 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
|
igor@18
|
145 done
|
igor@0
|
146 fi
|
igor@0
|
147
|
igor@0
|
148
|
igor@0
|
149 if echo $IOS_FS_BUILD | grep -qi ^y
|
igor@0
|
150 then
|
igor@18
|
151 myecho Preparing the filesystem with the IOSes
|
igor@18
|
152 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
|
igor@0
|
153 mkfs.ext3 -F ${IOS_FS_NAME}
|
igor@0
|
154 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
|
igor@0
|
155 cp ${IOS_DIR}/* ${WORK_DIR}
|
igor@0
|
156 umount ${WORK_DIR}
|
igor@0
|
157 fi
|
igor@0
|
158
|