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@7
|
5 CONFIG_FS_BUILD=yes
|
igor@0
|
6 IOS_FS_BUILD=yes
|
igor@0
|
7
|
igor@7
|
8 XENOMIPS_DIR="files/"
|
igor@7
|
9 XENOMIPS_IMAGES_DIR="../images/"
|
igor@7
|
10
|
igor@0
|
11 #Xenomips FS
|
igor@0
|
12 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
|
igor@7
|
13 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
|
igor@0
|
14
|
igor@0
|
15 # Config FS
|
igor@7
|
16 CONFIG_FS_SIZE=1000k
|
igor@7
|
17 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-config1.img
|
igor@0
|
18
|
igor@0
|
19 # IOS FS
|
igor@0
|
20 IOS_FS_SIZE=2048k
|
igor@7
|
21 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
|
igor@0
|
22
|
igor@0
|
23 DEBIAN_MIRROR=http://debian.org.ua/debian
|
igor@0
|
24 DISTRO=sid
|
igor@0
|
25 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga"
|
igor@0
|
26 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
|
igor@0
|
27 DYNAMIPS_BUILD_DIR=dynamips/
|
igor@0
|
28 KERNEL_VERSION=`uname -r`
|
igor@0
|
29 SSH_OPEN_KEY=files/id_dsa.pub
|
igor@0
|
30
|
igor@0
|
31 IOS_DIR="ios/"
|
igor@0
|
32
|
igor@0
|
33 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
|
igor@7
|
34 WORK_DIR2=/tmp/xenomips-build
|
igor@0
|
35
|
igor@0
|
36 build_and_install_dynamips()
|
igor@0
|
37 {
|
igor@0
|
38 OLD_PWD="`pwd`"
|
igor@0
|
39 DESTDIR=`pwd`/${WORK_DIR}
|
igor@0
|
40
|
igor@0
|
41 if echo $DYNAMIPS_BUILD | grep -qi ^y
|
igor@0
|
42 then
|
igor@0
|
43 rm -rf ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
44 mkdir -p ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
45 cd ${DYNAMIPS_BUILD_DIR}/
|
igor@0
|
46 wget $DYNAMIPS_SOURCES
|
igor@0
|
47 tar xfz dynamips*tar*
|
igor@0
|
48 cd dynamips*/
|
igor@0
|
49 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
|
igor@0
|
50 make
|
igor@0
|
51 else
|
igor@0
|
52 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
|
igor@0
|
53 fi
|
igor@0
|
54 make install DESTDIR=${DESTDIR}
|
igor@0
|
55 cd ${OLD_PWD}
|
igor@0
|
56 }
|
igor@0
|
57
|
igor@0
|
58
|
igor@0
|
59 dd if=/dev/zero of=${XENOMIPS_FS_NAME} count=${XENOMIPS_FS_SIZE} bs=1024
|
igor@0
|
60 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
|
igor@7
|
61 mkdir -p ${WORK_DIR} ${WORK_DIR2}
|
igor@0
|
62 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
|
igor@0
|
63 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
|
igor@0
|
64 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
|
igor@0
|
65 unset LANG
|
igor@0
|
66 apt-get -y --force-yes install ${PACKAGES}
|
igor@0
|
67 /etc/init.d/ssh stop
|
igor@0
|
68 cat <<FSTAB > /etc/fstab
|
igor@11
|
69 proc /proc proc defaults 0 0
|
igor@11
|
70 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
|
igor@11
|
71
|
igor@0
|
72 /dev/hda1 / ext3 ro 0 0
|
igor@0
|
73 /dev/hda2 /xenomips/ios ext3 ro 0 0
|
igor@0
|
74 /dev/hda3 /xenomips/config ext3 rw 0 0
|
igor@0
|
75 FSTAB
|
igor@0
|
76 mkdir -p /data/Cisco_IOS /xenomips
|
igor@0
|
77
|
igor@0
|
78 cat <<'INTERFACES' > /etc/network/interfaces
|
igor@0
|
79 auto lo eth0
|
igor@0
|
80
|
igor@0
|
81 iface lo inet loopback
|
igor@0
|
82 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
|
igor@0
|
83
|
igor@13
|
84 #iface eth0 inet dhcp
|
igor@0
|
85 INTERFACES
|
igor@0
|
86
|
igor@0
|
87 echo /usr/local/bin/xenomips.sh > /etc/rc.local
|
igor@0
|
88 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
|
igor@0
|
89 rm /etc/rc2.d/S*quagga
|
igor@0
|
90
|
igor@7
|
91 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
|
igor@7
|
92 mv /etc/quagga /etc/quagga.ORIG
|
igor@7
|
93 ln -s /xenomips/config/etc/quagga /etc/quagga
|
igor@0
|
94
|
igor@7
|
95 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
|
igor@0
|
96
|
igor@7
|
97 cat <<PROFILE >> /root/.profile
|
igor@7
|
98 TERM=linux
|
igor@0
|
99 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
|
igor@7
|
100 PROFILE
|
igor@0
|
101 SCRIPT
|
igor@0
|
102
|
igor@11
|
103 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
|
igor@11
|
104 do
|
igor@11
|
105 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
|
igor@11
|
106 done
|
igor@0
|
107
|
igor@0
|
108 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
|
igor@0
|
109 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
|
igor@0
|
110 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
|
igor@0
|
111
|
igor@0
|
112 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@0
|
113 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
|
igor@0
|
114
|
igor@0
|
115 build_and_install_dynamips
|
igor@0
|
116
|
igor@9
|
117 mv ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
|
igor@11
|
118 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
|
igor@11
|
119 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
|
igor@0
|
120 umount ${WORK_DIR}
|
igor@0
|
121
|
igor@0
|
122 if echo $CONFIG_FS_BUILD | grep -qi ^y
|
igor@0
|
123 then
|
igor@0
|
124 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
|
igor@0
|
125 mkfs.ext3 -F ${CONFIG_FS_NAME}
|
igor@0
|
126 fi
|
igor@0
|
127
|
igor@7
|
128 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
|
igor@7
|
129 mkdir -p ${WORK_DIR}/etc
|
igor@7
|
130 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
|
igor@9
|
131 umount ${WORK_DIR}
|
igor@0
|
132
|
igor@0
|
133 if echo $IOS_FS_BUILD | grep -qi ^y
|
igor@0
|
134 then
|
igor@0
|
135 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
|
igor@0
|
136 mkfs.ext3 -F ${IOS_FS_NAME}
|
igor@0
|
137 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
|
igor@0
|
138 cp ${IOS_DIR}/* ${WORK_DIR}
|
igor@0
|
139 umount ${WORK_DIR}
|
igor@0
|
140 fi
|
igor@0
|
141
|