warbo-utilities: b31a783f06717b7bc2ded6b8f8c8d2573e569755

     1: { bash, iptables, wrap }:
     2: 
     3: wrap {
     4:   name = "phone";
     5:   paths = [ bash iptables ];
     6:   script = ''
     7:     #!${bash}/bin/bash
     8:     set -e
     9: 
    10:     [[ -n "$DEVICE" ]] || DEVICE="enp0s29f0u2"
    11:     echo "Using DEVICE '$DEVICE'"                                    1>&2
    12:     echo "NOTE: The OpenMoko should appear as '$DEVICE' in ifconfig" 1>&2
    13: 
    14:     [[ -n "$ADDRESS" ]] || ADDRESS="192.168.1.200"
    15:     echo "Using ADDRESS '$ADDRESS'" 1>&2
    16:     echo "NOTE: This is the static IP we'll set on our end" 1>&2
    17: 
    18:     # "Easy" method; unreliable
    19:     #sudo ip address add "$ADDRESS"/24 dev "$DEVICE"
    20:     #sudo ip link set dev "$DEVICE" up
    21: 
    22:     # "Harder" method; seems to work, also forwards the Internet connection
    23:     # shellcheck disable=SC2001
    24:     ZERO=$(echo "$ADDRESS" | sed -e 's/[0-9]*$/0/g')
    25:     sudo iptables -A POSTROUTING -t nat -j MASQUERADE -s "$ZERO"/24
    26:     sudo sysctl -w net.ipv4.ip_forward=1
    27:     sudo ip addr add "$ADDRESS"/24 dev "$DEVICE"
    28: 
    29:     echo "Phone should now be available at 192.168.1.202"                 1>&2
    30:     echo "If not, run 'ifconfig' on the phone to make sure that's its IP" 1>&2
    31:   '';
    32: }

Generated by git2html.