freedombone-utils-network 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # Network functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. # If the system is on an IPv6 network
  31. IPV6_NETWORK='2001:470:26:307'
  32. # The static IP address of the system within the local network
  33. # By default the IP address is dynamic within your LAN
  34. LOCAL_NETWORK_STATIC_IP_ADDRESS=
  35. # IP address of the router (gateway)
  36. ROUTER_IP_ADDRESS="192.168.1.254"
  37. MESH_INSTALL_DIR=/var/lib
  38. function install_static_network {
  39. if grep -Fxq "install_static_network" $COMPLETION_FILE; then
  40. return
  41. fi
  42. if [[ $INSTALLING_ON_BBB == "yes" ]]; then
  43. return
  44. fi
  45. if [ ! $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
  46. return
  47. fi
  48. echo '# The loopback network interface' > /etc/network/interfaces
  49. echo 'auto lo' >> /etc/network/interfaces
  50. echo 'iface lo inet loopback' >> /etc/network/interfaces
  51. echo '' >> /etc/network/interfaces
  52. echo '# The primary network interface' >> /etc/network/interfaces
  53. echo 'auto eth0' >> /etc/network/interfaces
  54. echo 'iface eth0 inet static' >> /etc/network/interfaces
  55. echo " address $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/network/interfaces
  56. echo ' netmask 255.255.255.0' >> /etc/network/interfaces
  57. echo " gateway $ROUTER_IP_ADDRESS" >> /etc/network/interfaces
  58. echo " dns-nameservers $NAMESERVER1 $NAMESERVER2" >> /etc/network/interfaces
  59. echo '# Example to keep MAC address between reboots' >> /etc/network/interfaces
  60. echo '#hwaddress ether DE:AD:BE:EF:CA:FE' >> /etc/network/interfaces
  61. echo '' >> /etc/network/interfaces
  62. echo '# The secondary network interface' >> /etc/network/interfaces
  63. echo '#auto eth1' >> /etc/network/interfaces
  64. echo '#iface eth1 inet dhcp' >> /etc/network/interfaces
  65. echo '' >> /etc/network/interfaces
  66. echo '# WiFi Example' >> /etc/network/interfaces
  67. echo "#auto $WIFI_INTERFACE" >> /etc/network/interfaces
  68. echo "#iface $WIFI_INTERFACE inet dhcp" >> /etc/network/interfaces
  69. echo '# wpa-ssid "essid"' >> /etc/network/interfaces
  70. echo '# wpa-psk "password"' >> /etc/network/interfaces
  71. echo '' >> /etc/network/interfaces
  72. echo '# Ethernet/RNDIS gadget (g_ether)' >> /etc/network/interfaces
  73. echo '# ... or on host side, usbnet and random hwaddr' >> /etc/network/interfaces
  74. echo '# Note on some boards, usb0 is automaticly setup with an init script' >> /etc/network/interfaces
  75. echo '#iface usb0 inet static' >> /etc/network/interfaces
  76. echo '# address 192.168.7.2' >> /etc/network/interfaces
  77. echo '# netmask 255.255.255.0' >> /etc/network/interfaces
  78. echo '# network 192.168.7.0' >> /etc/network/interfaces
  79. echo '# gateway 192.168.7.1' >> /etc/network/interfaces
  80. echo 'install_static_network' >> $COMPLETION_FILE
  81. }
  82. # NOTE: deliberately no exit 0