xentaur

annotate build-xenomips-image @ 0:ab37f0ad70e5

Initial revision
author igor
date Fri Jul 13 16:57:33 2007 +0300 (2007-07-13)
parents
children 825cd93472de
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@0 5 CONFIG_FS_BUILD=no
igor@0 6 IOS_FS_BUILD=yes
igor@0 7
igor@0 8 #Xenomips FS
igor@0 9 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
igor@0 10 XENOMIPS_FS_NAME=xenomips1.img
igor@0 11
igor@0 12 # Config FS
igor@0 13 CONFIG_FS_SIZE=100k
igor@0 14 CONFIG_FS_NAME=xenomips-config1.img
igor@0 15
igor@0 16 # IOS FS
igor@0 17 IOS_FS_SIZE=2048k
igor@0 18 IOS_FS_NAME=xenomips-ios1.img
igor@0 19
igor@0 20
igor@0 21 XENOMIPS_DIR="files/"
igor@0 22
igor@0 23
igor@0 24 DEBIAN_MIRROR=http://debian.org.ua/debian
igor@0 25 DISTRO=sid
igor@0 26 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga"
igor@0 27 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
igor@0 28 DYNAMIPS_BUILD_DIR=dynamips/
igor@0 29 KERNEL_VERSION=`uname -r`
igor@0 30 SSH_OPEN_KEY=files/id_dsa.pub
igor@0 31
igor@0 32 IOS_DIR="ios/"
igor@0 33
igor@0 34 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
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@0 61 mkdir -p ${WORK_DIR}
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@0 88 perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
igor@0 89
igor@0 90 mkdir -p /xenomips/{ios,config,dynamips,etc/quagga} /var/lib/xenomips /root/.ssh
igor@0 91
igor@0 92 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
igor@0 93 SCRIPT
igor@0 94
igor@0 95 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
igor@0 96
igor@0 97 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
igor@0 98 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/usr/local/bin
igor@0 99 sudo chmod +x ${WORK_DIR}/usr/local/bin/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips-init
igor@0 100
igor@0 101 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
igor@0 102 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
igor@0 103
igor@0 104 build_and_install_dynamips
igor@0 105
igor@0 106 umount ${WORK_DIR}
igor@0 107
igor@0 108 if echo $CONFIG_FS_BUILD | grep -qi ^y
igor@0 109 then
igor@0 110 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
igor@0 111 mkfs.ext3 -F ${CONFIG_FS_NAME}
igor@0 112 fi
igor@0 113
igor@0 114
igor@0 115 if echo $IOS_FS_BUILD | grep -qi ^y
igor@0 116 then
igor@0 117 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=${CONFIG_FS_SIZE}
igor@0 118 mkfs.ext3 -F ${IOS_FS_NAME}
igor@0 119 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
igor@0 120 cp ${IOS_DIR}/* ${WORK_DIR}
igor@0 121 umount ${WORK_DIR}
igor@0 122 fi
igor@0 123