From fb3ddfe2ceafd54b2383e80e015782d5f4ba4551 Mon Sep 17 00:00:00 2001
From: evilsocket <evilsocket@gmail.com>
Date: Tue, 24 Sep 2019 15:50:27 +0200
Subject: [PATCH] scripts folder

---
 README.md                                      |  6 +++++-
 create_sibling.sh => scripts/create_sibling.sh |  0
 scripts/linux_connection_share.sh              | 18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 1 deletion(-)
 rename create_sibling.sh => scripts/create_sibling.sh (100%)
 create mode 100755 scripts/linux_connection_share.sh

diff --git a/README.md b/README.md
index 6936837..7493613 100644
--- a/README.md
+++ b/README.md
@@ -42,7 +42,7 @@ For hackers to learn reinforcement learning, WiFi networking and have an excuse
 
 #### Automatically create an image
 
-You can use the `create_sibling.sh` script to create an - ready to flash - rasbian image with pwnagotchi.
+You can use the `scripts/create_sibling.sh` script to create an - ready to flash - rasbian image with pwnagotchi.
 
 ```shell
 usage: ./create_sibling.sh [OPTIONS]
@@ -56,6 +56,10 @@ usage: ./create_sibling.sh [OPTIONS]
     -h        # Show this help
 ```
 
+#### Host Connection Share
+
+If you connect to the unit via `usb0` (thus using the data port), you might want to use the `scripts/linux_connection_share.sh` script to bring the interface up on your end and share internet connectivity from another interface, so you can update the unit and generally download things from the internet on it.
+
 ### UI
 
 The UI is available either via display if installed, or via http://10.0.0.2:8080/ if you connect to the unit via `usb0` and set a static address on the network interface.
diff --git a/create_sibling.sh b/scripts/create_sibling.sh
similarity index 100%
rename from create_sibling.sh
rename to scripts/create_sibling.sh
diff --git a/scripts/linux_connection_share.sh b/scripts/linux_connection_share.sh
new file mode 100755
index 0000000..e8e94dd
--- /dev/null
+++ b/scripts/linux_connection_share.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+# name of the ethernet gadget interface on the host
+USB_IFACE=${1:-enp0s20f0u1}
+USB_IFACE_IP=10.0.0.1
+USB_IFACE_NET=10.0.0.0/24
+# host interface to use for upstream connection
+UPSTREAM_IFACE=${2:-enxe4b97aa99867}
+
+ip addr add $USB_IFACE_IP/24 dev $USB_IFACE
+ifconfig $USB_IFACE up
+
+iptables -A FORWARD -o $UPSTREAM_IFACE -i $USB_IFACE -s $USB_IFACE_NET -m conntrack --ctstate NEW -j ACCEPT
+iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
+iptables -t nat -F POSTROUTING
+iptables -t nat -A POSTROUTING -o $UPSTREAM_IFACE -j MASQUERADE
+
+echo 1 > /proc/sys/net/ipv4/ip_forward