Last active
September 6, 2019 01:08
-
-
Save sr229/6950ab77a7fb5a6b6fc0891a2a398229 to your computer and use it in GitHub Desktop.
USB Ethernet Configuration Script for Raspberry Pi Zero. Source: http://www.circuitbasics.com/raspberry-pi-zero-ethernet-gadget/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Installation Script for usb_ethserv | |
set -eo pipefail | |
CONF_URL="https://gist.github.com/sr229/6950ab77a7fb5a6b6fc0891a2a398229/raw/2578e785ab9617f6909799f757e0a9014db45f7a/usb_ethserv" | |
if [ -z $(command -v wget) ]; then | |
echo "Setup requires wget" | |
exit 0 | |
fi | |
if [ -f "/usr/bin/usb_ethserv"]; then | |
echo "Already installed. Not continuing." | |
exit 0 | |
fi | |
echo "Running preinstall. Please be patient" | |
if [ -z $(cat /boot/config.txt | cat dtoverlay=dwc2) ]; then | |
echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt | |
echo "dwc2" | sudo tee -a /etc/modules | |
fi | |
sudo echo "libcomposite" | sudo tee -a /etc/modules | |
echo "Installing script to /usr/bin" | |
wget -qO - $CONF_URL > /usr/bin/usb_ethserv && chmod -R 755 /usr/bin/usb_ethserv | |
echo "Adding Script to rc.local (Required so it starts everytime you plug your Raspberry)" | |
# Remove exit from its line first | |
sed -e "s/exit//\usr/bin/usb_ethserv/g" > /etc/rc.local | |
# Then add it back | |
echo "exit" >> /etc/rc.local | |
echo "Configuration installed." | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /sys/kernel/config/usb_gadget/ | |
mkdir -p rpi-usb | |
cd rpi-usb | |
echo 0x1d6b > idVendor # Linux Foundation | |
echo 0x0104 > idProduct # Multifunction Composite Gadget | |
echo 0x0100 > bcdDevice # v1.0.0 | |
echo 0x0200 > bcdUSB # USB2 | |
mkdir -p strings/0x409 | |
echo "fedcba9876543210" > strings/0x409/serialnumber | |
echo "Ayane Satomi" > strings/0x409/manufacturer | |
echo "Raspberry Pi Zero W Ethernet over USB" > strings/0x409/product | |
mkdir -p configs/c.1/strings/0x409 | |
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration | |
echo 250 > configs/c.1/MaxPower | |
# Add functions here | |
mkdir -p functions/ecm.usb0 | |
# first byte of address must be even | |
HOST="48:6f:73:74:50:43" # "HostPC" | |
SELF="42:61:64:55:53:42" # "BadUSB" | |
echo $HOST > functions/ecm.usb0/host_addr | |
echo $SELF > functions/ecm.usb0/dev_addr | |
ln -s functions/ecm.usb0 configs/c.1/ | |
# End functions | |
ls /sys/class/udc > UDC | |
ifconfig usb0 10.0.0.1 netmask 255.255.255.252 up | |
route add -net default gw 10.0.0.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment