tree: rework static ip

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-09-14 23:56:14 +02:00
parent acdcd2c63c
commit 2729ea0f43
5 changed files with 36 additions and 25 deletions

View File

@ -1119,7 +1119,7 @@ function sysinfo() {
CPU=$(echo $(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:" | sed 's/\[.*\] DMI: //i')
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
ETHN="$(echo ${ETHX} | wc -w)"
ARCBRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")"
@ -1404,7 +1404,7 @@ function uploadDiag () {
# Shows Networkdiag to user
function networkdiag() {
(
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
for ETH in ${ETHX}; do
echo
DRIVER=$(ls -ld /sys/class/net/${ETH}/device/driver 2>/dev/null | awk -F '/' '{print $NF}')
@ -1492,7 +1492,7 @@ function credits() {
###############################################################################
# allow setting Static IP for Loader
function staticIPMenu() {
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
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:]')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
@ -1507,7 +1507,7 @@ function staticIPMenu() {
case ${RET} in
0) # ok-button
dialog --backtitle "$(backtitle)" --title "StaticIP" \
--infobox "Setting IP ..." 0 0
--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')"
@ -1515,18 +1515,7 @@ function staticIPMenu() {
if [ -z "${address}" ]; then
deleteConfigKey "network.${MACR}" "${USER_CONFIG_FILE}"
else
ip addr flush dev $ETH
ip addr add ${address}/${netmask:-"255.255.255.0"} dev $ETH
if [ -n "${gateway}" ]; then
ip route add default via ${gateway} dev $ETH
fi
if [ -n "${dnsname:-${gateway}}" ]; then
sed -i "/nameserver ${dnsname:-${gateway}}/d" /etc/resolv.conf
echo "nameserver ${dnsname:-${gateway}}" >>/etc/resolv.conf
fi
writeConfigKey "network.${MACR}" "${address}/${netmask}/${gateway}/${dnsname}" "${USER_CONFIG_FILE}"
IP="$(getIP)"
sleep 1
fi
writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
@ -1540,6 +1529,28 @@ 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
}
@ -2136,7 +2147,7 @@ function decryptMenu() {
# ArcNIC Menu
function arcNIC () {
ARCNIC="$(readConfigKey "arc.nic" "${USER_CONFIG_FILE}")"
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)" # real network cards list
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)" # real network cards list
rm -f "${TMP_PATH}/opts" >/dev/null
touch "${TMP_PATH}/opts"
echo -e "auto \"Automated\"" >>"${TMP_PATH}/opts"

View File

@ -1006,7 +1006,7 @@ else
echo "G \"Install opkg Package Manager \" " >>"${TMP_PATH}/menu"
fi
echo "y \"Choose a Keymap for Loader\" " >>"${TMP_PATH}/menu"
echo "D \"StaticIP \" " >>"${TMP_PATH}/menu"
echo "D \"StaticIP for Loader/DSM\" " >>"${TMP_PATH}/menu"
fi
echo "= \"\Z4========== Misc ==========\Zn \" " >>"${TMP_PATH}/menu"
echo "x \"Config Backup/Restore/Recovery \" " >>"${TMP_PATH}/menu"

View File

@ -183,14 +183,14 @@ if echo "purley broadwellnkv2" | grep -wq "${PLATFORM}"; then
fi
# Cmdline NIC Settings
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
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}"
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 | sed 's/://g' | tr '[:upper:]' '[:lower:]')"
[ -z "${MAC}" ] && MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:lower:]' '[:upper:]')"
NIC=$((${NIC} + 1))
[ ${NIC} -le ${ETHM} ] && CMDLINE["mac${NIC}"]="${MAC}"
[ ${NIC} -ge ${ETHM} ] && break

View File

@ -1,6 +1,6 @@
# Get Network Config for Loader
function getnet() {
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
ARCPATCH="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")"
NICPORTS="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)"
@ -41,7 +41,7 @@ function getnet() {
}
# Get Amount of NIC
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
# Get actual IP
for ETH in ${ETHX}; do
IPCON=$(getIP ${ETH})

View File

@ -96,7 +96,7 @@ fi
compatboot
# Init Network
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)"
ETHX="$(ls /sys/class/net 2>/dev/null | grep eth)"
if arrayExistItem "sortnetif:" $(readConfigMap "addons" "${USER_CONFIG_FILE}"); then
_sort_netif "$(readConfigKey "addons.sortnetif" "${USER_CONFIG_FILE}")"
fi
@ -107,10 +107,10 @@ for ETH in ${ETHX}; do
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
ip addr flush dev ${ETH}
ip addr add ${IPRA[0]}/${IPRA[1]:-"255.255.255.0"} dev ${ETH}
if [ -n "${IPRA[2]}" ]; then
ip route add default via ${IPRA[2]} dev $ETH
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