xentaur

view build-xenomips-image @ 62:e838c1223b89

Делаются какие-то попытки интегрировать в Xentaur
управление разнообразными доменами.
author igor
date Thu Feb 21 21:41:20 2008 +0200 (2008-02-21)
parents 0d56a515a5f6
children cf823d27b029
line source
1 #!/bin/sh
3 DYNAMIPS_BUILD=no
4 XENOMIPS_FS_BUILD=yes
5 CONFIG_FS_BUILD=yes
6 IOS_FS_BUILD=yes
8 process_args()
9 {
10 true
11 }
13 XENOMIPS_DIR="files/"
14 XENOMIPS_IMAGES_DIR="/xen/images/"
15 IOS_DIR="ios/"
16 SSH_OPEN_KEY=files/id_dsa.pub
18 #Xenomips FS
19 XENOMIPS_FS_SIZE=2048k # size in 1k blocks
20 XENOMIPS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips1.img
22 # Config FS
23 CONFIG_FS_SIZE=1000k
24 CONFIG_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-configXXX.img # XXX will be automagically substitued with
25 CONFIG_FS_NUMBER=10 # the number of the Xenomips instance
27 # IOS FS
28 IOS_FS_SIZE=2048k
29 IOS_FS_NAME=${XENOMIPS_IMAGES_DIR}/xenomips-ios1.img
31 DEBIAN_MIRROR=ftp://debian.org.ua/debian
32 DISTRO=etch
33 PACKAGES="openssh-server libc6-xen libelf1 libpcap0.8 screen nfs-common quagga tcpdump telnet ntpdate hping3 ntp nmap netcat socat"
34 DYNAMIPS_SOURCES=http://www.ipflow.utc.fr/dynamips/dynamips-0.2.7.tar.gz
35 DYNAMIPS_BUILD_DIR=dynamips/
36 PIXEMU_SOURCES=http://xgu.ru/download/pemu_public2007-07-02.tar.bz2
37 PIXEMU_BUILD_DIR=dynamips/
38 KERNEL_VERSION=`uname -r`
41 WORK_DIR=${XENOMIPS_FS_NAME%%.img}
42 WORK_DIR2=/tmp/xenomips-build
44 myecho()
45 {
46 echo '**************************'
47 echo "$@"
48 echo '**************************'
49 }
51 build_and_install_dynamips()
52 {
53 OLD_PWD="`pwd`"
54 DESTDIR=${WORK_DIR}/usr
56 if echo $DYNAMIPS_BUILD | grep -qi ^y
57 then
58 rm -rf ${DYNAMIPS_BUILD_DIR}/
59 mkdir -p ${DYNAMIPS_BUILD_DIR}/
60 cd ${DYNAMIPS_BUILD_DIR}/
61 wget $DYNAMIPS_SOURCES
62 tar xfz dynamips*tar*
63 cd dynamips*/
64 perl -p -i -e s@^PCAP_LIB=.*@PCAP_LIB=-lpcap@ Makefile
65 make
66 else
67 cd ${DYNAMIPS_BUILD_DIR}/dynamips*/
68 fi
69 make install DESTDIR=${DESTDIR}
70 cd ${OLD_PWD}
71 }
73 build_and_install_pixemu()
74 {
75 DESTDIR=${WORK_DIR}/usr/local/pixemu
76 mkdir -p $DESTDIR
77 cp /home/igor/pemu/pemu/* $DESTDIR
78 }
81 if [ $(id -u) != 0 ]
82 then
83 echo You are not root.
84 echo Please, log in as root or run the script with sudo
85 ecit 1
86 fi
89 if echo $XENOMIPS_FS_BUILD | grep -qi ^y
90 then
91 myecho Preparing the Xenomips filesystem
92 dd if=/dev/zero of=${XENOMIPS_FS_NAME} seek=${XENOMIPS_FS_SIZE} bs=1024 count=1
93 mkfs.ext3 -F ${XENOMIPS_FS_NAME}
94 mkdir -p ${WORK_DIR}
95 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
96 debootstrap ${DISTRO} ${WORK_DIR} ${DEBIAN_MIRROR}
97 cat <<SCRIPT | chroot ${WORK_DIR} sh -s
98 unset LANG
99 apt-get -y --force-yes install ${PACKAGES}
100 /etc/init.d/ssh stop
101 cat <<FSTAB > /etc/fstab
102 proc /proc proc defaults 0 0
103 tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
105 /dev/hda1 / ext3 ro 0 0
106 /dev/hda2 /xenomips/ios ext3 ro 0 0
107 /dev/hda3 /xenomips/config ext3 rw 0 0
108 FSTAB
109 mkdir -p /data/Cisco_IOS /xenomips
111 cat <<EOF > /etc/sysctl.conf
112 net/ipv4/ip_forward=1
113 EOF
115 cat <<'INTERFACES' > /etc/network/interfaces
116 auto lo eth0
118 iface lo inet loopback
119 up for i in \`ifconfig -a | grep 'eth.*Link encap' | awk '{print \$1}'\`; do ifconfig \$i up ; done || true
121 #iface eth0 inet dhcp
122 INTERFACES
124 #echo /usr/local/bin/xenomips.sh > /etc/rc.local
125 cd /etc/rcS.d; ln -s ../init.d/xenomips-init S35xenomips-init
126 rm /etc/rc2.d/S*quagga
127 cd /etc/rc2.d; ln -s ../init.d/xenomips S99xenomips
128 cd /etc/rc3.d; ln -s ../init.d/xenomips S99xenomips
129 cd /etc/rc4.d; ln -s ../init.d/xenomips S99xenomips
130 cd /etc/rc5.d; ln -s ../init.d/xenomips S99xenomips
131 cd /etc/rc0.d; ln -s ../init.d/xenomips K01xenomips
132 cd /etc/rc1.d; ln -s ../init.d/xenomips K01xenomips
133 cd /etc/rc6.d; ln -s ../init.d/xenomips K01xenomips
135 #perl -i -p -e s@C_PATH=/etc/quagga@C_PATH=/xenomips/etc/quagga@ /etc/init.d/quagga
136 mv /etc/quagga /etc/quagga.ORIG
137 ln -s /xenomips/config/etc/quagga /etc/quagga
139 mkdir -p /xenomips/{ios,config} /var/lib/xenomips /root/.ssh
141 cat <<PROFILE >> /root/.profile
142 TERM=linux
143 screen -ls | grep -q Attached && screen -x || screen -ls | grep -q Detached && screen -r
144 PROFILE
145 SCRIPT
147 for kernel_version in ${KERNEL_VERSION} 2.6.18-without-PAE-4-xen-686
148 do
149 cp -R /lib/modules/${KERNEL_VERSION} ${WORK_DIR}/lib/modules
150 done
152 cp ${XENOMIPS_DIR}/xenomips-init ${WORK_DIR}/etc/init.d/
153 cp ${XENOMIPS_DIR}/xenomips.sh ${WORK_DIR}/etc/init.d/xenomips
154 sudo chmod +x ${WORK_DIR}/etc/init.d/xenomips ${WORK_DIR}/etc/init.d/xenomips-init
156 cat ${SSH_OPEN_KEY} > ${WORK_DIR}/root/.ssh/authorized_keys
157 chmod 600 ${WORK_DIR}/root/.ssh/authorized_keys
159 build_and_install_dynamips
160 build_and_install_pixemu
161 kill $(lsof +D ${WORK_DIR} | awk '{print $2}' | grep -v PID)
162 pkill ntpd
163 umount ${WORK_DIR}
164 fi
167 if echo $CONFIG_FS_BUILD | grep -qi ^y
168 then
169 mkdir -p ${WORK_DIR}
170 mount -o loop ${XENOMIPS_FS_NAME} ${WORK_DIR}
171 mkdir -p ${WORK_DIR2}
172 cp -a ${WORK_DIR}/etc/quagga.ORIG ${WORK_DIR2}/quagga
173 perl -i -p -e 's/=no/=yes/' ${WORK_DIR2}/quagga/daemons
174 touch ${WORK_DIR2}/quagga/{zebra,bgpd,ospfd,ripd,ripngd,ospf6d,isisd}.conf
175 cp -a ${WORK_DIR}/usr/local/pixemu ${WORK_DIR2}/pixemu
176 umount ${WORK_DIR}
178 myecho Preparing the Xenomips config filesystem
179 dd if=/dev/zero of=${CONFIG_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
180 mkfs.ext3 -F ${CONFIG_FS_NAME}
182 mount -o loop ${CONFIG_FS_NAME} ${WORK_DIR}
183 mkdir -p ${WORK_DIR}/{dynamips,etc}
184 mv ${WORK_DIR2}/quagga ${WORK_DIR}/etc
185 mv ${WORK_DIR2}/pixemu ${WORK_DIR}/
186 dd if=/dev/zero of=${WORK_DIR}/pixemu/FLASH bs=1k count=16k
187 umount ${WORK_DIR}
189 myecho Creating $CONFIG_FS_NUMBER copies of the Xenomips config filesystem
190 for i in `seq 0 $CONFIG_FS_NUMBER`
191 do
192 cp ${CONFIG_FS_NAME} `echo ${CONFIG_FS_NAME} | sed s/XXX/$i/`
193 done
194 fi
197 if echo $IOS_FS_BUILD | grep -qi ^y
198 then
199 myecho Preparing the filesystem with the IOSes
200 dd if=/dev/zero of=${IOS_FS_NAME} bs=1k count=1 seek=${CONFIG_FS_SIZE}
201 mkfs.ext3 -F ${IOS_FS_NAME}
202 mount -o loop ${IOS_FS_NAME} ${WORK_DIR}
203 cp ${IOS_DIR}/* ${WORK_DIR}
204 umount ${WORK_DIR}
205 fi