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}')"
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')
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
ETHN="$(echo ${ETHX} | wc -w)"
ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
ETHN=$(echo ${ETHX} | wc -w)
ARC_BRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
CONFDONE="$(readConfigKey "arc.confdone" "${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"
TEXT+="\n\Z4> Network: ${ETHN} NIC\Zn"
for ETH in ${ETHX}; do
for N in ${ETHX}; do
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
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"
break
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"
break
fi
@ -1027,9 +1027,9 @@ function sysinfo() {
break
fi
COUNT=$((${COUNT} + 1))
IP="$(getIP ${ETH})"
IP="$(getIP ${N})"
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
TEXT+="\n$ {DRIVER} (${SPEED}): \ZbLINK LOCAL (No DHCP server found.)\Zn"
else
@ -1245,22 +1245,22 @@ function uploadDiag () {
# Shows Networkdiag to user
function networkdiag() {
(
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
for ETH in ${ETHX}; do
ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
for N in ${ETHX}; do
echo
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
echo -e "Interface: ${ETH} (${DRIVER})"
if ethtool ${ETH} 2>/dev/null | grep 'Link detected' | grep -q 'no'; then
DRIVER=$(ls -ld /sys/class/net/${N}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
echo -e "Interface: ${N} (${DRIVER})"
if [ "0" = "$(cat /sys/class/net/${N}/carrier 2>/dev/null)" ]; then
echo -e "Link: NOT CONNECTED"
continue
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"
continue
fi
echo -e "Link: CONNECTED"
addr=$(getIP ${ETH})
netmask=$(ifconfig ${ETH} | grep inet | grep 255 | awk '{print $4}' | cut -f2 -d':')
addr=$(getIP ${N})
netmask=$(ifconfig ${N} | grep inet | grep 255 | awk '{print $4}' | cut -f2 -d':')
echo -e "IP Address: ${addr}"
echo -e "Netmask: ${netmask}"
echo
@ -1281,14 +1281,14 @@ function networkdiag() {
fi
done
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
echo -e "Github API not reachable!"
else
echo -e "Github API reachable!"
fi
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
echo -e "Syno API not reachable!"
else
@ -1340,15 +1340,16 @@ function credits() {
}
###############################################################################
# allow setting Static IP for Loader
# Setting Static IP for Loader
function staticIPMenu() {
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
for ETH in ${ETHX}; do
MACR="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep -v lo)
IPCON=""
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}")"
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
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 \
@ -1356,19 +1357,42 @@ function staticIPMenu() {
RET=$?
case ${RET} in
0) # ok-button
dialog --backtitle "$(backtitle)" --title "StaticIP" \
--infobox "Setting IP ..." 3 25
address="$(cat "${TMP_PATH}/resp" | sed -n '1p')"
netmask="$(cat "${TMP_PATH}/resp" | sed -n '2p')"
gateway="$(cat "${TMP_PATH}/resp" | sed -n '3p')"
dnsname="$(cat "${TMP_PATH}/resp" | sed -n '4p')"
(
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}"
IP="$(getIP)"
[ -z "${IPCON}" ] && IPCON="${IP}"
sleep 1
fi
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}"
IP="$(getIP)"
[ -z "${IPCON}" ] && IPCON="${IP}"
sleep 1
fi
writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
) 2>&1 | dialog --backtitle "$(backtitle)" --title "StaticIP" \
--progressbox "Setting IP ..." 20 100
break
;;
1) # cancel-button
@ -1379,28 +1403,6 @@ function staticIPMenu() {
;;
esac
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
}

View File

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

View File

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

View File

@ -1,18 +1,17 @@
# Get Network Config for Loader
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}")"
ARCPATCH="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")"
NICPORTS="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)"
ETHN=$(echo ${ETHX} | wc -w)
if [ "${ARCPATCH}" == "true" ]; then
ETHN="$(echo ${ETHX} | wc -w)"
MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "true"))
for I in $(seq 1 ${ETHN}); do
eval MAC${I}="${MACS[$((${I} - 1))]}"
writeConfigKey "eth$((${I} - 1))" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}"
done
elif [ "${ARCPATCH}" == "false" ]; then
ETHN="$(echo ${ETHX} | wc -w)"
MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "false"))
for I in $(seq 1 ${ETHN}); do
eval MAC${I}="${MACS[$((${I} - 1))]}"
@ -20,19 +19,19 @@ function getnet() {
done
elif [ "${ARCPATCH}" == "user" ]; then
# User Mac
for ETH in ${ETHX}; do
for N in ${ETHX}; 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" \
--inputbox "Type a custom MAC for ${ETH} (Eq. 001132abc123)." 7 50 "${MAC}"\
2>"${TMP_PATH}/resp"
[ $? -ne 0 ] && break
MAC=$(cat "${TMP_PATH}/resp")
[ -z "${MAC}" ] && MAC="$(readConfigKey "${ETH}" "${USER_CONFIG_FILE}")"
[ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
[ -z "${MAC}" ] && MAC="$(readConfigKey "${N}" "${USER_CONFIG_FILE}")"
[ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
MAC="$(echo "${MAC}" | tr '[:lower:]' '[:upper:]')"
if [ ${#MAC} -eq 12 ]; then
writeConfigKey "${ETH}" "${MAC}" "${USER_CONFIG_FILE}"
writeConfigKey "${N}" "${MAC}" "${USER_CONFIG_FILE}"
break
else
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}")"
fi
# Read/Write IP/Mac to config
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
for ETH in ${ETHX}; do
MACR="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
ETHX=$(ip -o link show | awk -F': ' '{print $2}' | grep eth)
for N in ${ETHX}; do
MACR="$(cat /sys/class/net/${N}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
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}"
ip addr flush dev ${ETH}
ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${ETH}
ip addr flush dev ${N}
ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${N}
if [ -n "${IPRA[2]}" ]; then
ip route add default via ${IPRA[2]} dev ${ETH}
ip route add default via ${IPRA[2]} dev ${N}
fi
if [ -n "${IPRA[3]:-${IPRA[2]}}" ]; then
sed -i "/nameserver ${IPRA[3]:-${IPRA[2]}}/d" /etc/resolv.conf
@ -112,11 +112,11 @@ for ETH in ${ETHX}; do
fi
sleep 1
fi
[ "${ETH::3}" == "eth" ] && ethtool -s ${ETH} wol g 2>/dev/null || true
# [ "${ETH::3}" == "eth" ] && ethtool -K ${ETH} rxhash off 2>/dev/null || true
initConfigKey "${ETH}" "${MACR}" "${USER_CONFIG_FILE}"
[ "${N::3}" == "eth" ] && ethtool -s ${N} wol g 2>/dev/null || true
# [ "${N::3}" == "eth" ] && ethtool -K ${N} rxhash off 2>/dev/null || true
initConfigKey "${N}" "${MACR}" "${USER_CONFIG_FILE}"
done
ETHN="$(echo ${ETHX} | wc -w)"
ETHN=$(echo ${ETHX} | wc -w)
writeConfigKey "device.nic" "${ETHN}" "${USER_CONFIG_FILE}"
# No network devices
echo
@ -171,18 +171,18 @@ IPCON=""
echo
[ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 || true
sleep 3
for ETH in ${ETHX}; do
for N in ${ETHX}; do
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
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"
break
fi
COUNT=$((${COUNT} + 1))
IP="$(getIP ${ETH})"
IP="$(getIP ${N})"
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
echo -e "\r${DRIVER} (${SPEED}): \033[1;37mLINK LOCAL (No DHCP server found.)\033[0m"
else
@ -191,7 +191,7 @@ for ETH in ${ETHX}; do
fi
break
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"
break
fi