xentaur

annotate build-xenomips-image @ 53:129c08025d07

+nmap to xenomips
author igor
date Thu Oct 25 21:37:35 2007 +0300 (2007-10-25)
parents 65e80fabc89c
children 0d56a515a5f6
rev   line source
igor@0 1 #!/bin/sh
igor@0 2
nata@31 3 DYNAMIPS_BUILD=no
igor@49 4 XENOMIPS_FS_BUILD=yes
igor@49 5 CONFIG_FS_BUILD=yes
igor@45 6 IOS_FS_BUILD=yes
igor@0 7
igor@49 8 process_args()
igor@49 9 {
igor@49 10 true
igor@49 11 }
igor@49 12
igor@7 13 XENOMIPS_DIR="files/"
igor@40 14 XENOMIPS_IMAGES_DIR="/xen/images/"
igor@40 15 IOS_DIR="ios/"
igor@15 16 SSH_OPEN_KEY=files/id_dsa.pub
igor@7 17
igor@0 18 #Xenomips FS
igor@0 19 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
igor@7 20 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
igor@0 21
igor@0 22 # Config FS
igor@7 23 CONFIG_FS_SIZE=1000k
igor@18 24 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
igor@43 25 CONFIG_FS_NUMBER=10 # the number of the Xenomips instance
igor@0 26
igor@0 27 # IOS FS
igor@0 28 IOS_FS_SIZE=2048k
igor@7 29 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
igor@0 30
igor@42 31 DEBIAN_MIRROR=ftp://debian.org.ua/debian
igor@42 32 DISTRO=etch
igor@53 33 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntpd nmap"
igor@0 34 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
igor@0 35 DYNAMIPS_BUILD_DIR=dynamips/
igor@0 36 KERNEL_VERSION=`uname -r`
igor@0 37
igor@0 38
igor@0 39 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
igor@7 40 WORK_DIR2=/tmp/xenomips-build
igor@0 41
igor@17 42 myecho()
igor@17 43 {
igor@17 44 echo '**************************'
igor@17 45 echo "$@"
igor@17 46 echo '**************************'
igor@17 47 }
igor@17 48
igor@0 49 build_and_install_dynamips()
igor@0 50 {
igor@0 51 OLD_PWD="`pwd`"
igor@20 52 DESTDIR=${WORK_DIR}/usr
igor@0 53
igor@0 54 if echo $DYNAMIPS_BUILD | grep -qi ^y
igor@0 55 then
igor@0 56 rm -rf ${DYNAMIPS_BUILD_DIR}/
igor@0 57 mkdir -p ${DYNAMIPS_BUILD_DIR}/
igor@0 58 cd ${DYNAMIPS_BUILD_DIR}/
igor@0 59 wget $DYNAMIPS_SOURCES
igor@0 60 tar xfz dynamips*tar*
igor@0 61 cd dynamips*/
igor@0 62 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
igor@0 63 make
igor@0 64 else
igor@0 65 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
igor@0 66 fi
igor@20 67 make install DESTDIR=${DESTDIR}
igor@0 68 cd ${OLD_PWD}
igor@0 69 }
igor@0 70
igor@43 71 if [ $(id -u) != 0 ]
igor@43 72 then
igor@43 73 echo You are not root.
igor@43 74 echo Please, log in as root or run the script with sudo
igor@43 75 ecit 1
igor@43 76 fi
igor@43 77
igor@43 78
igor@43 79 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
igor@43 80 then
igor@43 81 myecho Preparing the Xenomips filesystem
igor@43 82 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
igor@43 83 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
igor@43 84 mkdir -p ${WORK_DIR}
igor@43 85 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 86 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
igor@43 87 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
igor@0 88 unset LANG
igor@0 89 apt-get -y --force-yes install ${PACKAGES}
igor@0 90 /etc/init.d/ssh stop
igor@0 91 cat <<FSTAB > /etc/fstab
igor@11 92 proc /proc proc defaults 0 0
igor@11 93 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
igor@11 94
igor@0 95 /dev/hda1 / ext3 ro 0 0
igor@0 96 /dev/hda2 /xenomips/ios ext3 ro 0 0
igor@0 97 /dev/hda3 /xenomips/config ext3 rw 0 0
igor@0 98 FSTAB
igor@0 99 mkdir -p /data/Cisco_IOS /xenomips
igor@0 100
igor@40 101 cat <<EOF > /etc/sysctl.conf
igor@40 102 net/ipv4/ip_forward=1
igor@40 103 EOF
igor@40 104
igor@0 105 cat <<'INTERFACES' > /etc/network/interfaces
igor@0 106 auto lo eth0
igor@0 107
igor@0 108 iface lo inet loopback
igor@0 109 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
igor@0 110
igor@13 111 #iface eth0 inet dhcp
igor@0 112 INTERFACES
igor@0 113
igor@49 114 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
igor@0 115 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
igor@0 116 rm /etc/rc2.d/S*quagga
igor@49 117 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
igor@49 118 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
igor@49 119 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
igor@49 120 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
igor@49 121 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
igor@49 122 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
igor@49 123 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
igor@0 124
igor@7 125 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
igor@7 126 mv /etc/quagga /etc/quagga.ORIG
igor@7 127 ln -s /xenomips/config/etc/quagga /etc/quagga
igor@0 128
igor@7 129 mkdir -p /xenomips/{ios,config,dynamips} /var/lib/xenomips /root/.ssh
igor@0 130
igor@7 131 cat <<PROFILE >> /root/.profile
igor@7 132 TERM=linux
igor@0 133 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
igor@7 134 PROFILE
igor@0 135 SCRIPT
igor@0 136
igor@43 137 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
igor@43 138 do
igor@43 139 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
igor@43 140 done
igor@0 141
igor@43 142 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
igor@49 143 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
igor@49 144 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
igor@0 145
igor@43 146 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
igor@43 147 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
igor@0 148
igor@43 149 build_and_install_dynamips
igor@43 150 umount ${WORK_DIR}
igor@43 151 fi
igor@0 152
igor@0 153
igor@0 154 if echo $CONFIG_FS_BUILD | grep -qi ^y
igor@0 155 then
igor@43 156 mkdir -p ${WORK_DIR}
igor@43 157 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 158 mkdir -p ${WORK_DIR2}
igor@43 159 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
igor@43 160 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
igor@43 161 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
igor@43 162 umount ${WORK_DIR}
igor@43 163
igor@18 164 myecho Preparing the Xenomips config filesystem
igor@41 165 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 166 mkfs.ext3 -F ${CONFIG_FS_NAME}
igor@14 167
igor@14 168 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
igor@14 169 mkdir -p ${WORK_DIR}/etc
igor@14 170 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
igor@14 171 umount ${WORK_DIR}
igor@14 172
igor@18 173 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
igor@18 174 for i in `seq 1 $CONFIG_FS_NUMBER`
igor@18 175 do
igor@18 176 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
igor@18 177 done
igor@0 178 fi
igor@0 179
igor@0 180
igor@0 181 if echo $IOS_FS_BUILD | grep -qi ^y
igor@0 182 then
igor@18 183 myecho Preparing the filesystem with the IOSes
igor@18 184 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 185 mkfs.ext3 -F ${IOS_FS_NAME}
igor@0 186 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
igor@0 187 cp ${IOS_DIR}/* ${WORK_DIR}
igor@0 188 umount ${WORK_DIR}
igor@0 189 fi
igor@0 190