pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

pastebin - collaborative debugging tool View Help


Posted by erika on Mon 14 Jul 01:06
report abuse | View followups from Anonymous | download | new post

  1. #!/bin/bash
  2.  
  3. # This script sets up bridged networking with qemu on FreeBSD
  4. #
  5. #
  6. #caveats:
  7. # * the script assumes that the tap interfaces are created in sequential order
  8. #   (eg tap12 is not created before tap5)
  9. # * if there is one network bridge found, the script will use that one bridge
  10. #   to attach the tap interfaces to no matter what you had in mind when
  11. #   creating that bridge. If there is more than one, the script will create its
  12. #   own and bridge $nic and the tap devices created by qemu together
  13. #
  14. # Those are not a technical limit, it is possible to script that, I just did
  15. # not do it (yet).
  16. #
  17. #usage:
  18. # in qemu-launcher set nic setting to "create tap device"
  19. # * put in this script in the field "TUN/TAP configuration script:" in
  20. #   quemu-launcher. when not using qemu launcher, use this script as
  21. #   configuration script on command line.
  22. # * put this script with command line option -e surrounded with $( ) into the field
  23. #   "Name of the Network Interface:" in qemu-launcher. just
  24. #   like $(name_of_this_script -e)
  25. # * adjust settings in this script (nic, IFCONFIG and $SUDO - leave SUDO empty
  26. #   if you do not want to use sudo)
  27. # * set up sudo to let your user execute ifconfig without entering a password
  28. #
  29.  
  30. # standard nic
  31. nic=fxp0
  32.  
  33. # ifconfig command
  34. IFCONFIG=/sbin/ifconfig
  35. SUDO=sudo
  36.  
  37. #needs to be empty at first
  38. bridge=
  39.  
  40. #echo "tap interface: $@"
  41. [[ $@ == "-e" ]] && {
  42. # echo the next tap device to be created - stupid qemu-launcher....
  43.   tap=$($SUDO $IFCONFIG |grep tap|cut -d: -f1|tail -n1)
  44.   tnum=$(echo $tap|tr -d a-z)
  45.   [[ -n $tnum ]] && ((tnum+=1))
  46.   num=${tnum:-0}
  47.   echo tap${tnum}
  48.   exit
  49. }
  50.  
  51.  
  52. # check if there is already a bridge:
  53. # if there is more than one bridge, this script creates its own and bridges
  54. # that with $nic
  55. [[ $($SUDO $IFCONFIG |grep -c bridge) -eq 1 ]] && bridge=$($SUDO $IFCONFIG |grep bridge|cut -d: -f1)
  56.  
  57. [[ -z $bridge ]] && {
  58.   bridge=$($SUDO $IFCONFIG bridge create)
  59.   $SUDO $IFCONFIG $nic 0.0.0.0
  60.   $SUDO $IFCONFIG $bridge addm $nic
  61.   $SUDO /sbin/dhclient $bridge
  62. }
  63.  
  64. # check which tap device was created by qemu
  65. tap=$($SUDO $IFCONFIG | grep tap|cut -d: -f1|tail -n 1)
  66.  
  67. echo created tap device: $tap  
  68. $SUDO $IFCONFIG $bridge addm $tap
  69. $SUDO $IFCONFIG $bridge up
  70.  
  71. $SUDO $IFCONFIG $tap 0.0.0.0
  72.  
  73. true

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post