xentaur

view build-xenomips-image @ 17:6d2b4b61733f

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