xentaur

annotate build-xenomips-image @ 41:8c00f233a1d4

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