12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- #!/bin/bash
- #
- # .---. . .
- # | | |
- # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
- # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
- # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
- #
- # Freedom in the Cloud
- #
- # Network functions
- #
- # License
- # =======
- #
- # Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
- #
- # This program is free software: you can redistribute it and/or modify
- # it under the terms of the GNU Affero General Public License as published by
- # the Free Software Foundation, either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU Affero General Public License for more details.
- #
- # You should have received a copy of the GNU Affero General Public License
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- # If the system is on an IPv6 network
- IPV6_NETWORK='2001:470:26:307'
-
- # The static IP address of the system within the local network
- # By default the IP address is dynamic within your LAN
- LOCAL_NETWORK_STATIC_IP_ADDRESS=
-
- # IP address of the router (gateway)
- ROUTER_IP_ADDRESS="192.168.1.254"
-
- MESH_INSTALL_DIR=/var/lib
-
- function install_static_network {
- if [[ $(is_completed $FUNCNAME) == "1" ]]; then
- return
- fi
- if [[ $INSTALLING_ON_BBB == "yes" ]]; then
- return
- fi
- if [ ! $LOCAL_NETWORK_STATIC_IP_ADDRESS ]; then
- return
- fi
-
- echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
- echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
- echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces
-
- echo 'auto eth0' > /etc/network/interfaces.d/static
- echo 'iface eth0 inet static' >> /etc/network/interfaces.d/static
- echo " address $LOCAL_NETWORK_STATIC_IP_ADDRESS" >> /etc/network/interfaces.d/static
- echo ' netmask 255.255.255.0' >> /etc/network/interfaces.d/static
- echo " gateway $ROUTER_IP_ADDRESS" >> /etc/network/interfaces.d/static
-
- mark_completed $FUNCNAME
- }
-
- function get_ipv4_address {
- IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
- echo $(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}' | awk -F '/' '{print $1}')
- }
-
- function get_ipv6_address {
- echo $(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
- }
-
- # NOTE: deliberately no exit 0
|