tree: rework more logic

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-11-16 11:23:52 +01:00
parent 390f5b11db
commit f4bbb7c5bb
5 changed files with 98 additions and 100 deletions

View File

@ -949,8 +949,8 @@ function sysinfo() {
CPU="$(cat /proc/cpuinfo 2>/dev/null | grep 'model name' | uniq | awk -F':' '{print $2}')" CPU="$(cat /proc/cpuinfo 2>/dev/null | grep 'model name' | uniq | awk -F':' '{print $2}')"
SECURE=$(dmesg 2>/dev/null | grep -i "Secure Boot" | awk -F'] ' '{print $2}') SECURE=$(dmesg 2>/dev/null | grep -i "Secure Boot" | awk -F'] ' '{print $2}')
VENDOR=$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i') VENDOR=$(dmesg 2>/dev/null | grep -i "DMI:" | head -1 | sed 's/\[.*\] DMI: //i')
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
ETHN="$(echo ${ETHX} | wc -w)" ETHN=$(echo ${ETHX} | wc -w)
ARC_BRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")" ARC_BRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")" CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
@ -1010,15 +1010,15 @@ function sysinfo() {
TEXT+="\n Bootdisk: \Zb${LOADER_DISK}\Zn" TEXT+="\n Bootdisk: \Zb${LOADER_DISK}\Zn"
TEXT+="\n" TEXT+="\n"
TEXT+="\n\Z4> Network: ${ETHN} NIC\Zn" TEXT+="\n\Z4> Network: ${ETHN} NIC\Zn"
for ETH in ${ETHX}; do for N in ${ETHX}; do
COUNT=0 COUNT=0
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}') DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
while true; do while true; do
if ! ip link show ${ETH} 2>/dev/null | grep -q 'UP'; then if [ -z "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
TEXT+="\n${DRIVER}: \ZbDOWN\Zn" TEXT+="\n${DRIVER}: \ZbDOWN\Zn"
break break
fi fi
if ethtool ${ETH} 2>/dev/null | grep 'Link detected' | grep -q 'no'; then if [ "0" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
TEXT+="\n${DRIVER}: \ZbNOT CONNECTED\Zn" TEXT+="\n${DRIVER}: \ZbNOT CONNECTED\Zn"
break break
fi fi
@ -1027,9 +1027,9 @@ function sysinfo() {
break break
fi fi
COUNT=$((${COUNT} + 1)) COUNT=$((${COUNT} + 1))
IP="$(getIP ${ETH})" IP="$(getIP ${N})"
if [ -n "${IP}" ]; then if [ -n "${IP}" ]; then
SPEED=$(ethtool ${ETH} 2>/dev/null | grep "Speed:" | awk '{print $2}') SPEED=$(ethtool ${N} 2>/dev/null | grep "Speed:" | awk '{print $2}')
if [[ "${IP}" =~ ^169\.254\..* ]]; then if [[ "${IP}" =~ ^169\.254\..* ]]; then
TEXT+="\n$ {DRIVER} (${SPEED}): \ZbLINK LOCAL (No DHCP server found.)\Zn" TEXT+="\n$ {DRIVER} (${SPEED}): \ZbLINK LOCAL (No DHCP server found.)\Zn"
else else
@ -1245,22 +1245,22 @@ function uploadDiag () {
# Shows Networkdiag to user # Shows Networkdiag to user
function networkdiag() { function networkdiag() {
( (
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
for ETH in ${ETHX}; do for N in ${ETHX}; do
echo echo
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}') DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
echo -e "Interface: ${ETH} (${DRIVER})" echo -e "Interface: ${N} (${DRIVER})"
if ethtool ${ETH} 2>/dev/null | grep 'Link detected' | grep -q 'no'; then if [ "0" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "Link: NOT CONNECTED" echo -e "Link: NOT CONNECTED"
continue continue
fi fi
if ! ip link show ${ETH} 2>/dev/null | grep -q 'UP'; then if [ -z "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "Link: DOWN" echo -e "Link: DOWN"
continue continue
fi fi
echo -e "Link: CONNECTED" echo -e "Link: CONNECTED"
addr=$(getIP ${ETH}) addr=$(getIP ${N})
netmask=$(ifconfig ${ETH} | grep inet | grep 255 | awk '{print $4}' | cut -f2 -d':') netmask=$(ifconfig ${N} | grep inet | grep 255 | awk '{print $4}' | cut -f2 -d':')
echo -e "IP Address: ${addr}" echo -e "IP Address: ${addr}"
echo -e "Netmask: ${netmask}" echo -e "Netmask: ${netmask}"
echo echo
@ -1281,14 +1281,14 @@ function networkdiag() {
fi fi
done done
echo echo
GITHUBAPI=$(curl --interface ${ETH} -skL "https://api.github.com/repos/AuxXxilium/arc/releases" | jq -r ".[].tag_name" | grep -v "dev" | sort -rV | head -1 2>/dev/null) GITHUBAPI=$(curl --interface ${N} -skL "https://api.github.com/repos/AuxXxilium/arc/releases" | jq -r ".[].tag_name" | grep -v "dev" | sort -rV | head -1 2>/dev/null)
if [[ $? -ne 0 || -z "${GITHUBAPI}" ]]; then if [[ $? -ne 0 || -z "${GITHUBAPI}" ]]; then
echo -e "Github API not reachable!" echo -e "Github API not reachable!"
else else
echo -e "Github API reachable!" echo -e "Github API reachable!"
fi fi
if [ "${CONFDONE}" == "true" ]; then if [ "${CONFDONE}" == "true" ]; then
SYNOAPI=$(curl --interface ${ETH} -m 5 -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${MODEL/+/%2B}&major=${PRODUCTVER%%.*}&minor=${PRODUCTVER##*.}" | jq -r '.info.system.detail[0].items[0].files[0].url') SYNOAPI=$(curl --interface ${N} -m 5 -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${MODEL/+/%2B}&major=${PRODUCTVER%%.*}&minor=${PRODUCTVER##*.}" | jq -r '.info.system.detail[0].items[0].files[0].url')
if [[ $? -ne 0 || -z "${SYNOAPI}" ]]; then if [[ $? -ne 0 || -z "${SYNOAPI}" ]]; then
echo -e "Syno API not reachable!" echo -e "Syno API not reachable!"
else else
@ -1340,15 +1340,16 @@ function credits() {
} }
############################################################################### ###############################################################################
# allow setting Static IP for Loader # Setting Static IP for Loader
function staticIPMenu() { function staticIPMenu() {
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep -v lo)
for ETH in ${ETHX}; do IPCON=""
MACR="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')" for N in ${ETHX}; do
MACR="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")" IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
IFS='/' read -r -a IPRA <<<"${IPR}" IFS='/' read -r -a IPRA <<<"${IPR}"
MSG="$(printf "Set to %s: (Delete if empty)" "${ETH}(${MACR})")" MSG="Set ${N}(${MACR}) IP to: (Delete if empty)"
while true; do while true; do
dialog --backtitle "$(backtitle)" --title "StaticIP" \ dialog --backtitle "$(backtitle)" --title "StaticIP" \
--form "${MSG}" 10 60 4 "address" 1 1 "${IPRA[0]}" 1 9 36 16 "netmask" 2 1 "${IPRA[1]}" 2 9 36 16 "gateway" 3 1 "${IPRA[2]}" 3 9 36 16 "dns" 4 1 "${IPRA[3]}" 4 9 36 16 \ --form "${MSG}" 10 60 4 "address" 1 1 "${IPRA[0]}" 1 9 36 16 "netmask" 2 1 "${IPRA[1]}" 2 9 36 16 "gateway" 3 1 "${IPRA[2]}" 3 9 36 16 "dns" 4 1 "${IPRA[3]}" 4 9 36 16 \
@ -1356,19 +1357,42 @@ function staticIPMenu() {
RET=$? RET=$?
case ${RET} in case ${RET} in
0) # ok-button 0) # ok-button
dialog --backtitle "$(backtitle)" --title "StaticIP" \
--infobox "Setting IP ..." 3 25
address="$(cat "${TMP_PATH}/resp" | sed -n '1p')" address="$(cat "${TMP_PATH}/resp" | sed -n '1p')"
netmask="$(cat "${TMP_PATH}/resp" | sed -n '2p')" netmask="$(cat "${TMP_PATH}/resp" | sed -n '2p')"
gateway="$(cat "${TMP_PATH}/resp" | sed -n '3p')" gateway="$(cat "${TMP_PATH}/resp" | sed -n '3p')"
dnsname="$(cat "${TMP_PATH}/resp" | sed -n '4p')" dnsname="$(cat "${TMP_PATH}/resp" | sed -n '4p')"
(
if [ -z "${address}" ]; then if [ -z "${address}" ]; then
if [ -n "$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")" ]; then
if [ "1" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
ip addr flush dev ${N}
fi
deleteConfigKey "network.${MACR}" "${USER_CONFIG_FILE}" deleteConfigKey "network.${MACR}" "${USER_CONFIG_FILE}"
IP="$(getIP)"
[ -z "${IPCON}" ] && IPCON="${IP}"
sleep 1
fi
else else
if [ "1" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
ip addr flush dev ${N}
ip addr add ${address}/${netmask:-"255.255.255.0"} dev ${N}
if [ -n "${gateway}" ]; then
ip route add default via ${gateway} dev ${N}
fi
if [ -n "${dnsname:-${gateway}}" ]; then
sed -i "/nameserver ${dnsname:-${gateway}}/d" /etc/resolv.conf
echo "nameserver ${dnsname:-${gateway}}" >>/etc/resolv.conf
fi
fi
writeConfigKey "network.${MACR}" "${address}/${netmask}/${gateway}/${dnsname}" "${USER_CONFIG_FILE}" writeConfigKey "network.${MACR}" "${address}/${netmask}/${gateway}/${dnsname}" "${USER_CONFIG_FILE}"
IP="$(getIP)"
[ -z "${IPCON}" ] && IPCON="${IP}"
sleep 1
fi fi
writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
) 2>&1 | dialog --backtitle "$(backtitle)" --title "StaticIP" \
--progressbox "Setting IP ..." 20 100
break break
;; ;;
1) # cancel-button 1) # cancel-button
@ -1379,28 +1403,6 @@ function staticIPMenu() {
;; ;;
esac esac
done done
sleep 1
done
IPCON=""
dialog --backtitle "$(backtitle)" --title "StaticIP" \
--infobox "Restart Network ..." 3 25
for ETH in ${ETHX}; do
MACR="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
if [ -n "${IPR}" ]; then
IFS='/' read -r -a IPRA <<<"${IPR}"
ip addr flush dev ${ETH}
ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${ETH}
[ -z "${IPCON}" ] && IPCON="${IPRA[0]}"
if [ -n "${IPRA[2]}" ]; then
ip route add default via ${IPRA[2]} dev ${ETH}
fi
if [ -n "${IPRA[3]:-${IPRA[2]}}" ]; then
sed -i "/nameserver ${IPRA[3]:-${IPRA[2]}}/d" /etc/resolv.conf
echo "nameserver ${IPRA[3]:-${IPRA[2]}}" >>/etc/resolv.conf
fi
sleep 1
fi
done done
} }

View File

@ -187,15 +187,14 @@ if echo "purley broadwellnkv2" | grep -wq "${PLATFORM}"; then
fi fi
# Cmdline NIC Settings # Cmdline NIC Settings
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
ETHM="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)" ETHM=$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)
ETHN="$(echo ${ETHX} | wc -w)" ETHN=$(echo ${ETHX} | wc -w)
[ -z "${ETHM}" ] && ETHM="${ETHN}" [ -z "${ETHM}" ] && ETHM=${ETHN}
NIC=0 NIC=0
for ETH in ${ETHX}; do for N in ${ETHX}; do
MAC="$(readConfigKey "${ETH}" "${USER_CONFIG_FILE}")" MAC="$(readConfigKey "${N}" "${USER_CONFIG_FILE}")"
[ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | tr '[:lower:]' '[:upper:]')" [ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${N}/address 2>/dev/null | tr '[:lower:]' '[:upper:]')" || NIC=$((${NIC} + 1))
NIC=$((${NIC} + 1))
[ ${NIC} -le ${ETHM} ] && CMDLINE["mac${NIC}"]="${MAC}" [ ${NIC} -le ${ETHM} ] && CMDLINE["mac${NIC}"]="${MAC}"
[ ${NIC} -ge ${ETHM} ] && break [ ${NIC} -ge ${ETHM} ] && break
done done
@ -268,18 +267,18 @@ elif [ "${DIRECTBOOT}" == "false" ]; then
echo echo
[ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 || true [ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 || true
sleep 3 sleep 3
for ETH in ${ETHX}; do for N in ${ETHX}; do
COUNT=0 COUNT=0
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}') DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
while true; do while true; do
if ethtool ${ETH} 2>/dev/null | grep 'Link detected' | grep -q 'no'; then if [ "0" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "\r${DRIVER}: \033[1;37mNOT CONNECTED\033[0m" echo -e "\r${DRIVER}: \033[1;37mNOT CONNECTED\033[0m"
break break
fi fi
COUNT=$((${COUNT} + 1)) COUNT=$((${COUNT} + 1))
IP="$(getIP ${ETH})" IP="$(getIP ${N})"
if [ -n "${IP}" ]; then if [ -n "${IP}" ]; then
SPEED=$(ethtool ${ETH} 2>/dev/null | grep "Speed:" | awk '{print $2}') SPEED=$(ethtool ${N} 2>/dev/null | grep "Speed:" | awk '{print $2}')
if [[ "${IP}" =~ ^169\.254\..* ]]; then if [[ "${IP}" =~ ^169\.254\..* ]]; then
echo -e "\r${DRIVER} (${SPEED}): \033[1;37mLINK LOCAL (No DHCP server found.)\033[0m" echo -e "\r${DRIVER} (${SPEED}): \033[1;37mLINK LOCAL (No DHCP server found.)\033[0m"
else else
@ -288,7 +287,7 @@ elif [ "${DIRECTBOOT}" == "false" ]; then
fi fi
break break
fi fi
if ! ip link show ${ETH} 2>/dev/null | grep -q 'UP'; then if [ -z "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "\r${DRIVER}: \033[1;37mDOWN\033[0m" echo -e "\r${DRIVER}: \033[1;37mDOWN\033[0m"
break break
fi fi

View File

@ -229,18 +229,16 @@ function _set_conf_kv() {
# sort netif busid # sort netif busid
function _sort_netif() { function _sort_netif() {
local ETHLIST="" local ETHLIST=""
local ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)" # real network cards list local ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
for ETH in ${ETHX}; do for N in ${ETHX}; do
local MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g; s/.*/\L&/')" local MAC="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g; s/.*/\L&/')"
local BUS="$(ethtool -i ${ETH} 2>/dev/null | grep bus-info | cut -d' ' -f2)" local BUS="$(ethtool -i ${N} 2>/dev/null | grep bus-info | cut -d' ' -f2)"
ETHLIST="${ETHLIST}${BUS} ${MAC} ${ETH}\n" ETHLIST="${ETHLIST}${BUS} ${MAC} ${N}\n"
done
local ETHLISTTMPB="$(echo -e "${ETHLIST}" | sort)" local ETHLISTTMPB="$(echo -e "${ETHLIST}" | sort)"
local ETHLIST="$(echo -e "${ETHLISTTMPB}" | grep -v '^$')" local ETHLIST="$(echo -e "${ETHLISTTMPB}" | grep -v '^$')"
local ETHSEQ="$(echo -e "${ETHLIST}" | awk '{print $3}' | sed 's/eth//g')" local ETHSEQ="$(echo -e "${ETHLIST}" | awk '{print $3}' | sed 's/eth//g')"
local ETHNUM="$(echo -e "${ETHLIST}" | wc -l)" local ETHNUM="$(echo -e "${ETHLIST}" | wc -l)"
# echo "${ETHSEQ}" >"/tmp/ethseq"
# sort # sort
if [ ! "${ETHSEQ}" = "$(seq 0 $((${ETHNUM:0} - 1)))" ]; then if [ ! "${ETHSEQ}" = "$(seq 0 $((${ETHNUM:0} - 1)))" ]; then
/etc/init.d/S41dhcpcd stop >/dev/null 2>&1 /etc/init.d/S41dhcpcd stop >/dev/null 2>&1

View File

@ -1,18 +1,17 @@
# Get Network Config for Loader # Get Network Config for Loader
function getnet() { function getnet() {
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")" MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
ARCPATCH="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")" ARCPATCH="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")"
NICPORTS="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)" NICPORTS="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)"
ETHN=$(echo ${ETHX} | wc -w)
if [ "${ARCPATCH}" == "true" ]; then if [ "${ARCPATCH}" == "true" ]; then
ETHN="$(echo ${ETHX} | wc -w)"
MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "true")) MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "true"))
for I in $(seq 1 ${ETHN}); do for I in $(seq 1 ${ETHN}); do
eval MAC${I}="${MACS[$((${I} - 1))]}" eval MAC${I}="${MACS[$((${I} - 1))]}"
writeConfigKey "eth$((${I} - 1))" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}" writeConfigKey "eth$((${I} - 1))" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}"
done done
elif [ "${ARCPATCH}" == "false" ]; then elif [ "${ARCPATCH}" == "false" ]; then
ETHN="$(echo ${ETHX} | wc -w)"
MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "false")) MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "false"))
for I in $(seq 1 ${ETHN}); do for I in $(seq 1 ${ETHN}); do
eval MAC${I}="${MACS[$((${I} - 1))]}" eval MAC${I}="${MACS[$((${I} - 1))]}"
@ -20,19 +19,19 @@ function getnet() {
done done
elif [ "${ARCPATCH}" == "user" ]; then elif [ "${ARCPATCH}" == "user" ]; then
# User Mac # User Mac
for ETH in ${ETHX}; do for N in ${ETHX}; do
while true; do while true; do
MAC="$(cat /sys/class/net/${ETH}/address | sed 's/://g' | tr '[:lower:]' '[:upper:]')" MAC="$(cat /sys/class/net/${N}/address | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
dialog --backtitle "$(backtitle)" --title "Mac Setting" \ dialog --backtitle "$(backtitle)" --title "Mac Setting" \
--inputbox "Type a custom MAC for ${ETH} (Eq. 001132abc123)." 7 50 "${MAC}"\ --inputbox "Type a custom MAC for ${ETH} (Eq. 001132abc123)." 7 50 "${MAC}"\
2>"${TMP_PATH}/resp" 2>"${TMP_PATH}/resp"
[ $? -ne 0 ] && break [ $? -ne 0 ] && break
MAC=$(cat "${TMP_PATH}/resp") MAC=$(cat "${TMP_PATH}/resp")
[ -z "${MAC}" ] && MAC="$(readConfigKey "${ETH}" "${USER_CONFIG_FILE}")" [ -z "${MAC}" ] && MAC="$(readConfigKey "${N}" "${USER_CONFIG_FILE}")"
[ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')" [ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
MAC="$(echo "${MAC}" | tr '[:lower:]' '[:upper:]')" MAC="$(echo "${MAC}" | tr '[:lower:]' '[:upper:]')"
if [ ${#MAC} -eq 12 ]; then if [ ${#MAC} -eq 12 ]; then
writeConfigKey "${ETH}" "${MAC}" "${USER_CONFIG_FILE}" writeConfigKey "${N}" "${MAC}" "${USER_CONFIG_FILE}"
break break
else else
dialog --backtitle "$(backtitle)" --title "Mac Setting" --msgbox "Invalid MAC - Try again!" 5 50 dialog --backtitle "$(backtitle)" --title "Mac Setting" --msgbox "Invalid MAC - Try again!" 5 50

View File

@ -95,16 +95,16 @@ if arrayExistItem "sortnetif:" $(readConfigMap "addons" "${USER_CONFIG_FILE}");
_sort_netif "$(readConfigKey "addons.sortnetif" "${USER_CONFIG_FILE}")" _sort_netif "$(readConfigKey "addons.sortnetif" "${USER_CONFIG_FILE}")"
fi fi
# Read/Write IP/Mac to config # Read/Write IP/Mac to config
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
for ETH in ${ETHX}; do for N in ${ETHX}; do
MACR="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')" MACR="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")" IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
if [ -n "${IPR}" ]; then if [ -n "${IPR}" ] && [ "1" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
IFS='/' read -r -a IPRA <<<"${IPR}" IFS='/' read -r -a IPRA <<<"${IPR}"
ip addr flush dev ${ETH} ip addr flush dev ${N}
ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${ETH} ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${N}
if [ -n "${IPRA[2]}" ]; then if [ -n "${IPRA[2]}" ]; then
ip route add default via ${IPRA[2]} dev ${ETH} ip route add default via ${IPRA[2]} dev ${N}
fi fi
if [ -n "${IPRA[3]:-${IPRA[2]}}" ]; then if [ -n "${IPRA[3]:-${IPRA[2]}}" ]; then
sed -i "/nameserver ${IPRA[3]:-${IPRA[2]}}/d" /etc/resolv.conf sed -i "/nameserver ${IPRA[3]:-${IPRA[2]}}/d" /etc/resolv.conf
@ -112,11 +112,11 @@ for ETH in ${ETHX}; do
fi fi
sleep 1 sleep 1
fi fi
[ "${ETH::3}" == "eth" ] && ethtool -s ${ETH} wol g 2>/dev/null || true [ "${N::3}" == "eth" ] && ethtool -s ${N} wol g 2>/dev/null || true
# [ "${ETH::3}" == "eth" ] && ethtool -K ${ETH} rxhash off 2>/dev/null || true # [ "${N::3}" == "eth" ] && ethtool -K ${N} rxhash off 2>/dev/null || true
initConfigKey "${ETH}" "${MACR}" "${USER_CONFIG_FILE}" initConfigKey "${N}" "${MACR}" "${USER_CONFIG_FILE}"
done done
ETHN="$(echo ${ETHX} | wc -w)" ETHN=$(echo ${ETHX} | wc -w)
writeConfigKey "device.nic" "${ETHN}" "${USER_CONFIG_FILE}" writeConfigKey "device.nic" "${ETHN}" "${USER_CONFIG_FILE}"
# No network devices # No network devices
echo echo
@ -171,18 +171,18 @@ IPCON=""
echo echo
[ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 || true [ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 || true
sleep 3 sleep 3
for ETH in ${ETHX}; do for N in ${ETHX}; do
COUNT=0 COUNT=0
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}') DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
while true; do while true; do
if ethtool ${ETH} 2>/dev/null | grep 'Link detected' | grep -q 'no'; then if [ "0" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "\r${DRIVER}: \033[1;37mNOT CONNECTED\033[0m" echo -e "\r${DRIVER}: \033[1;37mNOT CONNECTED\033[0m"
break break
fi fi
COUNT=$((${COUNT} + 1)) COUNT=$((${COUNT} + 1))
IP="$(getIP ${ETH})" IP="$(getIP ${N})"
if [ -n "${IP}" ]; then if [ -n "${IP}" ]; then
SPEED=$(ethtool ${ETH} 2>/dev/null | grep "Speed:" | awk '{print $2}') SPEED=$(ethtool ${N} 2>/dev/null | grep "Speed:" | awk '{print $2}')
if [[ "${IP}" =~ ^169\.254\..* ]]; then if [[ "${IP}" =~ ^169\.254\..* ]]; then
echo -e "\r${DRIVER} (${SPEED}): \033[1;37mLINK LOCAL (No DHCP server found.)\033[0m" echo -e "\r${DRIVER} (${SPEED}): \033[1;37mLINK LOCAL (No DHCP server found.)\033[0m"
else else
@ -191,7 +191,7 @@ for ETH in ${ETHX}; do
fi fi
break break
fi fi
if ! ip link show ${ETH} 2>/dev/null | grep -q 'UP'; then if [ -z "$(cat /sys/class/net/${N}}/carrier 2>/dev/null)" ]; then
echo -e "\r${DRIVER}: \033[1;37mDOWN\033[0m" echo -e "\r${DRIVER}: \033[1;37mDOWN\033[0m"
break break
fi fi