xentaur

annotate build-xenomips-image @ 64:baf0c3300c19

update tags
author convert-repo
date Sun Jun 29 09:03:52 2008 +0000 (2008-06-29)
parents 0d56a515a5f6
children cf823d27b029
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@61 33 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntp nmap netcat socat"
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@61 36 PIXEMU_SOURCES=http://xgu.ru/download/pemu_public2007-07-02.tar.bz2
igor@61 37 PIXEMU_BUILD_DIR=dynamips/
igor@0 38 KERNEL_VERSION=`uname -r`
igor@0 39
igor@0 40
igor@0 41 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
igor@7 42 WORK_DIR2=/tmp/xenomips-build
igor@0 43
igor@17 44 myecho()
igor@17 45 {
igor@17 46 echo '**************************'
igor@17 47 echo "$@"
igor@17 48 echo '**************************'
igor@17 49 }
igor@17 50
igor@0 51 build_and_install_dynamips()
igor@0 52 {
igor@0 53 OLD_PWD="`pwd`"
igor@20 54 DESTDIR=${WORK_DIR}/usr
igor@0 55
igor@0 56 if echo $DYNAMIPS_BUILD | grep -qi ^y
igor@0 57 then
igor@0 58 rm -rf ${DYNAMIPS_BUILD_DIR}/
igor@0 59 mkdir -p ${DYNAMIPS_BUILD_DIR}/
igor@0 60 cd ${DYNAMIPS_BUILD_DIR}/
igor@0 61 wget $DYNAMIPS_SOURCES
igor@0 62 tar xfz dynamips*tar*
igor@0 63 cd dynamips*/
igor@0 64 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
igor@0 65 make
igor@0 66 else
igor@0 67 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
igor@0 68 fi
igor@20 69 make install DESTDIR=${DESTDIR}
igor@0 70 cd ${OLD_PWD}
igor@0 71 }
igor@0 72
igor@61 73 build_and_install_pixemu()
igor@61 74 {
igor@61 75 DESTDIR=${WORK_DIR}/usr/local/pixemu
igor@61 76 mkdir -p $DESTDIR
igor@61 77 cp /home/igor/pemu/pemu/* $DESTDIR
igor@61 78 }
igor@61 79
igor@61 80
igor@43 81 if [ $(id -u) != 0 ]
igor@43 82 then
igor@43 83 echo You are not root.
igor@43 84 echo Please, log in as root or run the script with sudo
igor@43 85 ecit 1
igor@43 86 fi
igor@43 87
igor@43 88
igor@43 89 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
igor@43 90 then
igor@43 91 myecho Preparing the Xenomips filesystem
igor@43 92 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
igor@43 93 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
igor@43 94 mkdir -p ${WORK_DIR}
igor@43 95 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 96 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
igor@43 97 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
igor@0 98 unset LANG
igor@0 99 apt-get -y --force-yes install ${PACKAGES}
igor@0 100 /etc/init.d/ssh stop
igor@0 101 cat <<FSTAB > /etc/fstab
igor@11 102 proc /proc proc defaults 0 0
igor@11 103 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
igor@11 104
igor@0 105 /dev/hda1 / ext3 ro 0 0
igor@0 106 /dev/hda2 /xenomips/ios ext3 ro 0 0
igor@0 107 /dev/hda3 /xenomips/config ext3 rw 0 0
igor@0 108 FSTAB
igor@0 109 mkdir -p /data/Cisco_IOS /xenomips
igor@0 110
igor@40 111 cat <<EOF > /etc/sysctl.conf
igor@40 112 net/ipv4/ip_forward=1
igor@40 113 EOF
igor@40 114
igor@0 115 cat <<'INTERFACES' > /etc/network/interfaces
igor@0 116 auto lo eth0
igor@0 117
igor@0 118 iface lo inet loopback
igor@0 119 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
igor@0 120
igor@13 121 #iface eth0 inet dhcp
igor@0 122 INTERFACES
igor@0 123
igor@49 124 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
igor@0 125 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
igor@0 126 rm /etc/rc2.d/S*quagga
igor@49 127 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
igor@49 128 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
igor@49 129 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
igor@49 130 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
igor@49 131 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
igor@49 132 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
igor@49 133 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
igor@0 134
igor@7 135 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
igor@7 136 mv /etc/quagga /etc/quagga.ORIG
igor@7 137 ln -s /xenomips/config/etc/quagga /etc/quagga
igor@0 138
igor@61 139 mkdir -p /xenomips/{ios,config} /var/lib/xenomips /root/.ssh
igor@0 140
igor@7 141 cat <<PROFILE >> /root/.profile
igor@7 142 TERM=linux
igor@0 143 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
igor@7 144 PROFILE
igor@0 145 SCRIPT
igor@0 146
igor@43 147 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
igor@43 148 do
igor@43 149 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
igor@43 150 done
igor@0 151
igor@43 152 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
igor@49 153 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
igor@49 154 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
igor@0 155
igor@43 156 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
igor@43 157 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
igor@0 158
igor@43 159 build_and_install_dynamips
igor@61 160 build_and_install_pixemu
igor@61 161 kill $(lsof +D ${WORK_DIR} | awk '{print $2}' | grep -v PID)
igor@61 162 pkill ntpd
igor@43 163 umount ${WORK_DIR}
igor@43 164 fi
igor@0 165
igor@0 166
igor@0 167 if echo $CONFIG_FS_BUILD | grep -qi ^y
igor@0 168 then
igor@43 169 mkdir -p ${WORK_DIR}
igor@43 170 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
igor@43 171 mkdir -p ${WORK_DIR2}
igor@43 172 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
igor@43 173 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
igor@43 174 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
igor@61 175 cp -a ${WORK_DIR}/usr/local/pixemu ${WORK_DIR2}/pixemu
igor@43 176 umount ${WORK_DIR}
igor@43 177
igor@18 178 myecho Preparing the Xenomips config filesystem
igor@41 179 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 180 mkfs.ext3 -F ${CONFIG_FS_NAME}
igor@14 181
igor@14 182 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
igor@61 183 mkdir -p ${WORK_DIR}/{dynamips,etc}
igor@14 184 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
igor@61 185 mv ${WORK_DIR2}/pixemu ${WORK_DIR}/
igor@61 186 dd if=/dev/zero of=${WORK_DIR}/pixemu/FLASH bs=1k count=16k
igor@14 187 umount ${WORK_DIR}
igor@14 188
igor@18 189 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
igor@61 190 for i in `seq 0 $CONFIG_FS_NUMBER`
igor@18 191 do
igor@18 192 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
igor@18 193 done
igor@0 194 fi
igor@0 195
igor@0 196
igor@0 197 if echo $IOS_FS_BUILD | grep -qi ^y
igor@0 198 then
igor@18 199 myecho Preparing the filesystem with the IOSes
igor@18 200 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
igor@0 201 mkfs.ext3 -F ${IOS_FS_NAME}
igor@0 202 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
igor@0 203 cp ${IOS_DIR}/* ${WORK_DIR}
igor@0 204 umount ${WORK_DIR}
igor@0 205 fi
igor@0 206