mirror of
https://github.com/linuxboot/heads.git
synced 2025-03-03 04:18:38 +00:00
initrd/bin/network-init-recovery: put usb tethering and ethernet activation in functions and ask user prior of using each mode
Also remove output of attempted module loading since DEBUG will show if needed Remove timeout after 30 seconds to unify UX and block Change UX wording Should address all PR review comments Signed-off-by: Thierry Laurion <insurgo@riseup.net>
This commit is contained in:
parent
35de23483a
commit
5f8cb5a159
@ -4,45 +4,76 @@
|
|||||||
|
|
||||||
TRACE_FUNC
|
TRACE_FUNC
|
||||||
|
|
||||||
# bring up the ethernet interface
|
mobile_tethering()
|
||||||
ifconfig lo 127.0.0.1
|
{
|
||||||
|
TRACE_FUNC
|
||||||
echo "Loading Ethernet network modules..."
|
#Tethering over USB for Mobile phones supporting CDC (Android Pixel 6a+, Librem phone, etc.)
|
||||||
network_modules="e1000 e1000e igb sfc mdio mlx4_core mlx4_en"
|
if [ -e /lib/modules/cdc_ether.ko ]; then
|
||||||
for module in $(echo $network_modules); do
|
#prompt user if he wants to enable USB tethering and skip if not
|
||||||
if [ -f /lib/modules/$module.ko ]; then
|
echo ""
|
||||||
insmod /lib/modules/$module.ko
|
echo "USB tethering support is available for mobile phones supporting CDC NCM/EEM tethering"
|
||||||
|
read -p "Do you want to enable USB tethering now? (Y/n)" -n 1 -r REPLY
|
||||||
|
echo ""
|
||||||
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
|
echo "USB tethering not enabled, skipping..."
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
#Tethering over USB for Mobile phones supporting CDC (Android Pixel 6a+, Librem phone, etc.)
|
|
||||||
if [ -e /lib/modules/cdc_ether.ko ]; then
|
|
||||||
#first enable USB controllers
|
#first enable USB controllers
|
||||||
enable_usb
|
enable_usb
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Please verify that your mobile (CDC NCM/EEM tethering compatible phone) is networked in the desired way (WIFI/mobile + VPN/Orbot/etc)"
|
echo "Please connect your mobile phone to a USB port and enable internet connection sharing."
|
||||||
echo "Please connect mobile phone to this machine's fast USB port (blue identified) through a known working data cable"
|
echo "* Android: Select the 'Charging this device via USB' notification and enable tethering."
|
||||||
echo "Please enable USB tethering prior of going further (Android: select 'Charging this device via USB' notification and enable tethering option)"
|
echo "* Linux: Set the wired connection's IPv4 method on the mobile phone to 'Shared to other computers'."
|
||||||
read -p "Press Enter to continue now or wait 30 seconds..." -n 1 -r -t 30
|
echo "Heads supports CDC-NCM and CDC-EEM. Android phones using RNDIS and Apple phones are not supported."
|
||||||
|
echo ""
|
||||||
|
read -p "Press Enter to continue..." -n 1 -r
|
||||||
|
|
||||||
network_modules="mii usbnet cdc_ether cdc_ncm cdc_eem"
|
network_modules="mii usbnet cdc_ether cdc_ncm cdc_eem"
|
||||||
echo "Loading USB tethering network related modules: $network_modules..."
|
|
||||||
for module in $(echo $network_modules); do
|
for module in $(echo $network_modules); do
|
||||||
if [ -f /lib/modules/$module.ko ]; then
|
if [ -f /lib/modules/$module.ko ]; then
|
||||||
insmod /lib/modules/$module.ko
|
insmod /lib/modules/$module.ko
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! [ -e /sys/class/net/usb0 ]; then
|
if ! [ -e /sys/class/net/usb0 ]; then
|
||||||
echo ""
|
echo ""
|
||||||
echo "Tethering USB network interface was NOT detected with loaded kernel modules : $network_modules"
|
echo "No tethering network interface was found."
|
||||||
echo "Please check your phone's linux drivers requirements"
|
echo "* Make sure the phone supports CDC-NCM or CDC-EEM. Many, but not all, Android and Linux phones support these."
|
||||||
echo "Note that RNDIS kernel module inclusion was discussed and rejected due to security implications and planned deprecation under Linux kernel altogether"
|
echo "* Android phones requiring RNDIS and Apple phones are not supported."
|
||||||
echo "CDC NCM/CDC EEM support is known to be available on a majority of Android/GrapheneOS as well as Librem phones"
|
echo "* Make sure the cable used works with data and that the phone has tethering enabled."
|
||||||
echo "Non-exhaustive exeptions: Pixel 4a* known to only tether over RNDIS and won't be supported"
|
echo ""
|
||||||
echo "Apple phones won't be supported due to size and complexity of the drivers and toolstack required to support tethering"
|
read -p "Press Enter to continue..." -n 1 -r
|
||||||
read -p "Press Enter to continue now or wait 30 seconds..." -n 1 -r -t 30
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ethernet_activation()
|
||||||
|
{
|
||||||
|
TRACE_FUNC
|
||||||
|
#Prompt user if he wants to enable ethernet and skip if not
|
||||||
|
read -p "Do you want to enable Ethernet now? (Y/n)" -n 1 -r REPLY
|
||||||
|
echo ""
|
||||||
|
if [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
|
echo "Ethernet not enabled, skipping..."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Loading Ethernet network modules..."
|
||||||
|
network_modules="e1000 e1000e igb sfc mdio mlx4_core mlx4_en"
|
||||||
|
for module in $(echo $network_modules); do
|
||||||
|
if [ -f /lib/modules/$module.ko ]; then
|
||||||
|
insmod /lib/modules/$module.ko
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# bring up the ethernet interface
|
||||||
|
ifconfig lo 127.0.0.1
|
||||||
|
|
||||||
|
mobile_tethering
|
||||||
|
ethernet_activation
|
||||||
|
|
||||||
if [ -e /sys/class/net/usb0 ]; then
|
if [ -e /sys/class/net/usb0 ]; then
|
||||||
dev=usb0
|
dev=usb0
|
||||||
@ -50,24 +81,30 @@ if [ -e /sys/class/net/usb0 ]; then
|
|||||||
elif [ -e /sys/class/net/eth0 ]; then
|
elif [ -e /sys/class/net/eth0 ]; then
|
||||||
dev=eth0
|
dev=eth0
|
||||||
echo "Ethernet network interface detected as $dev"
|
echo "Ethernet network interface detected as $dev"
|
||||||
#Randomize eth0 MAC address of maximized boards
|
else
|
||||||
|
echo "No network interface detected, please check your hardware and board configuration"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$dev" ]; then
|
||||||
|
|
||||||
|
#Randomize MAC address for maximized boards
|
||||||
if echo "$CONFIG_BOARD" | grep -q maximized; then
|
if echo "$CONFIG_BOARD" | grep -q maximized; then
|
||||||
ifconfig $dev down
|
ifconfig $dev down
|
||||||
echo "Generating random MAC address..."
|
echo "Generating random MAC address..."
|
||||||
mac=$(generate_random_mac_address)
|
mac=$(generate_random_mac_address)
|
||||||
echo "Assigning randomly generated MAC: $mac to eth0..."
|
echo "Assigning randomly generated MAC: $mac to $dev..."
|
||||||
ifconfig $dev hw ether $mac
|
ifconfig $dev hw ether $mac
|
||||||
echo "Bringing up $dev... Connect a network cable to the $dev port and make sure status LEDs are on"
|
|
||||||
ifconfig $dev up
|
ifconfig $dev up
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Set up static IP
|
# Set up static IP if configured in board config
|
||||||
if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then
|
if [ ! -z "$CONFIG_BOOT_STATIC_IP" ]; then
|
||||||
echo "Setting static IP: $CONFIG_BOOT_STATIC_IP"
|
echo "Setting static IP: $CONFIG_BOOT_STATIC_IP"
|
||||||
ifconfig $dev $CONFIG_BOOT_STATIC_IP
|
ifconfig $dev $CONFIG_BOOT_STATIC_IP
|
||||||
echo "No NTP sync with static IP: no DNS server nor gateway defined, set time manually"
|
echo "No NTP sync with static IP: no DNS server nor gateway defined, set time manually"
|
||||||
elif [ -e /sbin/udhcpc ]; then
|
# Set up DHCP if no static IP
|
||||||
|
elif [ -e /sbin/udhcpc ]; then
|
||||||
echo "Getting IP from first DHCP server answering. This may take a while..."
|
echo "Getting IP from first DHCP server answering. This may take a while..."
|
||||||
if udhcpc -T 1 -i $dev -q; then
|
if udhcpc -T 1 -i $dev -q; then
|
||||||
if [ -e /sbin/ntpd ]; then
|
if [ -e /sbin/ntpd ]; then
|
||||||
@ -83,23 +120,24 @@ elif [ -e /sbin/udhcpc ]; then
|
|||||||
echo "NTP time sync successful."
|
echo "NTP time sync successful."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "Syncing hardware clock with system time in UTC/GMT timezone... NOT LOCAL TIMEZONE!"
|
echo "Syncing hardware clock with system time in UTC/GMT timezone..."
|
||||||
hwclock -w
|
hwclock -w
|
||||||
echo ""
|
echo ""
|
||||||
date=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
date=$(date "+%Y-%m-%d %H:%M:%S %Z")
|
||||||
echo "Time: $date"
|
echo "Time: $date"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e /bin/dropbear ]; then
|
if [ -e /bin/dropbear ]; then
|
||||||
# Set up the ssh server, allow root logins and log to stderr
|
# Set up the ssh server, allow root logins and log to stderr
|
||||||
if [ ! -d /etc/dropbear ]; then
|
if [ ! -d /etc/dropbear ]; then
|
||||||
mkdir /etc/dropbear
|
mkdir /etc/dropbear
|
||||||
fi
|
fi
|
||||||
echo "Starting dropbear ssh server..."
|
echo "Starting dropbear ssh server..."
|
||||||
dropbear -B -R
|
dropbear -B -R
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
echo "Network setup complete:"
|
||||||
|
ifconfig $dev
|
||||||
fi
|
fi
|
||||||
echo ""
|
|
||||||
echo "Network setup complete:"
|
|
||||||
ifconfig
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user