Package: freedombox-setup
Version: 0.5
Severity: normal
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

The attached patchset proposes the following:

- - Perform Wi-Fi access point setup on all Wi-Fi devices available and
  not only on Dreamplug's Wi-Fi.

- - Merge Wi-Fi configuration into the rest of the network configuration.

- - Don't install firmware-libertas during first boot.  Network may not
  be available during first boot.  Instead install it in setup step.

- - Give network connections, prettier, user-readable names.

- - Remove the NULL MACs fix which does not work.

- - Remove the interface-detect script that is no longer needed.

I have performed the following tests on a full-build:

- - Network first-run setup should happen properly without errors.

- - Network name is 'FreedomBox WAN' for WAN connections (log message
  should be proper)

- - Network name 'FreedomBox LAN <interface>' for LAN connections (log
  message should be proper).

- - /sbin/interface-detect should not exist

- - On Dreamplug image firmware-libertas should be installed (verify by
  mounting the image).

- - 30_wifi-ap-setup should not exist

- - On a machine with single network card, only 'FreedomBox WAN' is created
  with internal zone.

- - On a machine with multiple network cards, one as 'FreedomBox WAN' and
  remaining as 'FreedomBox LAN <interface>' (internal) are created.

I could not perform the following tests due to lack of a Dreamplug or a
Wi-Fi device that is supported by FreedomBox without extra firmware.

- - Wireless interface should get setup as 'FreedomBox $interface'

- - Wireles SSID shoould be 'FreedomBox$interface'

- - Password should be 'freedombox123'

- - Zone should be internal

Incompleteness:

- - We should remove freedombox-setup dependency on python3 in control
  and rules files.  I will submit another patch for this.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBAgAGBQJV4qaxAAoJEDbDYUQMm8lxxqwP/2vWjlngdGYz9/R02/xKpinS
o8/wFBuGQ7r5rOW6DnG82YMUovQ0nwQcpmyzX5dxboF/aPLSAlq5gMHnCj+E0pNw
d5vz4PhDdqg9S3CUrcP2sHHbfjmSk/8dYEvCCm7nV13zK99w46V9eY8vOU+CzsGY
rUTOLTmBw9bNxC7MbsxFT4rfGovk4lECCplVHSeVXgbuuUe2J4TD1mwwwAREOHb3
k34jpdq/LiYHN61q8qzOJisowFx/+KwjZs4CFAmRLCyL/gswsQUpdswNhfpeaM/+
1zw2VBYzaFDPCqmoPGYZFrF8G7BY8YaYNbFxF+uHQqCWyxqznLtagOk2Bci4iGhf
ydJ+k2tFcMhRi5a2J0C/YladKffm8fs9KZsvkPvnj+JxYwLUk8rsv8qnY0oLUT/B
rMrZ1c1Fax/jUkZ+CLvITRUmM9pvLosJqznsT45ZTnm5xVTBpw3fB+DERo5NMV2C
TANkPu79EUiEKNbp6i43XwCY1F8VDJ9Md1cDLHNq2MJ6Nv0sk73/i80OUN1YiIoC
qCgi7I/9i7B2zkIRDCEnV9d/V/osGBKsaApAphG2+Oww1AR2ts9LKScQDRgwh80B
QBNUmPP/AaRsAU9fs3gcRcztrza/59/w3gHluSetNn4NAiPBxxQs1vJLwMg8SjNH
eNKmyihOSqD4qpMbJbwC
=uHyt
-----END PGP SIGNATURE-----
>From ed1ffcdf2e8fc678ef0cd770f2d7634d66cb71ee Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa <su...@medhas.org>
Date: Sat, 15 Aug 2015 00:25:51 +0530
Subject: [PATCH 1/5] Remove outdated fix for NULL MAC addresses

---
 first-run.d/05_network | 44 --------------------------------------------
 1 file changed, 44 deletions(-)

