xentaur

view build-xenomips-image @ 43:61476759b5f1

build fixes
author igor
date Wed Oct 24 14:30:08 2007 +0300 (2007-10-24)
parents e006fac33f05
children 9c7a4cfa9738
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=no
4 XENOMIPS_FS_BUILD=no
5 CONFIG_FS_BUILD=yes
6 IOS_FS_BUILD=no
8 XENOMIPS_DIR="files/"
9 XENOMIPS_IMAGES_DIR="/xen/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-configXXX.img # XXX will be automagically substitued with
20 CONFIG_FS_NUMBER=10 # 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=ftp://debian.org.ua/debian
27 DISTRO=etch
28 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 openntpd"
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 if [ $(id -u) != 0 ]
67 then
68 echo You are not root.
69 echo Please, log in as root or run the script with sudo
70 ecit 1
71 fi
74 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
75 then
76 myecho Preparing the Xenomips filesystem
77 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
78 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
79 mkdir -p ${WORK_DIR}
80 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
81 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
82 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
83 unset LANG
84 apt-get -y --force-yes install ${PACKAGES}
85 /etc/init.d/ssh stop
86 cat <<FSTAB > /etc/fstab
87 proc /proc proc defaults 0 0
88 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
90 /dev/hda1 / ext3 ro 0 0
91 /dev/hda2 /xenomips/ios ext3 ro 0 0
92 /dev/hda3 /xenomips/config ext3 rw 0 0
93 FSTAB
94 mkdir -p /data/Cisco_IOS /xenomips
96 cat <<EOF > /etc/sysctl.conf
97 net/ipv4/ip_forward=1
98 EOF
100 cat <<'INTERFACES' > /etc/network/interfaces
101 auto lo eth0
103 iface lo inet loopback
104 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
106 #iface eth0 inet dhcp
107 INTERFACES
109 echo /usr/local/bin/xenomips.sh > /etc/rc.local
110 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
111 rm /etc/rc2.d/S*quagga
113 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
114 mv /etc/quagga /etc/quagga.ORIG
115 ln -s /xenomips/config/etc/quagga /etc/quagga
117 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
119 cat <<PROFILE >> /root/.profile
120 TERM=linux
121 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
122 PROFILE
123 SCRIPT
125 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
126 do
127 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
128 done
130 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
131 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
132 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
134 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
135 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
137 build_and_install_dynamips
138 umount ${WORK_DIR}
139 fi
142 if echo $CONFIG_FS_BUILD | grep -qi ^y
143 then
144 mkdir -p ${WORK_DIR}
145 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
146 mkdir -p ${WORK_DIR2}
147 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
148 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
149 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
150 umount ${WORK_DIR}
152 myecho Preparing the Xenomips config filesystem
153 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
154 mkfs.ext3 -F ${CONFIG_FS_NAME}
156 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
157 mkdir -p ${WORK_DIR}/etc
158 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
159 umount ${WORK_DIR}
161 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
162 for i in `seq 1 $CONFIG_FS_NUMBER`
163 do
164 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
165 done
166 fi
169 if echo $IOS_FS_BUILD | grep -qi ^y
170 then
171 myecho Preparing the filesystem with the IOSes
172 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
173 mkfs.ext3 -F ${IOS_FS_NAME}
174 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
175 cp ${IOS_DIR}/* ${WORK_DIR}
176 umount ${WORK_DIR}
177 fi