xentaur
view build-xenomips-image @ 0:ab37f0ad70e5
Initial revision
author | igor |
---|---|
date | Fri Jul 13 16:57:33 2007 +0300 (2007-07-13) |
parents | |
children | 825cd93472de |
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=yes
4 XENOMIPS_FS_BUILD=yes
5 CONFIG_FS_BUILD=no
6 IOS_FS_BUILD=yes
8 #Xenomips FS
9 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
10 XENOMIPS_FS_NAME=xenomips1.img
12 # Config FS
13 CONFIG_FS_SIZE=100k
14 CONFIG_FS_NAME=xenomips-config1.img
16 # IOS FS
17 IOS_FS_SIZE=2048k
18 IOS_FS_NAME=xenomips-ios1.img
21 XENOMIPS_DIR="files/"
24 DEBIAN_MIRROR=http://debian.org.ua/debian
25 DISTRO=sid
26 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga"
27 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
28 DYNAMIPS_BUILD_DIR=dynamips/
29 KERNEL_VERSION=`uname -r`
30 SSH_OPEN_KEY=files/id_dsa.pub
32 IOS_DIR="ios/"
34 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
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}
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
90 mkdir -p /xenomips/{ios,config,dynamips,etc/quagga} /var/lib/xenomips /root/.ssh
92 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
93 SCRIPT
95 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
97 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
98 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
99 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
101 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
102 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
104 build_and_install_dynamips
106 umount ${WORK_DIR}
108 if echo $CONFIG_FS_BUILD | grep -qi ^y
109 then
110 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
111 mkfs.ext3 -F ${CONFIG_FS_NAME}
112 fi
115 if echo $IOS_FS_BUILD | grep -qi ^y
116 then
117 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
118 mkfs.ext3 -F ${IOS_FS_NAME}
119 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
120 cp ${IOS_DIR}/* ${WORK_DIR}
121 umount ${WORK_DIR}
122 fi