diff --git a/first-run.d/05_network b/first-run.d/05_network
index 268133c..62aca8f 100755
--- a/first-run.d/05_network
+++ b/first-run.d/05_network
@@ -14,8 +14,6 @@ else
     IFACES_FILE=/etc/network/interfaces
 fi
 
-INTERFACE_DETECT="interface-detect"
-
 function get-wired-interfaces {
     # XXX: Sorting of interfaces is non-numeric
     WIRED_IFACES=$(nmcli --terse --fields type,device device | grep "^ethernet:" | cut -d: -f2 | sort)
@@ -71,46 +69,6 @@ function one-wired-setup {
     configure-regular-interface $interface internal
 }
 
-function update-null-macs {
-    # if interface's mac address is all zeroes, change it to 0:0:0:X:X:X
-
-    # iterate through all the interfaces
-    for description in $WIRED_IFACES
-    do
-        name=`echo $description | cut -d"," -f1`
-        mac=`echo $description | cut -d"," -f3`
-
-        # if it's null, swap it out in the interface file.
-        if [[ "$mac" == "00:00:00:00:00:00" ]]
-        then
-            # if macchanger gave us a new mac, use that.  or, generate dummy.
-            if [[ `macchanger -a $name` ]]
-            then
-                newMac=`$INTERFACE_DETECT | grep $name | cut -d, -f3`
-            else
-                generate_dummy_mac
-            fi
-
-            # save new mac.
-            sed -i "s/# $name: hwaddress ether .*$/hwaddress ether $newMac/" \
-                $IFACES_FILE
-        fi
-    done
-}
-
-function generate_dummy_mac {
-    # set "newMac" to a GlobalScale MAC address: F0:AD:4E:XX:XX:XX
-
-    # generate 3 sets of 2 random hex digits.
-    allSix="$(tr -dc '[:xdigit:]' < /dev/urandom | tr '[:lower:]' '[:upper:]' | head -c 6)"
-    high=`echo $allSix | cut -b1,2`
-    med=`echo $allSix | cut -b3,4`
-    low=`echo $allSix | cut -b5,6`
-
-    # generate three sets of 2 digits
-    newMac="F0:AD:4E:$high:$med:$low"
-}
-
 echo "Setting up network configuration..."
 get-wired-interfaces
 
@@ -125,6 +83,4 @@ case $NO_OF_WIRED_IFACES in
         multi-wired-setup $WIRED_IFACES
 esac
 
-update-null-macs
-
 echo "Done setting up network configuration."
-- 
2.5.0


>From 1e4624f9d186a965119df2120a8ff86085a39329 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa <su...@medhas.org>
Date: Sun, 16 Aug 2015 15:18:50 +0530
Subject: [PATCH 2/5] Name network connections more readably

---
 first-run.d/05_network | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/first-run.d/05_network b/first-run.d/05_network
index 62aca8f..2147b0a 100755
--- a/first-run.d/05_network
+++ b/first-run.d/05_network
@@ -23,22 +23,24 @@ function get-wired-interfaces {
 function configure-regular-interface {
     interface="$1"
     zone="$2"
+    connection_name="FreedomBox WAN"
 
     # Create n-m connection for a regular interface
-    nmcli con add con-name freedomboxWAN ifname $interface type ethernet
-    nmcli con modify freedomboxWAN connection.autoconnect TRUE
-    nmcli con modify freedomboxWAN connection.zone $zone
+    nmcli con add con-name $connection_name ifname $interface type ethernet
+    nmcli con modify $connection_name connection.autoconnect TRUE
+    nmcli con modify $connection_name connection.zone $zone
 
-    echo "Configured interface $interface for $zone use."
+    echo "Configured interface $interface for $zone use as $connection_name."
 }
 
 function configure-shared-interface {
     interface="$1"
+    connection_name="FreedomBox LAN $interface"
 
     # Create n-m connection for eth1
-    nmcli con add con-name freedomboxLAN$interface ifname $interface type ethernet
-    nmcli con modify freedomboxLAN$interface connection.autoconnect TRUE
-    nmcli con modify freedomboxLAN$interface connection.zone internal
+    nmcli con add con-name $connection_name ifname $interface type ethernet
+    nmcli con modify $connection_name connection.autoconnect TRUE
+    nmcli con modify $connection_name connection.zone internal
 
     # Configure this interface to be shared with other computers.
     #  - Self-assign an address and network
@@ -46,9 +48,10 @@ function configure-shared-interface {
     #  - Start and manage DHCP server (dnsmasq)
     #  - Register address with mDNS
     #  - Add firewall rules for NATing from this interface
-    nmcli con modify freedomboxLAN$interface ipv4.method shared
+    nmcli con modify $connection_name ipv4.method shared
+
+    echo "Configured interface $interface for shared use as $connection_name."
 
-    echo "Configured interface $interface for shared use."
 }
 
 function multi-wired-setup {
-- 
2.5.0


>From 897cecc50d3b1a2e7e06f2c4e305d382d7fbb9bc Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa <su...@medhas.org>
Date: Sun, 16 Aug 2015 15:56:03 +0530
Subject: [PATCH 3/5] Remove unused script interface-detect

---
 debian/freedombox-setup.install |   1 -
 sbin/interface-detect           | 107 ----------------------------------------
 2 files changed, 108 deletions(-)
 delete mode 100755 sbin/interface-detect

diff --git a/debian/freedombox-setup.install b/debian/freedombox-setup.install
index 8bfed71..b0871aa 100644
--- a/debian/freedombox-setup.install
+++ b/debian/freedombox-setup.install
@@ -5,7 +5,6 @@ first-run.d usr/lib/freedombox
 sysctl.d/freedombox-setup.conf etc/sysctl.d
 sbin/copy2dream usr/sbin
 sbin/machine-detect usr/sbin
-sbin/interface-detect usr/sbin
 sbin/tor-get-orport usr/sbin
 lxc-templates/lxc-debian-freedombox usr/share/lxc/templates
 avahi-services etc/avahi/services
diff --git a/sbin/interface-detect b/sbin/interface-detect
deleted file mode 100755
index b2d14eb..0000000
--- a/sbin/interface-detect
+++ /dev/null
@@ -1,107 +0,0 @@
-#!/usr/bin/python3
-
-"""
-Displays information about how network interfaces connect.
-
-This script displays connection-method information about the unique
-network interfaces it detects.  It displays output in the form:
-
-: interface-name,(wired|wireless),MAC
-
-Copyright (C) 2014  Nick Daly
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU 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
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
-
-import subprocess
-import sys
-
-
-def execute(command):
-    """Execute and return a command's stdout and stderr."""
-    process = subprocess.Popen(command, stdout=subprocess.PIPE,
-                               stderr=subprocess.PIPE)
-    stdout, stderr = process.communicate()
-    return stdout.decode(), stderr.decode()
-
-
-def parse_interface_and_macs():
-    """Associate all interfaces with their MAC addresses.
-
-    Parse *ifconfig* output and record each interface's MAC address.
-    Also, record the interfaces that share MAC addresses.
-    """
-    output, _ = execute(['/sbin/ifconfig', '-a'])
-
-    interfaces = {}
-    for line in output.splitlines():
-        if not line.split() or line.startswith(' '):
-            continue
-
-        line = line.split()
-        interface = line[0]
-        mac = line[-1]
-
-        interfaces[interface] = {'id': interface, 'mac': mac, 'type': None}
-
-    return interfaces
-
-
-def parse_connection_type(interfaces):
-    """Identify and record which interfaces are wired and wireless.
-
-    *iwconfig* returns wireless interfaces in *stdout* and wired
-    interfaces in *stderr*.  It's quite strange.
-    """
-    output, error = execute(['/sbin/iwconfig'])
-    parse_iwconfig(interfaces, 'wired', error)
-    parse_iwconfig(interfaces, 'wireless', output)
-
-
-def parse_iwconfig(interfaces, type_, lines):
-    """Actually parse the *iwconfig* output.
-
-    Each *iwconfig* line that identifies an interface starts with the
-    interface's name and contains data about the networks supported or
-    the line ~no wireless extensions.~, if the interface is a wired
-    interface.
-
-    *iwconfig* doesn't currently appear to display interface aliases,
-    so we can use its output to filter out the aliases that don't
-    refer to real, physical interfaces.
-    """
-    for line in lines.splitlines():
-        if not line.split() or line.startswith(' '):
-            continue
-
-        interface = line.split()[0]
-        interfaces[interface]['type'] = type_
-
-
-def main():
-    """Parse and print interfaces and their types."""
-    try:
-        interfaces = parse_interface_and_macs()
-        parse_connection_type(interfaces)
-    except OSError as exception:
-        print('Command not found: ifconfig or iwconfig', file=sys.stderr)
-        sys.exit(1)
-
-    for interface in interfaces.values():
-        if interface['type']:
-            print('{id},{type},{mac}'.format(**interface))
-
-
-if __name__ == "__main__":
-    main()
-- 
2.5.0


>From fc6419f6fbae6f89aebe8c96b37a3e4e6a944190 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa <su...@medhas.org>
Date: Mon, 17 Aug 2015 21:57:05 +0530
Subject: [PATCH 4/5] Merge wifi setup into network setup

---
 first-run.d/05_network       | 33 +++++++++++++++++++++++++++++++--
 first-run.d/30_wifi-ap-setup | 32 --------------------------------
 setup.d/10_hardware          | 12 ++++++++++++
 3 files changed, 43 insertions(+), 34 deletions(-)
 delete mode 100755 first-run.d/30_wifi-ap-setup

diff --git a/first-run.d/05_network b/first-run.d/05_network
index 2147b0a..3dff23b 100755
--- a/first-run.d/05_network
+++ b/first-run.d/05_network
@@ -14,10 +14,12 @@ else
     IFACES_FILE=/etc/network/interfaces
 fi
 
-function get-wired-interfaces {
+function get-interfaces {
     # XXX: Sorting of interfaces is non-numeric
     WIRED_IFACES=$(nmcli --terse --fields type,device device | grep "^ethernet:" | cut -d: -f2 | sort)
     NO_OF_WIRED_IFACES=$(echo $WIRED_IFACES | wc -w)
+
+    WIRELESS_IFACES=$(nmcli --terse --fields type,device device | grep "^wifi:" | cut -d: -f2 | sort)
 }
 
 function configure-regular-interface {
@@ -51,7 +53,23 @@ function configure-shared-interface {
     nmcli con modify $connection_name ipv4.method shared
 
     echo "Configured interface $interface for shared use as $connection_name."
+}
+
+function configure-wireless-interface {
+    interface="$1"
+    connection_name="FreedomBox $interface"
+    ssid="FreedomBox$interface"
+    secret="freedombox123"
+
+    configure-shared-interface $interface
+    nmcli con add con-name "FreedomBox AP $interface" ifname $interface type wifi ssid $ssid
+    nmcli con modify $connection_name connection.autoconnect TRUE
+    nmcli con modify $connection_name connection.zone internal
+    nmcli con modify $connection_name wifi.mode ap
+    nmcli con modify $connection_name wifi-sec.key-mgmt wpa-psk
+    nmcli con modify $connection_name wifi-sec.psk $secret
 
+    echo "Configured interface $interface for shared use as $connection_name."
 }
 
 function multi-wired-setup {
@@ -72,8 +90,17 @@ function one-wired-setup {
     configure-regular-interface $interface internal
 }
 
+function wireless-setup {
+    interface="$@"
+
+    for interface in $interfaces
+    do
+        configure-wireless-interface $interface
+    done
+}
+
 echo "Setting up network configuration..."
-get-wired-interfaces
+get-interfaces
 
 case $NO_OF_WIRED_IFACES in
     "0")
@@ -86,4 +113,6 @@ case $NO_OF_WIRED_IFACES in
         multi-wired-setup $WIRED_IFACES
 esac
 
+wireless-setup $WIRELESS_IFACES
+
 echo "Done setting up network configuration."
diff --git a/first-run.d/30_wifi-ap-setup b/first-run.d/30_wifi-ap-setup
deleted file mode 100755
index d359404..0000000
--- a/first-run.d/30_wifi-ap-setup
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh
-#
-# selectively configure wireless access point with libertas firmware.
-
-echo "Configuring WIFI..."
-
-# If users have selected non-free packages, install firmware-libertas.
-. machine-detect
-if [ "$MACHINE" = "dreamplug" ]
-then
-    if [ -n "`grep non-free /etc/apt/sources.list`" ]
-    then
-        echo "Installing non-free WIFI package: firmware-libertas..."
-        apt-get install firmware-libertas
-
-	echo "Creating WIFI AP connection..."
-	nmcli con add con-name freedomboxAP ifname uap0 \
-	      type wifi ssid freedombox ip4 192.168.2.1/24
-	nmcli con modify freedomboxAP connection.autoconnect TRUE
-	nmcli con modify freedomboxAP connection.zone internal
-	nmcli con modify freedomboxAP wifi.mode ap
-	nmcli con modify freedomboxAP wifi-sec.key-mgmt wpa-psk
-	nmcli con modify freedomboxAP wifi-sec.psk freedombox123
-
-    else
-        echo "Non-free packages disabled.  Skipping DreamPlug WIFI config."
-    fi
-else
-    echo "Not a DreamPlug.  Skipping DreamPlug WIFI config."
-fi
-
-echo "Done Configuring WIFI."
diff --git a/setup.d/10_hardware b/setup.d/10_hardware
index ab52ff9..9875c9d 100755
--- a/setup.d/10_hardware
+++ b/setup.d/10_hardware
@@ -7,6 +7,17 @@ enable_serial_console() {
     echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
 }
 
+dreamplug_install_extra_packages() {
+    # Install additional hardware related packages for Dreamplug
+    if [ -n "`grep non-free /etc/apt/sources.list`" ]
+    then
+        echo "Installing non-free WIFI package: firmware-libertas"
+        apt-get install -y firmware-libertas
+    else
+        echo "Non-free packages disabled.  Skipping DreamPlug non-free WIFI."
+    fi
+}
+
 dreamplug_flash() {
     # allow flash-kernel to work without valid /proc contents
     # ** this doesn't *really* work, since there are too many checks
@@ -235,6 +246,7 @@ tmp_on_tmpfs
 
 case "$MACHINE" in
     dreamplug|guruplug)
+	dreamplug_install_extra_packages
 	dreamplug_flash
 	dreamplug_repack_kernel
 	enable_serial_console ttyS0
-- 
2.5.0


>From a17a4481f605715a21b878fb2949632cf62f9cd5 Mon Sep 17 00:00:00 2001
From: Sunil Mohan Adapa <su...@medhas.org>
Date: Sat, 29 Aug 2015 18:25:42 +0530
Subject: [PATCH 5/5] Fixes to network setup

---
 first-run.d/05_network | 56 +++++++++++++++++++++-----------------------------
 1 file changed, 23 insertions(+), 33 deletions(-)

diff --git a/first-run.d/05_network b/first-run.d/05_network
index 3dff23b..e3bff67 100755
--- a/first-run.d/05_network
+++ b/first-run.d/05_network
@@ -1,18 +1,8 @@
 #!/bin/bash
 
-# Configure networking for device.
+# Configure networking for all wired and wireless devices.
 #
-# Creates a basic network interface file and network-manager connections.
-#
-# First parameter is the path to the network interface file to
-# configure.
-
-if [ -n "$1" ]
-then
-    IFACES_FILE=$1
-else
-    IFACES_FILE=/etc/network/interfaces
-fi
+# Creates network-manager connections.
 
 function get-interfaces {
     # XXX: Sorting of interfaces is non-numeric
@@ -28,11 +18,11 @@ function configure-regular-interface {
     connection_name="FreedomBox WAN"
 
     # Create n-m connection for a regular interface
-    nmcli con add con-name $connection_name ifname $interface type ethernet
-    nmcli con modify $connection_name connection.autoconnect TRUE
-    nmcli con modify $connection_name connection.zone $zone
+    nmcli con add con-name "$connection_name" ifname "$interface" type ethernet
+    nmcli con modify "$connection_name" connection.autoconnect TRUE
+    nmcli con modify "$connection_name" connection.zone "$zone"
 
-    echo "Configured interface $interface for $zone use as $connection_name."
+    echo "Configured interface '$interface' for '$zone' use as '$connection_name'."
 }
 
 function configure-shared-interface {
@@ -40,9 +30,9 @@ function configure-shared-interface {
     connection_name="FreedomBox LAN $interface"
 
     # Create n-m connection for eth1
-    nmcli con add con-name $connection_name ifname $interface type ethernet
-    nmcli con modify $connection_name connection.autoconnect TRUE
-    nmcli con modify $connection_name connection.zone internal
+    nmcli con add con-name "$connection_name" ifname "$interface" type ethernet
+    nmcli con modify "$connection_name" connection.autoconnect TRUE
+    nmcli con modify "$connection_name" connection.zone internal
 
     # Configure this interface to be shared with other computers.
     #  - Self-assign an address and network
@@ -50,9 +40,9 @@ function configure-shared-interface {
     #  - Start and manage DHCP server (dnsmasq)
     #  - Register address with mDNS
     #  - Add firewall rules for NATing from this interface
-    nmcli con modify $connection_name ipv4.method shared
+    nmcli con modify "$connection_name" ipv4.method shared
 
-    echo "Configured interface $interface for shared use as $connection_name."
+    echo "Configured interface '$interface' for shared use as '$connection_name'."
 }
 
 function configure-wireless-interface {
@@ -61,15 +51,15 @@ function configure-wireless-interface {
     ssid="FreedomBox$interface"
     secret="freedombox123"
 
-    configure-shared-interface $interface
-    nmcli con add con-name "FreedomBox AP $interface" ifname $interface type wifi ssid $ssid
-    nmcli con modify $connection_name connection.autoconnect TRUE
-    nmcli con modify $connection_name connection.zone internal
-    nmcli con modify $connection_name wifi.mode ap
-    nmcli con modify $connection_name wifi-sec.key-mgmt wpa-psk
-    nmcli con modify $connection_name wifi-sec.psk $secret
+    configure-shared-interface "$interface"
+    nmcli con add con-name "$connection_name" ifname "$interface" type wifi ssid "$ssid"
+    nmcli con modify "$connection_name" connection.autoconnect TRUE
+    nmcli con modify "$connection_name" connection.zone internal
+    nmcli con modify "$connection_name" wifi.mode ap
+    nmcli con modify "$connection_name" wifi-sec.key-mgmt wpa-psk
+    nmcli con modify "$connection_name" wifi-sec.psk "$secret"
 
-    echo "Configured interface $interface for shared use as $connection_name."
+    echo "Configured interface '$interface' for shared use as '$connection_name'."
 }
 
 function multi-wired-setup {
@@ -77,17 +67,17 @@ function multi-wired-setup {
     shift
     remaining_interfaces="$@"
 
-    configure-regular-interface $first_interface external
+    configure-regular-interface "$first_interface" external
 
     for interface in $remaining_interfaces
     do
-        configure-shared-interface $interface
+        configure-shared-interface "$interface"
     done
 }
 
 function one-wired-setup {
     interface="$1"
-    configure-regular-interface $interface internal
+    configure-regular-interface "$interface" internal
 }
 
 function wireless-setup {
@@ -95,7 +85,7 @@ function wireless-setup {
 
     for interface in $interfaces
     do
-        configure-wireless-interface $interface
+        configure-wireless-interface "$interface"
     done
 }
 
-- 
2.5.0

Reply via email to