NETem - Network Link Emulator for GNS3

NETem.sh 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. set -e
  2. set -x
  3. # TCE directory back to ramdisk
  4. mv /etc/sysconfig/tcedir /etc/sysconfig/tcedir.hd
  5. ln -s /tmp/tce /etc/sysconfig/tcedir
  6. mkdir build
  7. cd build
  8. tce-load -wi squashfs-tools
  9. # create utf8-locale
  10. tce-load -wi getlocale
  11. sudo mkdir -p /usr/lib/locale
  12. sudo localedef -i en_US -c -f UTF-8 en_US.UTF-8
  13. sudo localedef -i en_US -c -f UTF-8 C.UTF-8
  14. sudo mkdir -p /tmp/utf8-locale/usr/lib/locale
  15. sudo cp -p /usr/lib/locale/* /tmp/utf8-locale/usr/lib/locale/
  16. mksquashfs /tmp/utf8-locale utf8-locale.tcz
  17. md5sum utf8-locale.tcz > utf8-locale.tcz.md5.txt
  18. # create python3dialog
  19. tce-load -wi python3-dev
  20. wget https://bootstrap.pypa.io/get-pip.py
  21. sudo python3 get-pip.py
  22. rm get-pip.py
  23. tce-load -wi dialog
  24. sudo LANG=C.UTF-8 pip3 install pythondialog
  25. sudo mkdir -p /tmp/python3dialog/usr/local/lib/python3.4/site-packages
  26. sudo cp -a /usr/local/lib/python3.4/site-packages/dialog* /tmp/python3dialog/usr/local/lib/python3.4/site-packages/
  27. sudo cp -a /usr/local/lib/python3.4/site-packages/pythondialog* /tmp/python3dialog/usr/local/lib/python3.4/site-packages/
  28. mksquashfs /tmp/python3dialog python3dialog.tcz
  29. md5sum python3dialog.tcz > python3dialog.tcz.md5.txt
  30. echo -e 'python3.tcz\ndialog.tcz' > python3dialog.tcz.dep
  31. # TCEDIR back to harddisk
  32. rm -f /etc/sysconfig/tcedir; mv /etc/sysconfig/tcedir.hd /etc/sysconfig/tcedir
  33. mkdir -p /etc/sysconfig/tcedir/optional
  34. chmod 775 /etc/sysconfig/tcedir/optional
  35. rm -f /usr/local/tce.installed/*
  36. # install utf8-locale
  37. cp -p utf8-locale.tcz* /etc/sysconfig/tcedir/optional/
  38. echo 'utf8-locale.tcz' >> /etc/sysconfig/tcedir/onboot.lst
  39. # install python3 without TK
  40. cp -p /tmp/tce/optional/python3.tcz /etc/sysconfig/tcedir/optional/
  41. cp -p /tmp/tce/optional/python3.tcz.md5.txt /etc/sysconfig/tcedir/optional/
  42. sed -e '/^tk/ d' /tmp/tce/optional/python3.tcz.dep > /etc/sysconfig/tcedir/optional/python3.tcz.dep
  43. echo 'python3.tcz' >> /etc/sysconfig/tcedir/onboot.lst
  44. for pkg in `cat /etc/sysconfig/tcedir/optional/python3.tcz.dep`; do tce-load -w $pkg; done
  45. # install python3dialog
  46. cp -p python3dialog.tcz* /etc/sysconfig/tcedir/optional/
  47. echo 'python3dialog.tcz' >> /etc/sysconfig/tcedir/onboot.lst
  48. tce-load -w dialog
  49. # additional linux networking modules
  50. KERNEL=`uname -r`
  51. tce-load -w net-bridging-$KERNEL
  52. echo "net-bridging-$KERNEL.tcz" >> /etc/sysconfig/tcedir/onboot.lst
  53. tce-load -w net-sched-$KERNEL
  54. echo "net-sched-$KERNEL.tcz" >> /etc/sysconfig/tcedir/onboot.lst
  55. # clean up build environment
  56. cd ..
  57. rm -r build
  58. # NETem menu system
  59. . /etc/init.d/tc-functions
  60. http=http://`getbootparam http`
  61. wget $http/NETem/netem-conf.py
  62. chmod +x netem-conf.py
  63. # autologin on serial console
  64. sudo sed -i -e '/^tty1:/ s/^.*/tty1::respawn:\/sbin\/getty 38400 tty1/' -e '/^ttyS0:/ s/^.*/ttyS0::askfirst:\/sbin\/getty -nl \/sbin\/autologin 38400 ttyS0 xterm/' /etc/inittab
  65. sudo sed -i -e 's/tty1/`\/usr\/bin\/tty`/' /sbin/autologin
  66. echo 'sbin/autologin' >> /opt/.filetool.lst
  67. # autostart netem-conf
  68. sed -i -e '/^TERMTYPE/,$ d' .profile
  69. cat >> .profile << 'EOF'
  70. # autostart netem-conf only on local terminals
  71. TERMTYPE=`/usr/bin/tty`
  72. if [ "${TERMTYPE:5:3}" = "tty" ]; then
  73. ./netem-conf.py
  74. rm -f /var/log/autologin
  75. fi
  76. EOF
  77. # disable automatic interface configuration with dhcp
  78. sudo sed -i -e '/label microcore/,/append / s/\(append .*\)/\1 nodhcp/' /mnt/sda1/boot/extlinux/extlinux.conf
  79. # set locale and configure network at startup
  80. sed -i -e '3,$ d' /opt/bootlocal.sh
  81. sed -n -e '1,/^\/opt\/bootlocal/ p' /opt/bootsync.sh | head -n -1 > /tmp/bootsync.head
  82. sed -n -e '/^\/opt\/bootlocal/,$ p' /opt/bootsync.sh > /tmp/bootsync.tail
  83. cat /tmp/bootsync.head > /opt/bootsync.sh
  84. cat >> /opt/bootsync.sh <<'EOF'
  85. . /etc/init.d/tc-functions
  86. # default LANG=C.UTF-8
  87. [ ! -f /etc/sysconfig/language ] || [ "`cat /etc/sysconfig/language`" = "LANG=C" ] && \
  88. echo "LANG=C.UTF-8" > /etc/sysconfig/language
  89. # Configure network interfaces only when boot parameter "nodhcp" is used
  90. if grep -q -w nodhcp /proc/cmdline; then
  91. echo -en "${BLUE}Configuring network interfaces... ${NORMAL}"
  92. # This waits until all devices have registered
  93. /sbin/udevadm settle --timeout=10
  94. ip link add name br0 type bridge
  95. sysctl -q -w net.ipv6.conf.br0.disable_ipv6=1
  96. sysctl -q -w net.ipv6.conf.eth0.disable_ipv6=1
  97. ip link set dev eth0 promisc on
  98. ip link set dev eth0 mtu 2000
  99. ip link set dev eth0 up
  100. ip link set dev eth0 master br0
  101. sysctl -q -w net.ipv6.conf.eth1.disable_ipv6=1
  102. ip link set dev eth1 promisc on
  103. ip link set dev eth1 mtu 2000
  104. ip link set dev eth1 up
  105. ip link set dev eth1 master br0
  106. ip link set dev br0 up
  107. echo -e "${GREEN}Done.${NORMAL}"
  108. fi
  109. EOF
  110. cat /tmp/bootsync.tail >> /opt/bootsync.sh
  111. # Done