add 'no set macs' option

This commit is contained in:
Ing 2023-06-11 00:59:43 +08:00
parent 92b9f6b60e
commit 37fa4c45d0
3 changed files with 31 additions and 17 deletions

View File

@ -68,7 +68,7 @@ fi
declare -A CMDLINE declare -A CMDLINE
# Fixed values # Fixed values
#CMDLINE['netif_num']=0 CMDLINE['netif_num']=0
# Automatic values # Automatic values
CMDLINE['syno_hw_version']="${MODEL}" CMDLINE['syno_hw_version']="${MODEL}"
[ -z "${VID}" ] && VID="0x0000" # Sanity check [ -z "${VID}" ] && VID="0x0000" # Sanity check
@ -95,20 +95,26 @@ if [ "${BUS}" = "ata" ]; then
DOM="`readModelKey "${MODEL}" "dom"`" DOM="`readModelKey "${MODEL}" "dom"`"
fi fi
NOTSETMACS="`readConfigKey "notsetmacs" "${USER_CONFIG_FILE}"`"
if [ "${NOTSETMACS}" = "true" ]; then
for N in `seq 1 8`; do # Currently, only up to 8 are supported. (<==> menu.sh L396, <==> lkm: MAX_NET_IFACES)
[ -n "${CMDLINE["mac${N}"]}" ] && unset CMDLINE["mac${N}"]
done
unset CMDLINE['netif_num']
echo -e "\033[1;33m*** `printf "$(TEXT "Not set macs is enabled.")"` ***\033[0m"
else
# Validate netif_num # Validate netif_num
MACS=() MACS=()
for N in `seq 1 8`; do # Currently, only up to 8 are supported. (<==> menu.sh L396, <==> lkm: MAX_NET_IFACES) for N in `seq 1 8`; do # Currently, only up to 8 are supported. (<==> menu.sh L396, <==> lkm: MAX_NET_IFACES)
[ -n "${CMDLINE["mac${N}"]}" ] && MACS+=(${CMDLINE["mac${N}"]}) [ -n "${CMDLINE["mac${N}"]}" ] && MACS+=(${CMDLINE["mac${N}"]})
done done
NETIF_NUM=${#MACS[*]} NETIF_NUM=${#MACS[*]}
NETRL_NUM=`ls /sys/class/net/ | grep eth | wc -l` # real network cards amount
if [ ${NETIF_NUM} -eq 0 ]; then
echo -e "\033[1;33m*** `printf "$(TEXT "Detected %s network cards, but No MACs were customized, they will use the original MACs. May affect account related functions.")" "${NETRL_NUM}"` ***\033[0m"
else
# set netif_num to custom mac amount, netif_num must be equal to the MACX amount, otherwise the kernel will panic. # set netif_num to custom mac amount, netif_num must be equal to the MACX amount, otherwise the kernel will panic.
CMDLINE["netif_num"]=${NETIF_NUM} # The current original CMDLINE['netif_num'] is no longer in use, Consider deleting. CMDLINE["netif_num"]=${NETIF_NUM} # The current original CMDLINE['netif_num'] is no longer in use, Consider deleting.
# real network cards amount
NETRL_NUM=`ls /sys/class/net/ | grep eth | wc -l`
if [ ${NETIF_NUM} -le ${NETRL_NUM} ]; then if [ ${NETIF_NUM} -le ${NETRL_NUM} ]; then
echo -e "\033[1;33m*** `printf "$(TEXT "Detected %s network cards, but only %s MACs were customized, the rest will use the original MACs.")" "${NETRL_NUM}" "${CMDLINE["netif_num"]}"` ***\033[0m" echo -e "\033[1;33m*** `printf "$(TEXT "Detected %s network cards, %s MACs were customized, the rest will use the original MACs.")" "${NETRL_NUM}" "${CMDLINE["netif_num"]}"` ***\033[0m"
ETHX=(`ls /sys/class/net/ | grep eth`) # real network cards list ETHX=(`ls /sys/class/net/ | grep eth`) # real network cards list
for N in `seq $(expr ${NETIF_NUM} + 1) ${NETRL_NUM}`; do for N in `seq $(expr ${NETIF_NUM} + 1) ${NETRL_NUM}`; do
MACR="`cat /sys/class/net/${ETHX[$(expr ${N} - 1)]}/address | sed 's/://g'`" MACR="`cat /sys/class/net/${ETHX[$(expr ${N} - 1)]}/address | sed 's/://g'`"
@ -121,7 +127,6 @@ else
CMDLINE["netif_num"]=${NETRL_NUM} CMDLINE["netif_num"]=${NETRL_NUM}
fi fi
fi fi
# Prepare command line # Prepare command line
CMDLINE_LINE="" CMDLINE_LINE=""
grep -q "force_junior" /proc/cmdline && CMDLINE_LINE+="force_junior " grep -q "force_junior" /proc/cmdline && CMDLINE_LINE+="force_junior "
@ -149,8 +154,9 @@ if [ "${DIRECT}" = "true" ]; then
reboot reboot
exit 0 exit 0
else else
sleep 1
ETHX=(`ls /sys/class/net/ | grep eth`) # real network cards list ETHX=(`ls /sys/class/net/ | grep eth`) # real network cards list
echo "`printf "$(TEXT "Detected %s network cards, Waiting IP.(For reference only, not absolute.)")" "${#ETHX[@]}"`" echo "`printf "$(TEXT "Detected %s network cards, Waiting IP.(For reference only)")" "${#ETHX[@]}"`"
for N in $(seq 0 $(expr ${#ETHX[@]} - 1)); do for N in $(seq 0 $(expr ${#ETHX[@]} - 1)); do
COUNT=0 COUNT=0
DRIVER=`ls -ld /sys/class/net/${ETHX[${N}]}/device/driver 2>/dev/null | awk -F '/' '{print $NF}'` DRIVER=`ls -ld /sys/class/net/${ETHX[${N}]}/device/driver 2>/dev/null | awk -F '/' '{print $NF}'`

View File

@ -76,6 +76,7 @@ if [ ! -f "${USER_CONFIG_FILE}" ]; then
touch "${USER_CONFIG_FILE}" touch "${USER_CONFIG_FILE}"
writeConfigKey "lkm" "prod" "${USER_CONFIG_FILE}" writeConfigKey "lkm" "prod" "${USER_CONFIG_FILE}"
writeConfigKey "directboot" "false" "${USER_CONFIG_FILE}" writeConfigKey "directboot" "false" "${USER_CONFIG_FILE}"
writeConfigKey "notsetmacs" "false" "${USER_CONFIG_FILE}"
writeConfigKey "model" "" "${USER_CONFIG_FILE}" writeConfigKey "model" "" "${USER_CONFIG_FILE}"
writeConfigKey "build" "" "${USER_CONFIG_FILE}" writeConfigKey "build" "" "${USER_CONFIG_FILE}"
writeConfigKey "sn" "" "${USER_CONFIG_FILE}" writeConfigKey "sn" "" "${USER_CONFIG_FILE}"
@ -175,20 +176,21 @@ fi
echo "`printf "$(TEXT "Detected %s network cards, Waiting IP.")" "${#ETHX[@]}"`" echo "`printf "$(TEXT "Detected %s network cards, Waiting IP.")" "${#ETHX[@]}"`"
for N in $(seq 0 $(expr ${#ETHX[@]} - 1)); do for N in $(seq 0 $(expr ${#ETHX[@]} - 1)); do
COUNT=0 COUNT=0
echo -en "${ETHX[${N}]}: " DRIVER=`ls -ld /sys/class/net/${ETHX[${N}]}/device/driver 2>/dev/null | awk -F '/' '{print $NF}'`
echo -en "${ETHX[${N}]}(${DRIVER}): "
while true; do while true; do
if [ -z "`ip link show ${ETHX[${N}]} | grep 'UP'`" ]; then if [ -z "`ip link show ${ETHX[${N}]} | grep 'UP'`" ]; then
echo -en "\r${ETHX[${N}]}: $(TEXT "DOWN")\n" echo -en "\r${ETHX[${N}]}(${DRIVER}): $(TEXT "DOWN")\n"
break break
fi fi
if [ ${COUNT} -eq 30 ]; then if [ ${COUNT} -eq 30 ]; then
echo -en "\r${ETHX[${N}]}: $(TEXT "ERROR")\n" echo -en "\r${ETHX[${N}]}(${DRIVER}): $(TEXT "ERROR")\n"
break break
fi fi
COUNT=$((${COUNT}+1)) COUNT=$((${COUNT}+1))
IP=`ip route show dev ${ETHX[${N}]} 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p'` IP=`ip route show dev ${ETHX[${N}]} 2>/dev/null | sed -n 's/.* via .* src \(.*\) metric .*/\1/p'`
if [ -n "${IP}" ]; then if [ -n "${IP}" ]; then
echo -en "\r${ETHX[${N}]}: `printf "$(TEXT "Access \033[1;34mhttp://%s:7681\033[0m to configure the loader via web terminal.")" "${IP}"`\n" echo -en "\r${ETHX[${N}]}(${DRIVER}): `printf "$(TEXT "Access \033[1;34mhttp://%s:7681\033[0m to configure the loader via web terminal.")" "${IP}"`\n"
break break
fi fi
echo -n "." echo -n "."

View File

@ -26,6 +26,7 @@ LAYOUT="`readConfigKey "layout" "${USER_CONFIG_FILE}"`"
KEYMAP="`readConfigKey "keymap" "${USER_CONFIG_FILE}"`" KEYMAP="`readConfigKey "keymap" "${USER_CONFIG_FILE}"`"
LKM="`readConfigKey "lkm" "${USER_CONFIG_FILE}"`" LKM="`readConfigKey "lkm" "${USER_CONFIG_FILE}"`"
DIRECTBOOT="`readConfigKey "directboot" "${USER_CONFIG_FILE}"`" DIRECTBOOT="`readConfigKey "directboot" "${USER_CONFIG_FILE}"`"
NOTSETMACS="`readConfigKey "notsetmacs" "${USER_CONFIG_FILE}"`"
SN="`readConfigKey "sn" "${USER_CONFIG_FILE}"`" SN="`readConfigKey "sn" "${USER_CONFIG_FILE}"`"
############################################################################### ###############################################################################
@ -879,6 +880,7 @@ function advancedMenu() {
if loaderIsConfigured; then if loaderIsConfigured; then
echo "q \"$(TEXT "Switch direct boot:") \Z4${DIRECTBOOT}\Zn\"" >> "${TMP_PATH}/menu" echo "q \"$(TEXT "Switch direct boot:") \Z4${DIRECTBOOT}\Zn\"" >> "${TMP_PATH}/menu"
fi fi
echo "m \"$(TEXT "Switch not set MACs:") \Z4${NOTSETMACS}\Zn\"" >> "${TMP_PATH}/menu"
echo "u \"$(TEXT "Edit user config file manually")\"" >> "${TMP_PATH}/menu" echo "u \"$(TEXT "Edit user config file manually")\"" >> "${TMP_PATH}/menu"
echo "t \"$(TEXT "Try to recovery a DSM installed system")\"" >> "${TMP_PATH}/menu" echo "t \"$(TEXT "Try to recovery a DSM installed system")\"" >> "${TMP_PATH}/menu"
echo "s \"$(TEXT "Show SATA(s) # ports and drives")\"" >> "${TMP_PATH}/menu" echo "s \"$(TEXT "Show SATA(s) # ports and drives")\"" >> "${TMP_PATH}/menu"
@ -913,6 +915,10 @@ function advancedMenu() {
writeConfigKey "directboot" "${DIRECTBOOT}" "${USER_CONFIG_FILE}" writeConfigKey "directboot" "${DIRECTBOOT}" "${USER_CONFIG_FILE}"
NEXT="e" NEXT="e"
;; ;;
m) [ "${NOTSETMACS}" = "false" ] && NOTSETMACS='true' || NOTSETMACS='false'
writeConfigKey "notsetmacs" "${NOTSETMACS}" "${USER_CONFIG_FILE}"
NEXT="e"
;;
u) editUserConfig; NEXT="e" ;; u) editUserConfig; NEXT="e" ;;
t) tryRecoveryDSM ;; t) tryRecoveryDSM ;;
s) MSG="" s) MSG=""