diff --git a/.update/patches b/.update/patches index fd016c5b8c..0326d8ceaf 100644 --- a/.update/patches +++ b/.update/patches @@ -366,6 +366,38 @@ Patch_7_7() [[ -f '/etc/apt/trusted.gpg.d/dietpi-mono.gpg' ]] || G_EXEC curl -sSfL 'https://download.mono-project.com/repo/xamarin_ring.gpg' -o /etc/apt/trusted.gpg.d/dietpi-mono.gpg [[ -f '/etc/apt/trusted.gpg' ]] && G_EXEC apt-key --keyring /etc/apt/trusted.gpg del '3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF' fi + + # WireGuard: Patch config + if [[ -f '/etc/wireguard/wg0.conf' ]] + then + G_DIETPI-NOTIFY 2 'Updating WireGuard wg0 configuration' + G_EXEC sed -i '\|/boot/dietpi/func/obtain_network_details|d' /etc/wireguard/wg0.conf + G_EXEC sed -Ei "s#mawk .NR==3. /(run|boot|DietPi)/dietpi/.network#ip r l 0/0 | mawk '{print \$5;exit}'#g" /etc/wireguard/wg0.conf + fi + + # GMediaRender: Patch service + if [[ -f '/boot/dietpi/.installed' ]] && grep -q '^[[:blank:]]*aSOFTWARE_INSTALL_STATE\[163\]=2' /boot/dietpi/.installed + then + G_DIETPI-NOTIFY 2 'Updating GMediaRender service' + cat << _EOF_ > /etc/systemd/system/gmrender.service +[Unit] +Description=GMediaRender (DietPi) +Documentation=https://github.com/hzeller/gmrender-resurrect/blob/master/INSTALL.md#commandline-options +Wants=network-online.target +After=network-online.target sound.target dietpi-boot.service + +[Service] +User=gmrender +ExecStartPre=+/bin/bash -c '. /boot/dietpi/func/dietpi-globals; systemctl set-environment ACTIVE_IP=\$(G_GET_NET ip)' +ExecStart=/usr/local/bin/gmediarender -u '$G_HW_UUID' -f '$( v7 migration diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6e74bfb1eb..93460e0c8c 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -5,8 +5,9 @@ Removed software: - CouchPotato | Sadly, the CouchPotato project is not maintained anymore and has been abandoned. In turn we removed it from DietPi. The instance installed on your system will remain, but it cannot be installed, reinstalled or uninstalled anymore. We recommend to migrate to an alternative project, like Radarr, which can be found in DietPi-Software was well. Manual CouchPotato uninstall instructions: https://github.com/MichaIng/DietPi/issues/4323#issuecomment-927128724 Changes: -- DietPi-Globals | G_GET_WAN_IP: We use our own GEO IP service now to show the systems WAN IP and location in the DietPi banner and DietPi-VPN. When Pi-hole was used, with a previous update, "freegeoip.app" was added to Pi-hole's whitlist, which is now not required anymore. You may hence remove that entry from the whitelist. +- General | The /boot/dietpi/func/obtain_network_details script has been removed, including the related /run/dietpi/.network file to obtain network details. All uses of these files have been replaced with the new DietPi-Globals G_GET_NET function (see below). - DietPi-Globals | A new global function G_GET_NET has been added to print network interface details. Most importantly it prints info for the main interface, by following the priorities of /boot/dietpi/func/obtain_network_details: default gateway => state UP => IP assigned, but allows to additionally filter by IP family, type, interface name or print the default gateway explicitly. It aims to be a replacement for /boot/dietpi/func/obtain_network_details with more flexibility and to allow deriving always up-to-date interface info instead of depending on the correctness of a cache file. +- DietPi-Globals | G_GET_WAN_IP: We use our own GEO IP service now to show the systems WAN IP and location in the DietPi banner and DietPi-VPN. When Pi-hole was used, with a previous update, "freegeoip.app" was added to Pi-hole's whitlist, which is now not required anymore. You may hence remove that entry from the whitelist. - DietPi-Globals | The global functions G_DEV_1 and G_DEV_BENCH have been removed, which did exist for testing and development only but are not used in our current workflows. - DietPi-Login | The DietPi banner on login won't be shown anymore if ~/.hushlogin exists, which is a common method to prevent the shell from printing /etc/motd on login and should hence be respected for the DietPi banner as well. Many thanks to @dnknth for doing this suggestion: https://github.com/MichaIng/DietPi/issues/4786 - DietPi-JustBoom | Added the ability to enforce an output channel count, or to not enforce an audio format value to preserve the input stream format or leave conversion up to ALSA, which is now the default when resetting settings. Similarly the audio output buffer can now be unset to keep the MPD default. Generally, if not required for a specific reason, it is recommended to not convert the audio stream and keep these settings unchanged/default. @@ -22,6 +23,7 @@ Fixes: - DietPi-Backup | Resolved an issue where clearing the PATH cache via "hash" command did not work as of a wrong command line argument: https://github.com/MichaIng/DietPi/issues/4800 - DietPi-LetsEncrypt | Resolved an issue where the script failed when ownCloud or Nextcloud are were installed. Many thanks to @billouetaudrey for reporting this issue: https://github.com/MichaIng/DietPi/issues/4752 - DietPi-JustBoom | Resolved an issue where applying some MPD settings did not work. Many thanks to @elevader for reporting this issue: https://dietpi.com/phpbb/viewtopic.php?t=9426 +- DietPi-Config | Resolved an issue where the WiFi connection state could have been obtained falsely as accidentally the Ethernet interface index was used to derive it. - DietPi-Software | Resolved an issue where software services failed with a cryptic error message, when an expected directory was not present. This was especially reported with Sonarr and Radarr, if their log directory was missing for some reason. When directories are missing, which are explicitly listed to be read-writeable within the systemd service, systemd prints "Failed at step NAMESPACE spawning", while Sonarr and Radarr themselves would print a clearer error message about the missing log directory. Many thanks to @stevewitz for reporting this issue: https://dietpi.com/phpbb/viewtopic.php?t=9463 - DietPi-Software | Lighttpd: Resolved an issue where the upgrade from Buster to Bullseye, following our guide, fails if HTTPS was enabled via DietPi-LetsEncrypt before. Many thanks to @fhals for reporting this issue: https://dietpi.com/phpbb/viewtopic.php?t=9477 - DietPi-Software | Kodi: Resolved an issue on RPi ARMv8/64-bit systems where Kodi fails to start when it was installed without a desktop. Many thanks to @Klola for reporting this issue: https://dietpi.com/phpbb/viewtopic.php?p=38079#p38079 diff --git a/dietpi/boot b/dietpi/boot index 5c1c12ba0b..ce149fe6d9 100644 --- a/dietpi/boot +++ b/dietpi/boot @@ -63,11 +63,6 @@ # - Do not run before firstrun setup has finished, since related dietpi.txt settings are applied during first DietPi-Software run. (( $G_DIETPI_INSTALL_STAGE > 1 )) && /boot/dietpi/func/run_ntpd 1 #---------------------------------------------------------------- - # Write network details to /run/dietpi/.network - /boot/dietpi/func/obtain_network_details - # - Make file world-writeable initially, required for DietPi-Login to update it as non-root user - chmod 666 /run/dietpi/.network - #---------------------------------------------------------------- # Pre-installed image, 1st run if (( $G_DIETPI_INSTALL_STAGE == 10 )); then diff --git a/dietpi/dietpi-cloudshell b/dietpi/dietpi-cloudshell index 11da8da78c..aec084f51a 100644 --- a/dietpi/dietpi-cloudshell +++ b/dietpi/dietpi-cloudshell @@ -513,8 +513,8 @@ # Hostname NETWORK_DETAILS_HOSTNAME=$(hostname) - # Active network adapater - NETWORK_DETAILS_ADAPTER=$(mawk 'NR==3' /run/dietpi/.network) + # Active network adapter + NETWORK_DETAILS_ADAPTER=$(G_GET_NET iface) # Mode: DHCP/static if grep -q "iface $NETWORK_DETAILS_ADAPTER inet dhcp" /etc/network/interfaces; then @@ -528,14 +528,14 @@ fi # IP / MAC addresses - NETWORK_DETAILS_IP_INT=$(mawk 'NR==4' /run/dietpi/.network) + NETWORK_DETAILS_IP_INT=$(G_GET_NET ip) NETWORK_DETAILS_MAC_ADDRESS=$(<"/sys/class/net/$NETWORK_DETAILS_ADAPTER/address") # Speed/Strength # WiFi - if [[ $NETWORK_DETAILS_ADAPTER == *'wlan'* ]]; then + if [[ $NETWORK_DETAILS_ADAPTER == 'wlan'* ]]; then - NETWORK_DETAILS_SIGNAL_STRENGTH="$(iwconfig "$NETWORK_DETAILS_ADAPTER" | mawk '/Signal level=/{print $4}' | sed 's/level=//g' | cut -f1 -d "/")%" + NETWORK_DETAILS_SIGNAL_STRENGTH="$(iwconfig "$NETWORK_DETAILS_ADAPTER" | mawk '/Signal level=/{print $4}' | sed 's/level=//g' | cut -f1 -d '/')%" NETWORK_DETAILS_DUPLEXSPEED="$(iwconfig "$NETWORK_DETAILS_ADAPTER" | mawk '/Bit Rate:/{print $2}' | sed 's/Rate://g')Mbit" # Ethernet @@ -1109,10 +1109,6 @@ _EOF_ # Ensure we have at least 1 scene (dietpi) enabled in the settings file. [[ ${aEnabledScenes[*]} == *1* ]] || aEnabledScenes[4]=1 SCENE_CURRENT=4 - #-------------------------------------------------------------------------------- - # Update DietPi network shared data: https://github.com/MichaIng/DietPi/issues/359 - /boot/dietpi/func/obtain_network_details - } #///////////////////////////////////////////////////////////////////////////////////// diff --git a/dietpi/dietpi-config b/dietpi/dietpi-config index 1d9a2c7d93..9d2f61d520 100644 --- a/dietpi/dietpi-config +++ b/dietpi/dietpi-config @@ -2070,7 +2070,7 @@ Current setting: $user_frequency_min_text" && G_CONFIG_INJECT 'CONFIG_CPU_MIN_FR ETH_GATEWAY_STATIC='0.0.0.0' ETH_MASK_STATIC='0.0.0.0' ETH_DNS_STATIC='0.0.0.0' - ETH_DEV_INDEX=0 + ETH_DEV_IFACE='eth0' ETH_DISABLED=0 ETH_HARDWARE=0 ETH_CONNECTED=0 @@ -2084,7 +2084,7 @@ Current setting: $user_frequency_min_text" && G_CONFIG_INJECT 'CONFIG_CPU_MIN_FR WIFI_GATEWAY_STATIC='0.0.0.0' WIFI_MASK_STATIC='0.0.0.0' WIFI_DNS_STATIC='0.0.0.0' - WIFI_DEV_INDEX=0 + WIFI_DEV_IFACE='wlan0' WIFI_DISABLED=0 WIFI_HARDWARE=0 WIFI_CONNECTED=0 @@ -2140,23 +2140,23 @@ Current setting: $user_frequency_min_text" && G_CONFIG_INJECT 'CONFIG_CPU_MIN_FR # Drop Connections G_DIETPI-NOTIFY 0 'Dropping connections, please wait...' - ifdown eth$ETH_DEV_INDEX --force 2> /dev/null - ifdown wlan$WIFI_DEV_INDEX --force 2> /dev/null + ifdown "$ETH_DEV_IFACE" --force 2> /dev/null + ifdown "$WIFI_DEV_IFACE" --force 2> /dev/null # Kill dhclient killall dhclient 2> /dev/null # Flush, not viable to handle this if change of IP, requires a detect of SSH loss/IP change, then exit script. - #ip a flush dev eth$ETH_DEV_INDEX &> /dev/null - #ip a flush dev wlan$WIFI_DEV_INDEX &> /dev/null + #ip a flush dev "$ETH_DEV_IFACE" + #ip a flush dev "$WIFI_DEV_IFACE" # Restart Networking G_DIETPI-NOTIFY 2 'Restarting network, please wait...' - systemctl daemon-reload + G_EXEC systemctl daemon-reload # Manually bring up adapters - (( $ETH_DISABLED == 0 )) && ifup eth$ETH_DEV_INDEX --force - (( $WIFI_DISABLED == 0 )) && ifup wlan$WIFI_DEV_INDEX --force + (( $ETH_DISABLED == 0 )) && ifup "$ETH_DEV_IFACE" --force + (( $WIFI_DISABLED == 0 )) && ifup "$WIFI_DEV_IFACE" --force # Restart all services (required for hotspot) /boot/dietpi/dietpi-services start @@ -2234,21 +2234,21 @@ Current setting: $user_frequency_min_text" && G_CONFIG_INJECT 'CONFIG_CPU_MIN_FR source interfaces.d/* # Ethernet -${eth_enabled_text}allow-hotplug eth$ETH_DEV_INDEX -iface eth$ETH_DEV_INDEX inet $eth_dhcp_static_text +${eth_enabled_text}allow-hotplug $ETH_DEV_IFACE +iface $ETH_DEV_IFACE inet $eth_dhcp_static_text address $ETH_IP_STATIC netmask $ETH_MASK_STATIC $gateway ${eth_dns_text}dns-nameservers $ETH_DNS_STATIC # WiFi -${wifi_enabled_text}allow-hotplug wlan$WIFI_DEV_INDEX +${wifi_enabled_text}allow-hotplug $WIFI_DEV_IFACE _EOF_ # WiFi Hotspot if (( $WIFI_HOTSPOT )); then cat << _EOF_ >> /etc/network/interfaces -iface wlan$WIFI_DEV_INDEX inet static +iface $WIFI_DEV_IFACE inet static address 192.168.42.1 netmask 255.255.255.0 #gateway 192.168.0.1 @@ -2263,7 +2263,7 @@ _EOF_ gateway="gateway $WIFI_GATEWAY_STATIC" [[ $WIFI_GATEWAY_STATIC ]] || gateway="#gateway ${WIFI_IP_STATIC%.*}.1" cat << _EOF_ >> /etc/network/interfaces -iface wlan$WIFI_DEV_INDEX inet $wifi_dhcp_static_text +iface $WIFI_DEV_IFACE inet $wifi_dhcp_static_text address $WIFI_IP_STATIC netmask $WIFI_MASK_STATIC $gateway @@ -2274,7 +2274,7 @@ _EOF_ fi # Remove wireless-power setting, if not supported by adapter/firmware - iwconfig wlan$WIFI_DEV_INDEX power off 2> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces + iwconfig "$WIFI_DEV_IFACE" power off 2> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces # Update WiFi db/wpa_supplicant /boot/dietpi/func/dietpi-wifidb 1 @@ -2441,21 +2441,15 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges Network_GetData(){ - # Update DietPi system network details - /boot/dietpi/func/obtain_network_details - - # Copy /etc/network/interfaces to /tmp (tmpfs) and pull data from it. - cp /etc/network/interfaces /tmp/net_interfaces - # Reset - ETH_IP_STATIC=$(mawk '$1=="address"{print $2;exit}' /tmp/net_interfaces) - ETH_GATEWAY_STATIC=$(mawk '$1=="gateway"{print $2;exit}' /tmp/net_interfaces) - ETH_MASK_STATIC=$(mawk '$1=="netmask"{print $2;exit}' /tmp/net_interfaces) - ETH_DNS_STATIC=$(mawk '$1~/#?dns-nameservers/{print $2,$3;exit}' /tmp/net_interfaces) + ETH_IP_STATIC=$(mawk '$1=="address"{print $2;exit}' /etc/network/interfaces) + ETH_GATEWAY_STATIC=$(mawk '$1=="gateway"{print $2;exit}' /etc/network/interfaces) + ETH_MASK_STATIC=$(mawk '$1=="netmask"{print $2;exit}' /etc/network/interfaces) + ETH_DNS_STATIC=$(mawk '$1~/#?dns-nameservers/{print $2,$3;exit}' /etc/network/interfaces) # Remove trailing space in case of single nameserver, due to mawk '{print $2,$3}' ETH_DNS_STATIC=${ETH_DNS_STATIC%[[:blank:]]} - ETH_DEV_INDEX=$(mawk 'NR==1' /run/dietpi/.network) - ETH_DISABLED=$(( ! $(grep -Ecm1 "^[[:blank:]]*(allow-hotplug|auto)[[:blank:]]+eth$ETH_DEV_INDEX" /tmp/net_interfaces) )) + ETH_DEV_IFACE=$(G_GET_NET -t eth iface) || ETH_DEV_IFACE='eth0' + ETH_DISABLED=$(( ! $(grep -Ecm1 "^[[:blank:]]*(allow-hotplug|auto)[[:blank:]]+$ETH_DEV_IFACE" /etc/network/interfaces) )) ETH_HARDWARE=0 ETH_CONNECTED=0 ETH_IP='0.0.0.0' @@ -2464,14 +2458,14 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges ETH_MODE=1 ETH_MODE_TARGET=$ETH_MODE - WIFI_IP_STATIC=$(mawk '$1=="address"{print $2}' /tmp/net_interfaces | mawk 'NR==2') - WIFI_GATEWAY_STATIC=$(mawk '$1=="gateway"{print $2}' /tmp/net_interfaces | mawk 'NR==2') - WIFI_MASK_STATIC=$(mawk '$1=="netmask"{print $2}' /tmp/net_interfaces | mawk 'NR==2') - WIFI_DNS_STATIC=$(mawk '$1~/#?dns-nameservers/{print $2,$3}' /tmp/net_interfaces | mawk 'NR==2') + WIFI_IP_STATIC=$(mawk '$1=="address"{print $2}' /etc/network/interfaces | mawk 'NR==2') + WIFI_GATEWAY_STATIC=$(mawk '$1=="gateway"{print $2}' /etc/network/interfaces | mawk 'NR==2') + WIFI_MASK_STATIC=$(mawk '$1=="netmask"{print $2}' /etc/network/interfaces | mawk 'NR==2') + WIFI_DNS_STATIC=$(mawk '$1~/#?dns-nameservers/{print $2,$3}' /etc/network/interfaces | mawk 'NR==2') # Remove trailing space in case of single nameserver, due to mawk '{print $2,$3}' WIFI_DNS_STATIC=${WIFI_DNS_STATIC%[[:blank:]]} - WIFI_DEV_INDEX=$(mawk 'NR==2' /run/dietpi/.network) - WIFI_DISABLED=$(( ! $(grep -Ecm1 "^[[:blank:]]*(allow-hotplug|auto)[[:blank:]]+wlan$WIFI_DEV_INDEX" /tmp/net_interfaces) )) + WIFI_DEV_IFACE=$(G_GET_NET -t wlan iface) || WIFI_DEV_IFACE='wlan0' + WIFI_DISABLED=$(( ! $(grep -Ecm1 "^[[:blank:]]*(allow-hotplug|auto)[[:blank:]]+$WIFI_DEV_IFACE" /etc/network/interfaces) )) WIFI_HARDWARE=0 WIFI_CONNECTED=0 WIFI_IP='0.0.0.0' @@ -2516,52 +2510,52 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges } # Eth - if [[ -d /sys/class/net/eth$ETH_DEV_INDEX ]]; then + if [[ -d /sys/class/net/$ETH_DEV_IFACE ]]; then # Hardware ETH_HARDWARE=1 # Static or DHCP? - ETH_MODE=$(grep -cm1 "iface eth$ETH_DEV_INDEX inet dhcp" /tmp/net_interfaces) + ETH_MODE=$(grep -cm1 "iface $ETH_DEV_IFACE inet dhcp" /etc/network/interfaces) ETH_MODE_TARGET=$ETH_MODE # Connected and valid IP? - ETH_CONNECTED=$(ip -o r l dev "eth$ETH_DEV_INDEX" | grep -vcm1 '[[:blank:]]linkdown') + ETH_CONNECTED=$(ip -o r l dev "$ETH_DEV_IFACE" | grep -vcm1 '[[:blank:]]linkdown') # Enabled and connected if (( ! $ETH_DISABLED && $ETH_CONNECTED )); then - ETH_IP=$(ip -br -f inet a s "eth$ETH_DEV_INDEX" | mawk '{print $3}' | sed 's|/.*$||') - ETH_GATEWAY=$(ip r l dev "eth$ETH_DEV_INDEX" 0/0 | mawk '{print $3;exit}') - ETH_MASK=$(cidr2mask "$(ip -br -f inet a s "eth$ETH_DEV_INDEX" | mawk '{print $3}' | sed 's|^.*/||')") + ETH_IP=$(ip -br -f inet a s "$ETH_DEV_IFACE" | mawk '{print $3}' | sed 's|/.*$||') + ETH_GATEWAY=$(ip r l dev "$ETH_DEV_IFACE" 0/0 | mawk '{print $3;exit}') + ETH_MASK=$(cidr2mask "$(ip -br -f inet a s "$ETH_DEV_IFACE" | mawk '{print $3}' | sed 's|^.*/||')") fi fi # WiFi - if [[ -d /sys/class/net/wlan$WIFI_DEV_INDEX ]]; then + if [[ -d /sys/class/net/$WIFI_DEV_IFACE ]]; then # Hardware WIFI_HARDWARE=1 # Static or DHCP? - WIFI_MODE=$(grep -cm1 "iface wlan$WIFI_DEV_INDEX inet dhcp" /tmp/net_interfaces) + WIFI_MODE=$(grep -cm1 "iface $WIFI_DEV_IFACE inet dhcp" /etc/network/interfaces) WIFI_MODE_TARGET=$WIFI_MODE # Connected and valid IP? - WIFI_CONNECTED=$(ip -o r l dev "wlan$ETH_DEV_INDEX" | grep -vcm1 '[[:blank:]]linkdown') + WIFI_CONNECTED=$(ip -o r l dev "$WIFI_DEV_IFACE" | grep -vcm1 '[[:blank:]]linkdown') # Enabled and connected if (( ! $WIFI_DISABLED && $WIFI_CONNECTED )); then - WIFI_IP=$(ip -br -f inet a s "wlan$WIFI_DEV_INDEX" | mawk '{print $3}' | sed 's|/.*$||') - WIFI_GATEWAY=$(ip r l dev "wlan$WIFI_DEV_INDEX" 0/0 | mawk '{print $3;exit}') - WIFI_MASK=$(cidr2mask "$(ip -br -f inet a s "wlan$WIFI_DEV_INDEX" | mawk '{print $3}' | sed 's|^.*/||')") + WIFI_IP=$(ip -br -f inet a s "$WIFI_DEV_IFACE" | mawk '{print $3}' | sed 's|/.*$||') + WIFI_GATEWAY=$(ip r l dev "$WIFI_DEV_IFACE" 0/0 | mawk '{print $3;exit}') + WIFI_MASK=$(cidr2mask "$(ip -br -f inet a s "$WIFI_DEV_IFACE" | mawk '{print $3}' | sed 's|^.*/||')") # Get extra WiFi stats - WIFI_BITRATE=$(iwconfig "wlan$WIFI_DEV_INDEX" | mawk '/Bit Rate/{print $2;exit}' | sed 's/Rate[:=]//g') - WIFI_SIGNALSTRENGTH=$(iwconfig "wlan$WIFI_DEV_INDEX" | mawk '/Signal level=/{print $4;exit}' | sed 's/level=//g' | cut -f1 -d "/") + WIFI_BITRATE=$(iwconfig "$WIFI_DEV_IFACE" | mawk '/Bit Rate/{print $2;exit}' | sed 's/Rate[:=]//g') + WIFI_SIGNALSTRENGTH=$(iwconfig "$WIFI_DEV_IFACE" | mawk '/Signal level=/{print $4;exit}' | sed 's/level=//g' | cut -f1 -d "/") # Try and detect if this is dBm (contains -) or % if disable_error=1 G_CHECK_VALIDINT "$WIFI_SIGNALSTRENGTH" -500 -1; then @@ -2578,9 +2572,6 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges fi - # Cleanup tmp - [[ -f '/tmp/net_interfaces' ]] && rm /tmp/net_interfaces - } # TARGETMENUID=8 @@ -2734,13 +2725,13 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges ETH_DISABLED=0 Network_ApplyChanges - TARGETMENUID=9 + TARGETMENUID=9 # Ethernet adapter menu fi else - TARGETMENUID=9 + TARGETMENUID=9 # Ethernet adapter menu fi @@ -2756,6 +2747,7 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges WIFI_DISABLED=0 Network_ApplyChanges + TARGETMENUID=10 # WiFi adapter menu fi @@ -2772,7 +2764,7 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges else - TARGETMENUID=10 + TARGETMENUID=10 # WiFi adapter menu fi @@ -2828,7 +2820,7 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges # TARGETMENUID=9 Menu_NetworkAdapters_Ethernet(){ - TARGETMENUID=8 + TARGETMENUID=8 # Return to main adapters menu # Mode local mode_text='DHCP' @@ -2856,7 +2848,7 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges G_WHIP_MENU_ARRAY+=('' '●─ Apply ') G_WHIP_MENU_ARRAY+=('Apply' ': Save all changes and restart networking') - Net_Update_UsageStats "eth$ETH_DEV_INDEX" + Net_Update_UsageStats "$ETH_DEV_IFACE" G_WHIP_DEFAULT_ITEM=$WHIP_SELECTION_PREVIOUS if G_WHIP_MENU "Ethernet Details:\nUsage : Sent = $NET_TX_MB | Recieved = $NET_RX_MB\nAddress : IP = $ETH_IP | Mask = $ETH_MASK | Gateway = $ETH_GATEWAY | DNS = $DNS_CURRENT"; then @@ -2883,7 +2875,7 @@ NB: All Ethernet connections will be dropped!' && Network_ApplyChanges speed=${speed//[^0-9]} [[ $speed ]] && G_WHIP_MENU_ARRAY+=("$speed" ": Force $speed Mbit link speed") - done < <(ethtool "eth$ETH_DEV_INDEX" | sed -n '/Supported link modes:/,/^[[:blank:]]*[[:alpha:]]/p' | head -n -1 | mawk '{print $NF}') + done < <(ethtool "$ETH_DEV_IFACE" | sed -n '/Supported link modes:/,/^[[:blank:]]*[[:alpha:]]/p' | head -n -1 | mawk '{print $NF}') G_WHIP_MENU 'Please select a supported Ethernet link speed to force or auto-negotiation. NB: Auto-negotiation is highly recommended as long as you do not have issues with the auto estimated link speed. This is mainly aimed at PINE A64 which may have a hardware issue that causes unstable 1000 Mbit link.' && /boot/dietpi/func/dietpi-set_hardware eth-forcespeed "$G_WHIP_RETURNED_VALUE" @@ -2896,7 +2888,7 @@ NB: Auto-negotiation is highly recommended as long as you do not have issues wit ETH_DISABLED=1 Network_ApplyChanges - TARGETMENUID=8 + TARGETMENUID=8 # Return to main adapters menu fi @@ -2955,9 +2947,9 @@ NB: Auto-negotiation is highly recommended as long as you do not have issues wit # TARGETMENUID=10 Menu_NetworkAdapters_Wifi(){ - TARGETMENUID=8 + TARGETMENUID=8 # Return to main adapters menu - Net_Update_UsageStats "wlan$WIFI_DEV_INDEX" + Net_Update_UsageStats "$WIFI_DEV_IFACE" local description_text="WiFi Details:\nUsage : Sent = $NET_TX_MB | Recieved = $NET_RX_MB\n" @@ -3144,7 +3136,7 @@ NB: Auto-negotiation is highly recommended as long as you do not have issues wit WIFI_DISABLED=1 WiFi_Monitor_Disable Network_ApplyChanges - TARGETMENUID=8 + TARGETMENUID=8 # Return to main adapters menu ;; diff --git a/dietpi/dietpi-login b/dietpi/dietpi-login index 596a889707..2a1550cac3 100644 --- a/dietpi/dietpi-login +++ b/dietpi/dietpi-login @@ -239,8 +239,6 @@ Please login again as user "root" with password "dietpi", respectively the one y #G_INIT # To allow concurrent logins # Import DietPi-Globals -------------------------------------------------------------- - /boot/dietpi/func/obtain_network_details - #---------------------------------------------------------------- # Normal Login if (( $G_DIETPI_INSTALL_STAGE == 2 )); then diff --git a/dietpi/dietpi-software b/dietpi/dietpi-software index 83827650e9..50136952da 100644 --- a/dietpi/dietpi-software +++ b/dietpi/dietpi-software @@ -9101,7 +9101,7 @@ _EOF_ G_EXEC_OUTPUT=1 G_EXEC openbazaar-go init -d /mnt/dietpi_userdata/openbazaar # Add current IP as gateway to allow external client connection - G_CONFIG_INJECT '"Gateway": "' " \"Gateway\": \"/ip4/$(mawk 'NR==4' /run/dietpi/.network)/tcp/4002\"," /mnt/dietpi_userdata/openbazaar/config + G_CONFIG_INJECT '"Gateway": "' " \"Gateway\": \"/ip4/$(G_GET_NET -4 ip)/tcp/4002\"," /mnt/dietpi_userdata/openbazaar/config # Client connection credentials G_DIETPI-NOTIFY 2 "Please enter username and password for your ${aSOFTWARE_NAME[$software_id]} client connection:" @@ -9411,7 +9411,7 @@ The install script will now exit. After applying one of the the above, rerun die # If "1 => '" does not exist, the config.php is not copied e.g. from older instance, so we add entries. if ! grep -q "1 => '" $config_php; then - sed -i "/0 => 'localhost'/a 1 => '$(mawk 'NR==4' /run/dietpi/.network)'," $config_php + sed -i "/0 => 'localhost'/a 1 => '$(G_GET_NET ip)'," $config_php sed -i "/1 => '/a 2 => '$( /etc/default/isc-dhcp-server + echo "INTERFACESv4=\"$wifi_iface\"" > /etc/default/isc-dhcp-server # Remove all entries below wlan, so we can recreate them G_EXEC sed -i '/allow-hotplug wlan/q0' /etc/network/interfaces # Enable up wlan - G_CONFIG_INJECT 'allow-hotplug wlan' "allow-hotplug wlan$wifi_index" /etc/network/interfaces + G_CONFIG_INJECT 'allow-hotplug wlan' "allow-hotplug $wifi_iface" /etc/network/interfaces # Add WiFi settings to network interfaces config cat << _EOF_ >> /etc/network/interfaces -iface wlan$wifi_index inet static +iface $wifi_iface inet static address 192.168.42.1 netmask 255.255.255.0 #gateway 192.168.0.1 @@ -11403,12 +11402,12 @@ wireless-power off up iptables-restore < /etc/iptables.ipv4.nat _EOF_ # Assign static IP for wlan now - ip a add 192.168.42.1 dev "wlan$wifi_index" + G_EXEC ip a add 192.168.42.1 dev "$wifi_iface" # Create access point config G_BACKUP_FP /etc/hostapd/hostapd.conf cat << _EOF_ > /etc/hostapd/hostapd.conf -interface=wlan$wifi_index +interface=$wifi_iface driver=nl80211 ssid=$(sed -n '/^[[:blank:]]*SOFTWARE_WIFI_HOTSPOT_SSID=/{s/^[^=]*=//p;q}' /boot/dietpi.txt) hw_mode=g @@ -11433,9 +11432,9 @@ _EOF_ sysctl net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1 net.ipv6.conf.default.forwarding=1 # Apply IP tables - iptables -t nat -A POSTROUTING -o "eth$eth_index" -j MASQUERADE - iptables -A FORWARD -i "eth$eth_index" -o "wlan$wifi_index" -m state --state RELATED,ESTABLISHED -j ACCEPT - iptables -A FORWARD -i "wlan$wifi_index" -o "eth$eth_index" -j ACCEPT + iptables -t nat -A POSTROUTING -o "$eth_iface" -j MASQUERADE + iptables -A FORWARD -i "$eth_iface" -o "$wifi_iface" -m state --state RELATED,ESTABLISHED -j ACCEPT + iptables -A FORWARD -i "$wifi_iface" -o "$eth_iface" -j ACCEPT # Save IP tables, applied during ifup in /etc/network/interfaces iptables-save > /etc/iptables.ipv4.nat @@ -11466,10 +11465,10 @@ _EOF_ iptables -t nat -F # Generate tor prerouting tables - local wifi_index=$(mawk 'NR==2' /run/dietpi/.network) - iptables -t nat -A PREROUTING -i "wlan$wifi_index" -p tcp --dport 22 -j REDIRECT --to-ports 22 - iptables -t nat -A PREROUTING -i "wlan$wifi_index" -p udp --dport 53 -j REDIRECT --to-ports 53 - iptables -t nat -A PREROUTING -i "wlan$wifi_index" -p tcp --syn -j REDIRECT --to-ports 9040 + local wifi_iface=$(G_GET_NET -t wlan iface) + iptables -t nat -A PREROUTING -i "$wifi_iface" -p tcp --dport 22 -j REDIRECT --to-ports 22 + iptables -t nat -A PREROUTING -i "$wifi_iface" -p udp --dport 53 -j REDIRECT --to-ports 53 + iptables -t nat -A PREROUTING -i "$wifi_iface" -p tcp --syn -j REDIRECT --to-ports 9040 # Save IP tables iptables-save > /etc/iptables.ipv4.nat @@ -12451,7 +12450,7 @@ _EOF_ if [[ ${aSOFTWARE_INSTALL_STATE[153]} == 2 && -f '/mnt/dietpi_userdata/octoprint/.octoprint/config.yaml' ]] then G_DIETPI-NOTIFY 2 'Configuring OctoPrint to use mjpg-streamer for webcam support' - G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.stream "http://$(mawk 'NR==4' /run/dietpi/.network):8082/?action=stream" + G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.stream "http://$(G_GET_NET ip):8082/?action=stream" G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.snapshot 'http://127.0.0.1:8082/?action=snapshot' G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.ffmpeg "$(command -v ffmpeg)" fi @@ -12559,7 +12558,7 @@ _EOF_ if [[ ! -f $ffsync_conf ]]; then G_EXEC cp -a /opt/firefox-sync/syncserver.ini $ffsync_conf - local ffsync_ip=$(mawk 'NR==4' /run/dietpi/.network) + local ffsync_ip=$(G_GET_NET ip) G_CONFIG_INJECT 'host =' "host = $ffsync_ip" $ffsync_conf G_CONFIG_INJECT 'port =' 'port = 5002' $ffsync_conf # Avoid port conflict with Shairport Sync G_CONFIG_INJECT 'public_url =' "public_url = http://$ffsync_ip:5002/" $ffsync_conf @@ -12614,7 +12613,7 @@ _EOF_ G_EXEC cp /opt/vaultwarden/.env.template /mnt/dietpi_userdata/vaultwarden/vaultwarden.env G_CONFIG_INJECT 'DATA_FOLDER=' 'DATA_FOLDER=/mnt/dietpi_userdata/vaultwarden' /mnt/dietpi_userdata/vaultwarden/vaultwarden.env # Create TLS certificate for web vault: Currently only RSA is supported. Add SAN with local IP and hostname, required for the client to accept the connection. - G_EXEC_OUTPUT=1 G_EXEC openssl req -reqexts SAN -subj '/CN=DietPi Vaultwarden' -config <(cat /etc/ssl/openssl.cnf <(echo -ne "[SAN]\nsubjectAltName=DNS:$( 0 )) then G_DIETPI-NOTIFY 2 'Configuring OctoPrint to use mjpg-streamer for webcam support' - G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.stream "http://$(mawk 'NR==4' /run/dietpi/.network):8082/?action=stream" + G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.stream "http://$(G_GET_NET ip):8082/?action=stream" G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.snapshot 'http://127.0.0.1:8082/?action=snapshot' G_EXEC sudo -u octoprint /mnt/dietpi_userdata/octoprint/.local/bin/octoprint config set webcam.ffmpeg "$(command -v ffmpeg)" fi @@ -13398,8 +13397,7 @@ After=network-online.target sound.target dietpi-boot.service [Service] User=gmrender -ExecStartPre=/boot/dietpi/func/obtain_network_details -ExecStartPre=+/bin/dash -c 'systemctl set-environment ACTIVE_IP=\$(mawk 'NR==4' /run/dietpi/.network)' +ExecStartPre=+/bin/bash -c '. /boot/dietpi/func/dietpi-globals; systemctl set-environment ACTIVE_IP=\$(G_GET_NET ip)' ExecStart=/usr/local/bin/gmediarender -u '$G_HW_UUID' -f '$(> /etc/network/interfaces -iface wlan$wifi_index inet dhcp +iface $wifi_iface inet dhcp address 192.168.0.101 netmask 255.255.255.0 gateway 192.168.0.1 @@ -17493,20 +17491,20 @@ We allow it to take up to 30 minutes, it's process can be followed, please be pa while : do local criteria_passed=1 - local output_string='The following criteria must be met, for the installation of WiFi Hotspot to succeed:' + local output_string='The following criteria must be met for the installation of WiFi Hotspot to succeed:' - if ip r | grep -q "eth$(mawk 'NR==1' /run/dietpi/.network)"; then + if [[ $(G_GET_NET -q -t eth ip) ]]; then output_string+='\n\n - Ethernet online: PASSED' else criteria_passed=0 - output_string+='\n\n - Ethernet online: FAILED.\nUse dietpi-config to connect and configure ethernet.' + output_string+='\n\n - Ethernet online: FAILED.\nUse dietpi-config to connect and configure Ethernet.' fi - if [[ -d /sys/class/net/wlan$(mawk 'NR==2' /run/dietpi/.network) ]]; then + if [[ $(G_GET_NET -q -t wlan iface) ]]; then output_string+='\n\n - WiFi adapter detected: PASSED' @@ -17532,7 +17530,7 @@ We allow it to take up to 30 minutes, it's process can be followed, please be pa (( ${aSOFTWARE_INSTALL_STATE[60]} == 1 )) && aSOFTWARE_INSTALL_STATE[60]=0 (( ${aSOFTWARE_INSTALL_STATE[61]} == 1 )) && aSOFTWARE_INSTALL_STATE[61]=0 - G_WHIP_MSG 'WiFi Hotspot criteria was not met. The software will not be installed.' + G_WHIP_MSG 'WiFi Hotspot criteria were not met. The software will not be installed.' break fi diff --git a/dietpi/dietpi-survey b/dietpi/dietpi-survey index 1e4dd6dd80..fcb114035c 100644 --- a/dietpi/dietpi-survey +++ b/dietpi/dietpi-survey @@ -50,8 +50,7 @@ local gitbranch="$G_GITOWNER/$G_GITBRANCH" # Active network interface - local network_interface - [[ -f '/run/dietpi/.network' ]] && network_interface=$(mawk 'NR==3' /run/dietpi/.network) + local network_interface=$(G_GET_NET iface) [[ $network_interface ]] || network_interface='NONE' # Autostart index diff --git a/dietpi/func/dietpi-banner b/dietpi/func/dietpi-banner index d3dbdaa121..acc3322035 100644 --- a/dietpi/func/dietpi-banner +++ b/dietpi/func/dietpi-banner @@ -10,7 +10,7 @@ # # Info: # - Location: /boot/dietpi/func/dietpi-banner - # - Checks /run/dietpi/.update_available, /run/dietpi/.live_patches, /run/dietpi/.apt_updates, /run/dietpi/.network, /run/dietpi/.dietpi_motd and /boot/dietpi/.prep_info + # - Checks /run/dietpi/.update_available, /run/dietpi/.live_patches, /run/dietpi/.apt_updates, /run/dietpi/.dietpi_motd and /boot/dietpi/.prep_info # # Usage: # - dietpi-banner = banner customisation menu @@ -165,7 +165,11 @@ $GREEN_LINE" Print_Local_Ip(){ - [[ ${aENABLED[5]} == 1 ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[5]} $GREEN_SEPARATOR $(mawk 'NR==3 {dev=$0} NR==4 {print $0" ("dev")"}' /run/dietpi/.network 2>&1)" + local iface=$(G_GET_NET -q iface) + [[ $iface ]] || iface='NONE' + local ip=$(G_GET_NET -q ip) + [[ $ip ]] || ip='Use dietpi-config to setup a connection' + [[ ${aENABLED[5]} == 1 ]] && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[5]} $GREEN_SEPARATOR $ip ($iface)" } @@ -226,7 +230,7 @@ $GREEN_LINE" (( ${aENABLED[4]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[4]} $GREEN_SEPARATOR $(hostname -y 2>&1)" # LAN IP [5] Print_Local_Ip - # WAN IP + location info: Move this to /run/dietpi/.network? + # WAN IP + location info (( ${aENABLED[6]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[6]} $GREEN_SEPARATOR $(G_GET_WAN_IP 2>&1)" # DietPi-VPN connection status (( ${aENABLED[13]} == 1 )) && echo -e "$GREEN_BULLET ${aCOLOUR[1]}${aDESCRIPTION[13]} $GREEN_SEPARATOR $(/boot/dietpi/dietpi-vpn status 2>&1)" diff --git a/dietpi/func/dietpi-benchmark b/dietpi/func/dietpi-benchmark index 44b00f9d2e..5fc2e52008 100644 --- a/dietpi/func/dietpi-benchmark +++ b/dietpi/func/dietpi-benchmark @@ -313,7 +313,7 @@ Compare these results online with other users, using the link below: G_AG_CHECK_INSTALL_PREREQ iperf G_THREAD_START iperf -s G_WHIP_MSG "Network benchmark is now running in 'server mode'. Please use another DietPi system to connect as a client and begin the test. - - Server IP = $(mawk 'NR==4' /run/dietpi/.network)\n\nWhen the client has finished, select 'Ok' to stop the server." + - Server IP = $(G_GET_NET ip)\n\nWhen the client has finished, select 'Ok' to stop the server." killall -w iperf G_THREAD_WAIT diff --git a/dietpi/func/dietpi-globals b/dietpi/func/dietpi-globals index 38a785852c..16172a14b6 100644 --- a/dietpi/func/dietpi-globals +++ b/dietpi/func/dietpi-globals @@ -339,7 +339,8 @@ $(ps f -eo pid,user,tty,cmd | grep -i '[d]ietpi')" && continue output_string+=$failed ainput_string+=('\n') - Print 1 + # Print error messages to STDERR + Print 1 >&2 #-------------------------------------------------------------------------------------- # Info @@ -461,7 +462,8 @@ $grey───────────────────────── # Update backtitle WHIP_BACKTITLE=$G_HW_MODEL_NAME - [[ -f '/run/dietpi/.network' ]] && WHIP_BACKTITLE+=" | IP: $(mawk 'NR==4' /run/dietpi/.network)" + local active_ip=$(G_GET_NET ip) + [[ $active_ip ]] && WHIP_BACKTITLE+=" | IP: $active_ip" # Set default button text, if not defined G_WHIP_BUTTON_OK_TEXT=${G_WHIP_BUTTON_OK_TEXT:-Ok} @@ -1263,6 +1265,7 @@ $log_content" || break # Exit error handler menu loop on cancel # "iface": Print the interface name # "ip": Print the IP address # Options: + # "-q": Hide all error messages that are not related to invalid arguments # "-4": Print info for interfaces with an IPv4 address only if available, else return 1 # "-6": Print info for interfaces with an IPv6 address only if available, else return 1 # "-t TYPE": Print info for interfaces of type TYPE only if available, else return 1 @@ -1279,10 +1282,11 @@ $log_content" || break # Exit error handler menu loop on cancel G_GET_NET() { # Grab input - local fam type iface command + local quite=0 fam type iface command while (( $# )) do case "$1" in + '-q') quite=1;; '-'[46]) fam=$1;; '-t') shift; type=$1;; '-i') shift; iface=$1;; @@ -1300,12 +1304,12 @@ $log_content" || break # Exit error handler menu loop on cancel then if [[ ! -e /sys/class/net/$iface ]] then - G_DIETPI-NOTIFY 2 "The given interface \"$iface\" does not exist." + (( $quite )) || G_DIETPI-NOTIFY 2 "The given interface \"$iface\" does not exist." return 1 elif [[ $type && $iface != $type* ]] then - G_DIETPI-NOTIFY 2 "The given interface \"$iface\" is not of type \"$type\"." + (( $quite )) || G_DIETPI-NOTIFY 2 "The given interface \"$iface\" is not of type \"$type\"." return 1 fi fi @@ -1329,12 +1333,12 @@ $log_content" || break # Exit error handler menu loop on cancel # Check for interface type if [[ $type && $if != $type* ]] then - G_DIETPI-NOTIFY 2 "The default gateway is not assigned to any interface of type \"$type\"." + (( $quite )) || G_DIETPI-NOTIFY 2 "The default gateway is not assigned to any interface of type \"$type\"." return 1 fi echo "$gateway" else - G_DIETPI-NOTIFY 2 "A default gateway${fam:+ for IPv${fam#-}}${iface:+ on interface \"$iface\"} does not exist." + (( $quite )) || G_DIETPI-NOTIFY 2 "A default gateway${fam:+ for IPv${fam#-}}${iface:+ on interface \"$iface\"} does not exist." return 1 fi return 0 @@ -1345,7 +1349,7 @@ $log_content" || break # Exit error handler menu loop on cancel then iface=$if # shellcheck disable=SC2086 - [[ $command == 'ip' ]] && ip=$(ip -br $fam a s dev "$iface" | mawk '{print $3}') ip=${ip%/*} + [[ $command == 'ip' ]] && ip=$(ip -br $fam a s dev "$iface" | mawk '{print $3;exit}') ip=${ip%/*} echo "${!command}" return 0 fi @@ -1384,12 +1388,12 @@ $log_content" || break # Exit error handler menu loop on cancel ip=$ip_final ip=${ip%%/*} if [[ $command == 'ip' && ! $ip ]] then - G_DIETPI-NOTIFY 2 "An interface${iface:+ named \"$iface\"}${type:+ of type \"$type\"} with an IP${fam:+v${fam#-}} address does not exist." + (( $quite )) || G_DIETPI-NOTIFY 2 "An interface${iface:+ named \"$iface\"}${type:+ of type \"$type\"} with an IP${fam:+v${fam#-}} address does not exist." return 1 elif [[ $command == 'iface' && ! $iface ]] then - G_DIETPI-NOTIFY 2 "An interface${iface:+ named \"$iface\"}${type:+ of type \"$type\"}${fam:+ with an IPv${fam#-} address} does not exist." + (( $quite )) || G_DIETPI-NOTIFY 2 "An interface${iface:+ named \"$iface\"}${type:+ of type \"$type\"}${fam:+ with an IPv${fam#-} address} does not exist." return 1 fi echo "${!command}" diff --git a/dietpi/func/dietpi-set_hardware b/dietpi/func/dietpi-set_hardware index 294a2bf5e3..0138a79b19 100644 --- a/dietpi/func/dietpi-set_hardware +++ b/dietpi/func/dietpi-set_hardware @@ -560,7 +560,7 @@ _EOF_ if disable_error=1 G_CHECK_VALIDINT "$INPUT_DEVICE_VALUE" 1; then local speed_mbit=$INPUT_DEVICE_VALUE - local iface="eth$(mawk 'NR==1' /run/dietpi/.network)" + local iface=$(G_GET_NET -t eth iface) cat << _EOF_ > /etc/systemd/system/ethtool_force_speed.service [Unit] @@ -1473,9 +1473,6 @@ _EOF_ fi - # Update our networking file (refresh active wlan index) - /boot/dietpi/func/obtain_network_details - } Wifi_Countrycode_Main(){ diff --git a/dietpi/func/dietpi-wifidb b/dietpi/func/dietpi-wifidb index 2f01a3ee43..b093ada57e 100644 --- a/dietpi/func/dietpi-wifidb +++ b/dietpi/func/dietpi-wifidb @@ -202,10 +202,10 @@ _EOF_ Scan_Wifi(){ - local wifi_dev_index=$(mawk 'NR==2' /run/dietpi/.network) + local wifi_iface=$(G_GET_NET -t wlan iface) # Ensure adapater is up - ifup "wlan$wifi_dev_index" + ifup "$wifi_iface" # Get all SSIDs G_DIETPI-NOTIFY 0 'Scanning SSIDs, please wait....' @@ -213,10 +213,9 @@ _EOF_ G_WHIP_MENU_ARRAY=() while read -r line do - [[ $line ]] && G_WHIP_MENU_ARRAY+=("$line" '') - done <<< "$(iwlist "wlan$wifi_dev_index" scan | sed -n '/^[[:blank:]]*ESSID:/s/^[[:blank:]]*ESSID:"\(.*\)"/\1/p')" + done < <(iwlist "$wifi_iface" scan | sed -n '/^[[:blank:]]*ESSID:/s/^[[:blank:]]*ESSID:"\(.*\)"/\1/p') if G_WHIP_MENU 'Please select a WiFi SSID'; then diff --git a/dietpi/func/obtain_network_details b/dietpi/func/obtain_network_details deleted file mode 100644 index 42faf0fc45..0000000000 --- a/dietpi/func/obtain_network_details +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash -{ - #//////////////////////////////////// - # DietPi Function: - # - obtain_network_details - # - #//////////////////////////////////// - # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com - # - #//////////////////////////////////// - # - # Info: - # - Location: /boot/dietpi/func/obtain_network_details - # - Attempts to find the 1st available index numbers for eth[0-9] and wlan[0-9] devices - # - Obtains the active network interface (eth, then wlan). - # - Saves the above data to $FP_NETFILE for system-wide use: - # line1: eth index - # line2: wlan index - # line3: Active interface name (eg: eth0) - # line4: Active IP address - # line5: ETH_IP= - # line6: WLAN_IP= - #//////////////////////////////////// - - # Exit, if already running - pgrep 'obtain_network_details' > /dev/null && exit - - #///////////////////////////////////////////////////////////////////////////////////// - # Global - #///////////////////////////////////////////////////////////////////////////////////// - readonly FP_NETFILE='/run/dietpi/.network' - - ETH_INDEX= - WLAN_INDEX= - ACTIVE_IFACE= - ACTIVE_IP= - ETH_IP= - WLAN_IP= - - Scan(){ - - # ETH - local eth_iface eth_index eth_out eth_ip - for i in /sys/class/net/eth* - do - - # Check if any eth dev exists - [[ -e $i ]] || break - - # Get interface name and index, assign if no lower index was assigned yet - eth_iface=${i#*net/} - eth_index=${eth_iface#eth} - [[ $ETH_INDEX ]] || ETH_INDEX=$eth_index - - # Get and check IP, assign if no lower index IP was assigned yet - eth_out=$(ip -br a s "$eth_iface" 2> /dev/null) || continue - eth_out=${eth_out%%/*} # Remove trailing white space and net mask, if IP assigned - eth_ip=${eth_out##*[[:blank:]]} # Remove everything until IP, if assigned, else will empty string due to trailing white space - [[ $eth_ip ]] || continue - [[ $ETH_IP ]] || { ETH_IP=$eth_ip ETH_INDEX=$eth_index; } - - # Check connection state - [[ $eth_out == *[[:blank:]]UP[[:blank:]]* ]] || continue - - # Assign active dev info - ETH_INDEX=$eth_index - ETH_IP=$eth_ip - ACTIVE_IFACE=$eth_iface - ACTIVE_IP=$ETH_IP - break - - done - - # WLAN - local wlan_iface wlan_index wlan_out wlan_ip - for i in /sys/class/net/wlan* - do - - # Check if any wlan dev exists - [[ -e $i ]] || break - - # Get interface name and index, assign if no lower index was assigned yet - wlan_iface=${i#*net/} - wlan_index=${wlan_iface#wlan} - [[ $WLAN_INDEX ]] || WLAN_INDEX=$wlan_index - - # Get and check IP, assign if no lower index IP was assigned yet - wlan_out=$(ip -br a s "$wlan_iface" 2> /dev/null) || continue - wlan_out=${wlan_out%%/*} # Remove trailing white space and net mask, if IP assigned - wlan_ip=${wlan_out##*[[:blank:]]} # Remove everything until IP, if assigned, else will empty string due to trailing white space - [[ $wlan_ip ]] || continue - [[ $WLAN_IP ]] || { WLAN_IP=$wlan_ip WLAN_INDEX=$wlan_index; } - - # Check connection state - [[ $wlan_out == *[[:blank:]]UP[[:blank:]]* ]] || continue - - # Assign active dev info if none (eth) was assigned yet - WLAN_INDEX=$wlan_index - WLAN_IP=$wlan_ip - [[ $ACTIVE_IFACE ]] || { ACTIVE_IFACE=$wlan_iface ACTIVE_IP=$WLAN_IP; } - break - - done - - } - - #///////////////////////////////////////////////////////////////////////////////////// - # Main Loop - #///////////////////////////////////////////////////////////////////////////////////// - Scan - #----------------------------------------------------------------------------------- - # Active interface fallback due to possible "UNKNOWN" connection state and to always have an interface assigned if any present - if [[ ! $ACTIVE_IFACE ]]; then - - if [[ $ETH_IP ]]; then - - ACTIVE_IFACE="eth$ETH_INDEX" - ACTIVE_IP=$ETH_IP - - elif [[ $WLAN_IP ]]; then - - ACTIVE_IFACE="wlan$WLAN_INDEX" - ACTIVE_IP=$WLAN_IP - - elif [[ $ETH_INDEX ]]; then - - ACTIVE_IFACE="eth$ETH_INDEX" - - elif [[ $WLAN_INDEX ]]; then - - ACTIVE_IFACE="wlan$WLAN_INDEX" - - fi - - fi - #----------------------------------------------------------------------------------- - # Write to file - echo "${ETH_INDEX:-0} -${WLAN_INDEX:-0} -${ACTIVE_IFACE:-NONE} -${ACTIVE_IP:-Use dietpi-config to setup a connection} -ETH_IP=$ETH_IP -WLAN_IP=$WLAN_IP" > $FP_NETFILE - #----------------------------------------------------------------------------------- - exit - #----------------------------------------------------------------------------------- -} diff --git a/dietpi/patch_file b/dietpi/patch_file index a020b362e5..600b82c133 100644 --- a/dietpi/patch_file +++ b/dietpi/patch_file @@ -90,8 +90,6 @@ fi # - Pre-create new DietPi runtime dir for later used scripts, created via /etc/tmpfiles.d/dietpi.conf from next boot on [[ -d '/run/dietpi' ]] || { mkdir -p /run/dietpi; chmod 777 /run/dietpi; } - # - Create network info file on new location - [[ -f '/run/dietpi/.network' ]] || { /boot/dietpi/func/obtain_network_details; chmod 666 /run/dietpi/.network; } # Pre-v6.22: Update Git owner due to official lead transfer from Fourdee to MichaIng: https://github.com/MichaIng/DietPi/issues/2589 grep -q '^[[:blank:]]*DEV_GITOWNER=Fourdee' /boot/dietpi.txt && sed -i '/^[[:blank:]]*DEV_GITOWNER=/c\DEV_GITOWNER=MichaIng' /boot/dietpi.txt @@ -1226,9 +1224,9 @@ Also have a look at "Sonarr", another alternative TV show manager, available for G_AGI procps #------------------------------------------------------------------------------- # Remove wireless-power setting from /etc/network/interfaces, if not supported by adapter/firmware: https://github.com/MichaIng/DietPi/issues/2198 - iwconfig "wlan$(mawk 'NR==2' /run/dietpi/.network)" power off &> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces + iwconfig "$(G_GET_NET -q -t wlan iface)" power off &> /dev/null || sed -i '/^wireless-power/d' /etc/network/interfaces #------------------------------------------------------------------------------- - # Remove armbian banner/profiles left on ASUS TB image + # Remove Armbian banner/profiles left on ASUS TB image rm -f /etc/profile.d/armbian-* #------------------------------------------------------------------------------- @@ -1456,17 +1454,12 @@ Further info and usage: https://dietpi.com/phpbb/viewtopic.php?t=5828' # Fix IPv6 connections with WireGuard: https://github.com/MichaIng/DietPi/issues/2691 if [[ -f '/etc/wireguard/wg0.conf' ]] && ! grep -q 'sysctl' /etc/wireguard/wg0.conf; then - [[ -f '/etc/sysctl.d/dietpi-wireguard.conf' ]] && rm /etc/sysctl.d/dietpi-wireguard.conf - # shellcheck disable=SC2016 - sed -i '/^ListenPort/a\PostUp = sysctl net.ipv4.conf.%i.forwarding=1 net.ipv4.conf.$(mawk "NR==3" /run/dietpi/.network).forwarding=1' /etc/wireguard/wg0.conf - # shellcheck disable=SC2016 - sed -i '/^ListenPort/a\PostUp = sysctl net.ipv6.conf.$(mawk "NR==3" /run/dietpi/.network).accept_ra=2' /etc/wireguard/wg0.conf - # shellcheck disable=SC2016 - sed -i '/^ListenPort/a\PostUp = sysctl net.ipv6.conf.%i.forwarding=1 net.ipv6.conf.$(mawk "NR==3" /run/dietpi/.network).forwarding=1' /etc/wireguard/wg0.conf - # shellcheck disable=SC2016 - sed -i '/^ListenPort/a\PostUp = ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o $(mawk "NR==3" /run/dietpi/.network) -j MASQUERADE' /etc/wireguard/wg0.conf - # shellcheck disable=SC2016 - sed -i '/^ListenPort/a\PostDown = ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o $(mawk "NR==3" /run/dietpi/.network) -j MASQUERADE' /etc/wireguard/wg0.conf + [[ -f '/etc/sysctl.d/dietpi-wireguard.conf' ]] && G_EXEC rm /etc/sysctl.d/dietpi-wireguard.conf + sed -i "/^ListenPort/a\PostUp = sysctl net.ipv4.conf.%i.forwarding=1 net.ipv4.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').forwarding=1" /etc/wireguard/wg0.conf + sed -i "/^ListenPort/a\PostUp = sysctl net.ipv6.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').accept_ra=2" /etc/wireguard/wg0.conf + sed -i "/^ListenPort/a\PostUp = sysctl net.ipv6.conf.%i.forwarding=1 net.ipv6.conf.\$(ip r l 0/0 | mawk '{print \$5;exit}').forwarding=1" /etc/wireguard/wg0.conf + sed -i "/^ListenPort/a\PostUp = ip6tables -A FORWARD -i %i -j ACCEPT; ip6tables -t nat -A POSTROUTING -o \$(ip r l 0/0 | mawk '{print \$5;exit}') -j MASQUERADE" /etc/wireguard/wg0.conf + sed -i "/^ListenPort/a\PostDown = ip6tables -D FORWARD -i %i -j ACCEPT; ip6tables -t nat -D POSTROUTING -o \$(ip r l 0/0 | mawk '{print \$5;exit}') -j MASQUERADE" /etc/wireguard/wg0.conf fi #----------------------------------------------------------------------- @@ -2258,9 +2251,6 @@ To reinstall now, run: "dietpi-software reinstall 106 144 145" 6. Press ctrl+o buttons to save and ctrl+x to exit' fi - # Update .network info file locations in existing software services - [[ -f '/etc/wireguard/wg0.conf' ]] && sed -Ei 's@/(DietPi|boot)/dietpi/\.network@/run/dietpi/.network@g' /etc/wireguard/wg0.conf - [[ -f '/etc/systemd/system/gmrender.service' ]] && sed -Ei 's@/(DietPi|boot)/dietpi/\.network@/run/dietpi/.network@g' /etc/systemd/system/gmrender.service # Pi-hole: Assure v5 compatibility if getent group pihole > /dev/null && command -v php > /dev/null; then diff --git a/rootfs/etc/systemd/system/dietpi-wifi-monitor.service b/rootfs/etc/systemd/system/dietpi-wifi-monitor.service index 9881744e28..79b7457325 100644 --- a/rootfs/etc/systemd/system/dietpi-wifi-monitor.service +++ b/rootfs/etc/systemd/system/dietpi-wifi-monitor.service @@ -1,12 +1,9 @@ -# Monitors loss of WiFi connection and automatically reconnects [Unit] -Description=DietPi-WiFi-Monitor +Description=DietPi-WiFi_Monitor Wants=network-online.target -After=dietpi-boot.service network-online.target +After=network-online.target dietpi-boot.service [Service] -ExecStartPre=/boot/dietpi/func/obtain_network_details -ExecStartPre=/bin/dash -c '[ -e /sys/class/net/wlan$(mawk "NR==2" /run/dietpi/.network) ]' ExecStart=/var/lib/dietpi/services/dietpi-wifi-monitor.sh [Install] diff --git a/rootfs/var/lib/dietpi/services/dietpi-firstboot.bash b/rootfs/var/lib/dietpi/services/dietpi-firstboot.bash index 2d5f862d76..691f4d4d25 100755 --- a/rootfs/var/lib/dietpi/services/dietpi-firstboot.bash +++ b/rootfs/var/lib/dietpi/services/dietpi-firstboot.bash @@ -217,15 +217,14 @@ _EOF_ # Network setup # - Grab available network interfaces - /boot/dietpi/func/obtain_network_details - local index_eth=$(mawk 'NR==1' /run/dietpi/.network) - disable_error=1 G_CHECK_VALIDINT "$index_eth" 0 || index_eth=0 - local index_wlan=$(mawk 'NR==2' /run/dietpi/.network) - disable_error=1 G_CHECK_VALIDINT "$index_wlan" 0 || index_wlan=0 + local iface_eth=$(G_GET_NET -t eth iface) + [[ $iface_eth ]] || iface_eth='eth0' + local iface_wlan=$(G_GET_NET -t wlan iface) + [[ $iface_wlan ]] || iface_wlan='wlan0' # - Replace interface names with the ones obtained above - sed -i "s/eth[0-9]/eth$index_eth/g" /etc/network/interfaces - sed -i "s/wlan[0-9]/wlan$index_wlan/g" /etc/network/interfaces + sed -i "s/eth[0-9]/$iface_eth/g" /etc/network/interfaces + sed -i "s/wlan[0-9]/$iface_wlan/g" /etc/network/interfaces # - Grab user requested settings from dietpi.txt local ethernet_enabled=$(grep -cm1 '^[[:blank:]]*AUTO_SETUP_NET_ETHERNET_ENABLED=1' /boot/dietpi.txt) @@ -241,8 +240,8 @@ _EOF_ # Enable WiFi, disable Ethernet ethernet_enabled=0 - sed -Ei "/(allow-hotplug|auto)[[:blank:]]+wlan/c\allow-hotplug wlan$index_wlan" /etc/network/interfaces - sed -Ei "/(allow-hotplug|auto)[[:blank:]]+eth/c\#allow-hotplug eth$index_eth" /etc/network/interfaces + sed -Ei "/(allow-hotplug|auto)[[:blank:]]+wlan/c\allow-hotplug $iface_wlan" /etc/network/interfaces + sed -Ei "/(allow-hotplug|auto)[[:blank:]]+eth/c\#allow-hotplug $iface_eth" /etc/network/interfaces # Apply global SSID/keys from dietpi.txt to wpa_supplicant /boot/dietpi/func/dietpi-wifidb 1 @@ -255,8 +254,8 @@ _EOF_ # Enable Eth, disable WiFi wifi_enabled=0 - sed -Ei "/(allow-hotplug|auto)[[:blank:]]+eth/c\allow-hotplug eth$index_eth" /etc/network/interfaces - sed -Ei "/(allow-hotplug|auto)[[:blank:]]+wlan/c\#allow-hotplug wlan$index_wlan" /etc/network/interfaces + sed -Ei "/(allow-hotplug|auto)[[:blank:]]+eth/c\allow-hotplug $iface_eth" /etc/network/interfaces + sed -Ei "/(allow-hotplug|auto)[[:blank:]]+wlan/c\#allow-hotplug $iface_wlan" /etc/network/interfaces # Disable WiFi kernel modules /boot/dietpi/func/dietpi-set_hardware wifimodules disable @@ -268,11 +267,11 @@ _EOF_ if (( $wifi_enabled )); then - sed -i "/iface wlan/c\iface wlan$index_wlan inet static" /etc/network/interfaces + sed -i "/iface wlan/c\iface $iface_wlan inet static" /etc/network/interfaces elif (( $ethernet_enabled )); then - sed -i "/iface eth/c\iface eth$index_eth inet static" /etc/network/interfaces + sed -i "/iface eth/c\iface $iface_eth inet static" /etc/network/interfaces fi sed -i "/address/c\address $static_ip" /etc/network/interfaces @@ -299,7 +298,7 @@ _EOF_ # - Configure enabled interfaces now, /etc/network/interfaces will be effective from next boot on # Failsafe: Bring up Ethernet, whenever WiFi is disabled or fails to be configured, e.g. due to wrong credentials # shellcheck disable=SC2015 - (( $wifi_enabled )) && ifup wlan$index_wlan || ifup eth$index_eth + (( $wifi_enabled )) && ifup "$iface_wlan" || ifup "$iface_eth" # x86_64 BIOS: Set GRUB install device: https://github.com/MichaIng/DietPi/issues/4542 if (( $G_HW_MODEL == 10 )) && dpkg-query -s grub-pc &> /dev/null diff --git a/rootfs/var/lib/dietpi/services/dietpi-wifi-monitor.sh b/rootfs/var/lib/dietpi/services/dietpi-wifi-monitor.sh index 69a200142a..121adc4a3a 100644 --- a/rootfs/var/lib/dietpi/services/dietpi-wifi-monitor.sh +++ b/rootfs/var/lib/dietpi/services/dietpi-wifi-monitor.sh @@ -1,45 +1,39 @@ #!/bin/bash { - # Check for root permissions - (( $UID )) && { echo 'ERROR: Root permissions required. Please run this script with "sudo". Exiting...'; exit 1; } - - # Check for concurrent execution - (( $(pgrep -cf 'dietpi-wifi-monitor.sh') > 1 )) && { echo 'ERROR: Concurrent execution detected. Please exit the running instance of DietPi-WiFi-Monitor first. Exiting...'; exit 1; } - - URL_PING= - ADAPTER="wlan$(mawk 'NR==2' /run/dietpi/.network)" - [[ $TICKRATE =~ ^[0-9]+$ ]] && (( $TICKRATE > 0 )) || TICKRATE=10 + # Import DietPi-Globals --------------------------------------------------------------- + . /boot/dietpi/func/dietpi-globals + readonly G_PROGRAM_NAME='DietPi-WiFi_Monitor' + G_CHECK_ROOT_USER + G_INIT + # Import DietPi-Globals --------------------------------------------------------------- + + readonly ADAPTER=$(G_GET_NET -t wlan iface) + [[ $ADAPTER ]] || { G_DIETPI-NOTIFY 1 'No WiFi adapter has been found. Exiting...'; exit 1; } + [[ $TICKRATE =~ ^[1-9][0-9]*$ ]] || readonly TICKRATE=10 + GATEWAY= #------------------------------------------------------------------------------------- # Main #------------------------------------------------------------------------------------- - echo "Checking connection for: $ADAPTER via ping to default gateway every $TICKRATE seconds" + G_DIETPI-NOTIFY 2 "Checking connection for $ADAPTER via ping to default gateway every $TICKRATE seconds" while : do - - # Get current gateway for ping - URL_PING=$(ip r l 0/0 dev "$ADAPTER" | mawk '{print $3}') - - [[ $G_DEBUG == 1 ]] && echo "Checking connection for: $ADAPTER via ping to $URL_PING" - if [[ $URL_PING ]] && ping -qI "$ADAPTER" -c 1 "$URL_PING" &> /dev/null; then - - [[ $G_DEBUG == 1 ]] && echo "Connection valid for: $ADAPTER" - - else - - [[ -e /sys/class/net/$ADAPTER ]] || { echo "ERROR: WiFi adapter has been unplugged: $ADAPTER. Exiting..."; exit 1; } - - echo "Detected connection loss: $ADAPTER. Reconnecting..." + if [[ ! -e /sys/class/net/$ADAPTER ]] + then + G_DIETPI-NOTIFY 1 "WiFi adapter $ADAPTER has been unplugged. Exiting..." + exit 1 + + elif ! GATEWAY=$(G_GET_NET -i "$ADAPTER" gateway) || ! ping -qI "$ADAPTER" -c 1 "$GATEWAY" &> /dev/null + then + G_DIETPI-NOTIFY 2 "Detected $ADAPTER connection loss. Reconnecting..." ifdown "$ADAPTER" sleep 1 ifup "$ADAPTER" - echo 'Completed' - + G_DIETPI-NOTIFY 0 'Completed' fi sleep $TICKRATE - done exit 0