xentaur

annotate build-xenomips-image @ 9:3d837efe2d1c

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