xentaur

view build-xenomips-image @ 7:825cd93472de

Dodelal
author igor
date Thu Aug 02 20:46:09 2007 +0300 (2007-08-02)
parents ab37f0ad70e5
children 3d837efe2d1c
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 /dev/hda1 / ext3 ro 0 0
70 /dev/hda2 /xenomips/ios ext3 ro 0 0
71 /dev/hda3 /xenomips/config ext3 rw 0 0
72 FSTAB
73 mkdir -p /data/Cisco_IOS /xenomips
75 cat <<'INTERFACES' > /etc/network/interfaces
76 auto lo eth0
78 iface lo inet loopback
79 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
81 iface eth0 inet dhcp
82 INTERFACES
84 echo /usr/local/bin/xenomips.sh > /etc/rc.local
85 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
86 rm /etc/rc2.d/S*quagga
88 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
89 mv /etc/quagga /etc/quagga.ORIG
90 ln -s /xenomips/config/etc/quagga /etc/quagga
92 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
94 cat <<PROFILE >> /root/.profile
95 TERM=linux
96 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
97 PROFILE
98 SCRIPT
100 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
102 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
103 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
104 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
106 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
107 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
109 build_and_install_dynamips
111 mv ${WORK_DIR}/etc/quagga ${WORK_DIR2}
112 umount ${WORK_DIR}
114 if echo $CONFIG_FS_BUILD | grep -qi ^y
115 then
116 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
117 mkfs.ext3 -F ${CONFIG_FS_NAME}
118 fi
120 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
121 mkdir -p ${WORK_DIR}/etc
122 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
124 if echo $IOS_FS_BUILD | grep -qi ^y
125 then
126 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
127 mkfs.ext3 -F ${IOS_FS_NAME}
128 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
129 cp ${IOS_DIR}/* ${WORK_DIR}
130 umount ${WORK_DIR}
131 fi