xentaur

annotate build-xenomips-image @ 17:6d2b4b61733f

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