xentaur

view build-xenomips-image @ 13:de23c23ef4ac

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