modify mac related

This commit is contained in:
Ing 2023-09-28 20:27:23 +08:00
parent 4617a29784
commit 7f590099d9
10 changed files with 1099 additions and 1167 deletions

View File

@ -60,14 +60,11 @@ if [ "${RAMDISK_HASH_CUR}" != "${RAMDISK_HASH}" ]; then
fi
# Load necessary variables
VID="$(readConfigKey "vid" "${USER_CONFIG_FILE}")"
PID="$(readConfigKey "pid" "${USER_CONFIG_FILE}")"
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")"
BUILDNUM="$(readConfigKey "buildnum" "${USER_CONFIG_FILE}")"
SMALLNUM="$(readConfigKey "smallnum" "${USER_CONFIG_FILE}")"
LKM="$(readConfigKey "lkm" "${USER_CONFIG_FILE}")"
SN="$(readConfigKey "sn" "${USER_CONFIG_FILE}")"
DMI="$(dmesg | grep -i "DMI:" | sed 's/\[.*\] DMI: //i')"
CPU="$(echo $(cat /proc/cpuinfo | grep 'model name' | uniq | awk -F':' '{print $2}'))"
@ -85,17 +82,22 @@ if [ ! -f "${MODEL_CONFIG_PATH}/${MODEL}.yml" ] || [ -z "$(readConfigKey "produc
exit 1
fi
VID="$(readConfigKey "vid" "${USER_CONFIG_FILE}")"
PID="$(readConfigKey "pid" "${USER_CONFIG_FILE}")"
SN="$(readConfigKey "sn" "${USER_CONFIG_FILE}")"
MAC1="$(readConfigKey "mac1" "${USER_CONFIG_FILE}")"
declare -A CMDLINE
# Fixed values
CMDLINE['netif_num']=0
# Automatic values
CMDLINE['syno_hw_version']="${MODEL}"
[ -z "${VID}" ] && VID="0x0000" # Sanity check
[ -z "${PID}" ] && PID="0x0000" # Sanity check
[ -z "${VID}" ] && VID="0x46f4" # Sanity check
[ -z "${PID}" ] && PID="0x0001" # Sanity check
CMDLINE['vid']="${VID}"
CMDLINE['pid']="${PID}"
CMDLINE['sn']="${SN}"
CMDLINE['mac1']="${MAC1}"
CMDLINE['netif_num']="1"
# Read cmdline
while IFS=': ' read KEY VALUE; do
@ -115,61 +117,22 @@ if [ ! "${BUS}" = "usb" ]; then
DOM="$(readModelKey "${MODEL}" "dom")"
fi
NOTSETMACS="$(readConfigKey "notsetmacs" "${USER_CONFIG_FILE}")"
if [ "${NOTSETMACS}" = "true" ]; then
# Currently, only up to 8 are supported. (<==> menu.sh L396, <==> lkm: MAX_NET_IFACES)
for N in $(seq 1 8); do
[ -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
MACS=()
# Currently, only up to 8 are supported. (<==> menu.sh L396, <==> lkm: MAX_NET_IFACES)
for N in $(seq 1 8); do
[ -n "${CMDLINE["mac${N}"]}" ] && MACS+=(${CMDLINE["mac${N}"]})
done
NETIF_NUM=${#MACS[*]}
# 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.
# real network cards amount
NETRL_NUM=$(ls /sys/class/net/ | grep eth | wc -l)
if [ ${NETIF_NUM} -le ${NETRL_NUM} ]; then
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
for N in $(seq $(expr ${NETIF_NUM} + 1) ${NETRL_NUM}); do
MACR="$(cat /sys/class/net/${ETHX[$(expr ${N} - 1)]}/address | sed 's/://g')"
# no duplicates
while [[ "${MACS[*]}" =~ "$MACR" ]]; do # no duplicates
MACR="${MACR:0:10}$(printf "%02x" $((0x${MACR:10:2} + 1)))"
done
CMDLINE["mac${N}"]="${MACR}"
done
CMDLINE["netif_num"]=${NETRL_NUM}
fi
fi
# Prepare command line
CMDLINE_LINE=""
grep -q "force_junior" /proc/cmdline && CMDLINE_LINE+="force_junior "
[ ${EFI} -eq 1 ] && CMDLINE_LINE+="withefi " || CMDLINE_LINE+="noefi "
[ ! "${BUS}" = "usb" ] && CMDLINE_LINE+="synoboot_satadom=${DOM} dom_szmax=${SIZE} "
CMDLINE_LINE+="console=ttyS0,115200n8 earlyprintk earlycon=uart8250,io,0x3f8,115200n8 root=/dev/md0 loglevel=15 log_buf_len=32M"
CMDLINE_DIRECT="${CMDLINE_LINE}"
CMDLINE_LINE+="console=ttyS0,115200n8 earlyprintk earlycon=uart8250,io,0x3f8,115200n8 root=/dev/md0 skip_vender_mac_interfaces=0,1,2,3,4,5,6,7 loglevel=15 log_buf_len=32M"
for KEY in ${!CMDLINE[@]}; do
VALUE="${CMDLINE[${KEY}]}"
CMDLINE_LINE+=" ${KEY}"
CMDLINE_DIRECT+=" ${KEY}"
[ -n "${VALUE}" ] && CMDLINE_LINE+="=${VALUE}"
[ -n "${VALUE}" ] && CMDLINE_DIRECT+="=${VALUE}"
done
# Escape special chars
#CMDLINE_LINE=`echo ${CMDLINE_LINE} | sed 's/>/\\\\>/g'`
CMDLINE_DIRECT=$(echo ${CMDLINE_DIRECT} | sed 's/>/\\\\>/g')
echo -e "$(TEXT "Cmdline:\n")\033[1;36m${CMDLINE_LINE}\033[0m"
DIRECT="$(readConfigKey "directboot" "${USER_CONFIG_FILE}")"
if [ "${DIRECT}" = "true" ]; then
CMDLINE_DIRECT=$(echo ${CMDLINE_LINE} | sed 's/>/\\\\>/g') # Escape special chars
grub-editenv ${GRUB_PATH}/grubenv set dsm_cmdline="${CMDLINE_DIRECT}"
echo -e "\033[1;33m$(TEXT "Reboot to boot directly in DSM")\033[0m"
grub-editenv ${GRUB_PATH}/grubenv set next_entry="direct"
@ -243,22 +206,22 @@ else
BOOTWAIT=$((BOOTWAIT - 1))
done
rm -f WB WC
echo -en "\r$(printf "%$((${#MSG} * 3))s" " ")\n"
fi
echo -en "\r$(printf "%$((${#MSG} * 2))s" " ")\n"
echo -e "\033[1;37m$(TEXT "Loading DSM kernel...")\033[0m"
echo -e "\033[1;37m$(TEXT "Loading DSM kernel...")\033[0m"
# Executes DSM kernel via KEXEC
if [ "${KVER:0:1}" = "3" -a ${EFI} -eq 1 ]; then
echo -e "\033[1;33m$(TEXT "Warning, running kexec with --noefi param, strange things will happen!!")\033[0m"
kexec --noefi -l "${MOD_ZIMAGE_FILE}" --initrd "${MOD_RDGZ_FILE}" --command-line="${CMDLINE_LINE}" >"${LOG_FILE}" 2>&1 || dieLog
else
kexec -l "${MOD_ZIMAGE_FILE}" --initrd "${MOD_RDGZ_FILE}" --command-line="${CMDLINE_LINE}" >"${LOG_FILE}" 2>&1 || dieLog
fi
echo -e "\033[1;37m$(TEXT "Booting...")\033[0m"
for T in $(w | grep -v "TTY" | awk -F' ' '{print $2}'); do
echo -e "\n\033[1;43m$(TEXT "[This interface will not be operational.\nPlease wait for a few minutes before using the http://find.synology.com/ or Synology Assistant find DSM and connect.]")\033[0m\n" >"/dev/${T}" 2>/dev/null || true
done
KERNELWAY="$(readConfigKey "kernelway" "${USER_CONFIG_FILE}")"
[ "${KERNELWAY}" = "kexec" ] && kexec -f -e || poweroff
exit 0
# Executes DSM kernel via KEXEC
if [ "${KVER:0:1}" = "3" -a ${EFI} -eq 1 ]; then
echo -e "\033[1;33m$(TEXT "Warning, running kexec with --noefi param, strange things will happen!!")\033[0m"
kexec --noefi -l "${MOD_ZIMAGE_FILE}" --initrd "${MOD_RDGZ_FILE}" --command-line="${CMDLINE_LINE}" >"${LOG_FILE}" 2>&1 || dieLog
else
kexec -l "${MOD_ZIMAGE_FILE}" --initrd "${MOD_RDGZ_FILE}" --command-line="${CMDLINE_LINE}" >"${LOG_FILE}" 2>&1 || dieLog
fi
echo -e "\033[1;37m$(TEXT "Booting...")\033[0m"
for T in $(w | grep -v "TTY" | awk -F' ' '{print $2}'); do
echo -e "\n\033[1;43m$(TEXT "[This interface will not be operational.\nPlease wait for a few minutes before using the http://find.synology.com/ or Synology Assistant find DSM and connect.]")\033[0m\n" >"/dev/${T}" 2>/dev/null || true
done
KERNELWAY="$(readConfigKey "kernelway" "${USER_CONFIG_FILE}")"
[ "${KERNELWAY}" = "kexec" ] && kexec -f -e || poweroff
exit 0
fi

View File

@ -103,6 +103,21 @@ function generateSerial() {
echo ${SERIAL}
}
###############################################################################
# Generate a MAC address for a model
# 1 - Model
# 2 - number
# Returns serial number
function generateMacAddress() {
PRE="$(readModelArray "${1}" "serial.macpre")"
SUF="$(printf '%02x%02x%02x' $((${RANDOM} % 256)) $((${RANDOM} % 256)) $((${RANDOM} % 256)))"
NUM=${2:-1}
for I in $(seq 1 ${NUM}); do
printf '%06x%06x' $((0x${PRE:-"001132"})) $(($((0x${SUF})) + ${I}))
[ ${I} -lt ${NUM} ] && printf ' '
done
}
###############################################################################
# Validate a serial number for a model
# 1 - Model

View File

@ -77,7 +77,6 @@ if [ ! -f "${USER_CONFIG_FILE}" ]; then
writeConfigKey "lkm" "prod" "${USER_CONFIG_FILE}"
writeConfigKey "dsmlogo" "true" "${USER_CONFIG_FILE}"
writeConfigKey "directboot" "false" "${USER_CONFIG_FILE}"
writeConfigKey "notsetmacs" "false" "${USER_CONFIG_FILE}"
writeConfigKey "prerelease" "false" "${USER_CONFIG_FILE}"
writeConfigKey "bootwait" "10" "${USER_CONFIG_FILE}"
writeConfigKey "bootipwait" "10" "${USER_CONFIG_FILE}"
@ -90,6 +89,7 @@ if [ ! -f "${USER_CONFIG_FILE}" ]; then
writeConfigKey "paturl" "" "${USER_CONFIG_FILE}"
writeConfigKey "patsum" "" "${USER_CONFIG_FILE}"
writeConfigKey "sn" "" "${USER_CONFIG_FILE}"
writeConfigKey "mac1" "" "${USER_CONFIG_FILE}"
# writeConfigKey "maxdisks" "" "${USER_CONFIG_FILE}"
writeConfigKey "layout" "qwerty" "${USER_CONFIG_FILE}"
writeConfigKey "keymap" "" "${USER_CONFIG_FILE}"
@ -102,30 +102,20 @@ if [ ! -f "${USER_CONFIG_FILE}" ]; then
writeConfigKey "addons.acpid" "" "${USER_CONFIG_FILE}"
writeConfigKey "addons.reboottoarpl" "" "${USER_CONFIG_FILE}"
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
# When the user has not customized, Use 1 to maintain normal startup parameters.
# writeConfigKey "cmdline.netif_num" "1" "${USER_CONFIG_FILE}"
# writeConfigKey "cmdline.mac1" "`cat /sys/class/net/${ETHX[0]}/address | sed 's/://g'`" "${USER_CONFIG_FILE}"
fi
for N in $(seq 1 ${#ETHX[@]}); do
MACR="$(cat /sys/class/net/${ETHX[$(expr ${N} - 1)]}/address | sed 's/://g')"
# Set custom MAC if defined
MACF="$(readConfigKey "cmdline.mac${N}" "${USER_CONFIG_FILE}")"
if [ -n "${MACF}" -a "${MACF}" != "${MACR}" ]; then
MAC="${MACF:0:2}:${MACF:2:2}:${MACF:4:2}:${MACF:6:2}:${MACF:8:2}:${MACF:10:2}"
echo "$(printf "$(TEXT "Setting %s MAC to %s")" "${ETHX[$(expr ${N} - 1)]}" "${MAC}")"
ip link set dev ${ETHX[$(expr ${N} - 1)]} address ${MAC} >/dev/null 2>&1 &&
(/etc/init.d/S41dhcpcd restart >/dev/null 2>&1 &) || true
for ETH in ${ETHX[@]}; do
MACR="$(cat /sys/class/net/${ETH}/address | sed 's/://g')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
if [ -n "${IPR}" ]; then
ip addr add ${IPC}/24 dev ${ETH}
sleep 1
fi
# Initialize with real MAC
writeConfigKey "original-mac${N}" "${MACR}" "${USER_CONFIG_FILE}"
# Enable Wake on Lan, ignore errors
ethtool -s ${ETHX[$(expr ${N} - 1)]} wol g 2>/dev/null
done
# Get the VID/PID if we are in USB
VID="0x0000"
PID="0x0000"
VID="0x46f4"
PID="0x0001"
BUS=$(udevadm info --query property --name ${LOADER_DISK} | grep ID_BUS | cut -d= -f2)
[ "${BUS}" = "ata" ] && BUS="sata"

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -29,13 +29,13 @@ KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")"
LKM="$(readConfigKey "lkm" "${USER_CONFIG_FILE}")"
DSMLOGO="$(readConfigKey "dsmlogo" "${USER_CONFIG_FILE}")"
DIRECTBOOT="$(readConfigKey "directboot" "${USER_CONFIG_FILE}")"
NOTSETMACS="$(readConfigKey "notsetmacs" "${USER_CONFIG_FILE}")"
PRERELEASE="$(readConfigKey "prerelease" "${USER_CONFIG_FILE}")"
BOOTWAIT="$(readConfigKey "bootwait" "${USER_CONFIG_FILE}")"
BOOTIPWAIT="$(readConfigKey "bootipwait" "${USER_CONFIG_FILE}")"
KERNELWAY="$(readConfigKey "kernelway" "${USER_CONFIG_FILE}")"
ODP="$(readConfigKey "odp" "${USER_CONFIG_FILE}")" # official drivers priorities
ODP="$(readConfigKey "odp" "${USER_CONFIG_FILE}")" # official drivers priorities
SN="$(readConfigKey "sn" "${USER_CONFIG_FILE}")"
MAC1="$(readConfigKey "mac1" "${USER_CONFIG_FILE}")"
###############################################################################
# Mounts backtitle dynamically
@ -151,6 +151,11 @@ function modelMenu() {
writeConfigKey "patsum" "" "${USER_CONFIG_FILE}"
SN=$(generateSerial "${MODEL}")
writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}"
NETIF_NUM=1
MACS=($(generateMacAddress "${MODEL}" ${NETIF_NUM}))
for I in $(seq 1 ${NETIF_NUM}); do
writeConfigKey "mac${I}" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}"
done
DIRTY=1
fi
}
@ -170,92 +175,95 @@ function productversMenu() {
if ! arrayExistItem "${1}" ${ITEMS}; then return; fi
resp="${1}"
fi
if [ "${PRODUCTVER}" != "${resp}" ]; then
local KVER=$(readModelKey "${MODEL}" "productvers.[${resp}].kver")
if [ -d "/sys/firmware/efi" -a "${KVER:0:1}" = "3" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--msgbox "$(TEXT "This version does not support UEFI startup, Please select another version or switch the startup mode.")" 0 0
return
fi
if [ ! "usb" = "$(udevadm info --query property --name ${LOADER_DISK} | grep ID_BUS | cut -d= -f2)" -a "${KVER:0:1}" = "5" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--msgbox "$(TEXT "This version only support usb startup, Please select another version or switch the startup mode.")" 0 0
# return
fi
while true; do
# get online pat data
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--infobox "$(TEXT "Get pat data ..")" 0 0
idx=0
while [ ${idx} -le 3 ]; do # Loop 3 times, if successful, break
fastest=$(_get_fastest "www.synology.com" "www.synology.cn")
[ "${fastest}" = "www.synology.cn" ] &&
fastest="https://www.synology.cn/api/support/findDownloadInfo?lang=zh-cn" ||
fastest="https://www.synology.com/api/support/findDownloadInfo?lang=en-us"
patdata=$(curl -skL "${fastest}&product=${MODEL/+/%2B}&major=${resp%%.*}&minor=${resp##*.}")
if [ "$(echo ${patdata} | jq -r '.success' 2>/dev/null)" = "true" ]; then
if echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].label_ext' 2>/dev/null | grep -q 'pat'; then
paturl=$(echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].url')
patsum=$(echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].checksum')
paturl=${paturl%%\?*}
break
fi
fi
idx=$((${idx} + 1))
done
if [ -z "${paturl}" -o -z "${patsum}" ]; then
MSG="$(TEXT "Failed to get pat data,\nPlease manually fill in the URL and md5sum of the corresponding version of pat.")"
paturl=""
patsum=""
else
MSG="$(TEXT "Successfully to get pat data,\nPlease confirm or modify as needed.")"
fi
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--extra-button --extra-label "$(TEXT "Retry")" \
--form "${MSG}" 10 110 2 "URL" 1 1 "${paturl}" 1 5 100 0 "MD5" 2 1 "${patsum}" 2 5 100 0 \
2>"${TMP_PATH}/resp"
RET=$?
[ ${RET} -eq 0 ] && break # ok-button
[ ${RET} -eq 3 ] && continue # extra-button
return # 1 or 255 # cancel-button or ESC
done
paturl="$(cat "${TMP_PATH}/resp" | tail -n +1 | head -1)"
patsum="$(cat "${TMP_PATH}/resp" | tail -n +2 | head -1)"
[ -z "${paturl}" -o -z "${patsum}" ] && return
writeConfigKey "paturl" "${paturl}" "${USER_CONFIG_FILE}"
writeConfigKey "patsum" "${patsum}" "${USER_CONFIG_FILE}"
PRODUCTVER=${resp}
writeConfigKey "productver" "${PRODUCTVER}" "${USER_CONFIG_FILE}"
BUILDNUM=""
SMALLNUM=""
writeConfigKey "buildnum" "${BUILDNUM}" "${USER_CONFIG_FILE}"
writeConfigKey "smallnum" "${SMALLNUM}" "${USER_CONFIG_FILE}"
if [ "${PRODUCTVER}" = "${resp}" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--infobox "$(TEXT "Reconfiguring Synoinfo, Addons and Modules")" 0 0
# Delete synoinfo and reload model/build synoinfo
writeConfigKey "synoinfo" "{}" "${USER_CONFIG_FILE}"
while IFS=': ' read KEY VALUE; do
writeConfigKey "synoinfo.${KEY}" "${VALUE}" "${USER_CONFIG_FILE}"
done < <(readModelMap "${MODEL}" "productvers.[${PRODUCTVER}].synoinfo")
# Check addons
PLATFORM="$(readModelKey "${MODEL}" "platform")"
KVER="$(readModelKey "${MODEL}" "productvers.[${PRODUCTVER}].kver")"
KPRE="$(readModelKey "${MODEL}" "productvers.[${PRODUCTVER}].kpre")"
while IFS=': ' read ADDON PARAM; do
[ -z "${ADDON}" ] && continue
if ! checkAddonExist "${ADDON}" "${PLATFORM}" "${KVER}"; then
deleteConfigKey "addons.${ADDON}" "${USER_CONFIG_FILE}"
fi
done < <(readConfigMap "addons" "${USER_CONFIG_FILE}")
# Rebuild modules
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
while read ID DESC; do
writeConfigKey "modules.${ID}" "" "${USER_CONFIG_FILE}"
done < <(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
# Remove old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
DIRTY=1
--yesno "$(printf "$(TEXT "The current version has been set to %s. Do you want to reset the version?")" "${PRODUCTVER}")" 0 0
[ $? -ne 0 ] && return
fi
local KVER=$(readModelKey "${MODEL}" "productvers.[${resp}].kver")
if [ -d "/sys/firmware/efi" -a "${KVER:0:1}" = "3" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--msgbox "$(TEXT "This version does not support UEFI startup, Please select another version or switch the startup mode.")" 0 0
return
fi
if [ ! "usb" = "$(udevadm info --query property --name ${LOADER_DISK} | grep ID_BUS | cut -d= -f2)" -a "${KVER:0:1}" = "5" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--msgbox "$(TEXT "This version only support usb startup, Please select another version or switch the startup mode.")" 0 0
# return
fi
while true; do
# get online pat data
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--infobox "$(TEXT "Get pat data ..")" 0 0
idx=0
while [ ${idx} -le 3 ]; do # Loop 3 times, if successful, break
fastest=$(_get_fastest "www.synology.com" "www.synology.cn")
[ "${fastest}" = "www.synology.cn" ] &&
fastest="https://www.synology.cn/api/support/findDownloadInfo?lang=zh-cn" ||
fastest="https://www.synology.com/api/support/findDownloadInfo?lang=en-us"
patdata=$(curl -skL "${fastest}&product=${MODEL/+/%2B}&major=${resp%%.*}&minor=${resp##*.}")
if [ "$(echo ${patdata} | jq -r '.success' 2>/dev/null)" = "true" ]; then
if echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].label_ext' 2>/dev/null | grep -q 'pat'; then
paturl=$(echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].url')
patsum=$(echo ${patdata} | jq -r '.info.system.detail[0].items[0].files[0].checksum')
paturl=${paturl%%\?*}
break
fi
fi
idx=$((${idx} + 1))
done
if [ -z "${paturl}" -o -z "${patsum}" ]; then
MSG="$(TEXT "Failed to get pat data,\nPlease manually fill in the URL and md5sum of the corresponding version of pat.")"
paturl=""
patsum=""
else
MSG="$(TEXT "Successfully to get pat data,\nPlease confirm or modify as needed.")"
fi
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--extra-button --extra-label "$(TEXT "Retry")" \
--form "${MSG}" 10 110 2 "URL" 1 1 "${paturl}" 1 5 100 0 "MD5" 2 1 "${patsum}" 2 5 100 0 \
2>"${TMP_PATH}/resp"
RET=$?
[ ${RET} -eq 0 ] && break # ok-button
[ ${RET} -eq 3 ] && continue # extra-button
return # 1 or 255 # cancel-button or ESC
done
paturl="$(cat "${TMP_PATH}/resp" | sed -n '1p')"
patsum="$(cat "${TMP_PATH}/resp" | sed -n '2p')"
[ -z "${paturl}" -o -z "${patsum}" ] && return
writeConfigKey "paturl" "${paturl}" "${USER_CONFIG_FILE}"
writeConfigKey "patsum" "${patsum}" "${USER_CONFIG_FILE}"
PRODUCTVER=${resp}
writeConfigKey "productver" "${PRODUCTVER}" "${USER_CONFIG_FILE}"
BUILDNUM=""
SMALLNUM=""
writeConfigKey "buildnum" "${BUILDNUM}" "${USER_CONFIG_FILE}"
writeConfigKey "smallnum" "${SMALLNUM}" "${USER_CONFIG_FILE}"
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Product Version")" \
--infobox "$(TEXT "Reconfiguring Synoinfo, Addons and Modules")" 0 0
# Delete synoinfo and reload model/build synoinfo
writeConfigKey "synoinfo" "{}" "${USER_CONFIG_FILE}"
while IFS=': ' read KEY VALUE; do
writeConfigKey "synoinfo.${KEY}" "${VALUE}" "${USER_CONFIG_FILE}"
done < <(readModelMap "${MODEL}" "productvers.[${PRODUCTVER}].synoinfo")
# Check addons
PLATFORM="$(readModelKey "${MODEL}" "platform")"
KVER="$(readModelKey "${MODEL}" "productvers.[${PRODUCTVER}].kver")"
KPRE="$(readModelKey "${MODEL}" "productvers.[${PRODUCTVER}].kpre")"
while IFS=': ' read ADDON PARAM; do
[ -z "${ADDON}" ] && continue
if ! checkAddonExist "${ADDON}" "${PLATFORM}" "${KVER}"; then
deleteConfigKey "addons.${ADDON}" "${USER_CONFIG_FILE}"
fi
done < <(readConfigMap "addons" "${USER_CONFIG_FILE}")
# Rebuild modules
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
while read ID DESC; do
writeConfigKey "modules.${ID}" "" "${USER_CONFIG_FILE}"
done < <(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
# Remove old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
DIRTY=1
}
###############################################################################
@ -542,9 +550,8 @@ function cmdlineMenu() {
echo "a \"$(TEXT "Add/edit a cmdline item")\"" >"${TMP_PATH}/menu"
echo "d \"$(TEXT "Delete cmdline item(s)")\"" >>"${TMP_PATH}/menu"
if [ -n "${MODEL}" ]; then
echo "s \"$(TEXT "Define a serial number")\"" >>"${TMP_PATH}/menu"
echo "s \"$(TEXT "Define SN/MAC")\"" >>"${TMP_PATH}/menu"
fi
echo "c \"$(TEXT "Define a custom MAC")\"" >>"${TMP_PATH}/menu"
echo "v \"$(TEXT "Show user added cmdline")\"" >>"${TMP_PATH}/menu"
echo "m \"$(TEXT "Show model inherent cmdline")\"" >>"${TMP_PATH}/menu"
echo "e \"$(TEXT "Exit")\"" >>"${TMP_PATH}/menu"
@ -592,66 +599,42 @@ function cmdlineMenu() {
done
;;
s)
MSG="$(TEXT "Note: (MAC will not be set to NIC)")"
sn="${SN}"
mac1="${MAC1}"
while true; do
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--inputbox "$(TEXT "Please enter a serial number ")" 0 0 "" \
2>${TMP_PATH}/resp
[ $? -ne 0 ] && break 2
SERIAL=$(cat ${TMP_PATH}/resp)
if [ -z "${SERIAL}" ]; then
return
elif [ $(validateSerial ${MODEL} ${SERIAL}) -eq 1 ]; then
--extra-button --extra-label "$(TEXT "Random")" \
--form "${MSG}" 10 110 2 "sn" 1 1 "${sn}" 1 5 100 0 "mac1" 2 1 "${mac1}" 2 5 100 0 \
2>"${TMP_PATH}/resp"
RET=$?
case ${RET} in
0) # ok-button
sn="$(cat "${TMP_PATH}/resp" | sed -n '1p')"
mac1="$(cat "${TMP_PATH}/resp" | sed -n '2p')"
if [ -z "${sn}" -o -z "${mac1}" ]; then
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--yesno "$(TEXT "Invalid SN/MAC, retry?")" 0 0
[ $? -eq 0 ] && break
fi
SN="${sn}"
writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}"
MAC1="${mac1}"
writeConfigKey "mac1" "${MAC1}" "${USER_CONFIG_FILE}"
break
fi
# At present, the SN rules are not complete, and many SNs are not truly invalid, so not provide tips now.
break
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--yesno "$(TEXT "Invalid serial, continue?")" 0 0
[ $? -eq 0 ] && break
done
SN="${SERIAL}"
writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}"
;;
c)
ETHX=($(ls /sys/class/net/ | grep eth)) # real network cards list
for N in $( # Currently, only up to 8 are supported. (<==> boot.sh L96, <==> lkm: MAX_NET_IFACES)
seq 1 8
); do
MACR="$(cat /sys/class/net/${ETHX[$(expr ${N} - 1)]}/address | sed 's/://g')"
MACF=${CMDLINE["mac${N}"]}
[ -n "${MACF}" ] && MAC=${MACF} || MAC=${MACR}
RET=1
while true; do
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--inputbox "$(printf "$(TEXT "Type a custom MAC address of %s")" "mac${N}")" 0 0 "${MAC}" \
2>${TMP_PATH}/resp
RET=$?
[ ${RET} -ne 0 ] && break 2
MAC="$(<"${TMP_PATH}/resp")"
[ -z "${MAC}" ] && MAC="$(readConfigKey "original-mac${i}" "${USER_CONFIG_FILE}")"
[ -z "${MAC}" ] && MAC="${MACFS[$(expr ${i} - 1)]}"
MACF="$(echo "${MAC}" | sed "s/:\|-\| //g")"
[ ${#MACF} -eq 12 ] && break
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--msgbox "$(TEXT "Invalid MAC")" 0 0
done
if [ ${RET} -eq 0 ]; then
CMDLINE["mac${N}"]="${MACF}"
CMDLINE["netif_num"]=${N}
writeConfigKey "cmdline.mac${N}" "${MACF}" "${USER_CONFIG_FILE}"
writeConfigKey "cmdline.netif_num" "${N}" "${USER_CONFIG_FILE}"
MAC="${MACF:0:2}:${MACF:2:2}:${MACF:4:2}:${MACF:6:2}:${MACF:8:2}:${MACF:10:2}"
ip link set dev ${ETHX[$(expr ${N} - 1)]} address "${MAC}" 2>&1 |
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--progressbox "$(TEXT "Changing MAC")" 20 70
/etc/init.d/S41dhcpcd restart 2>&1 |
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--progressbox "$(TEXT "Renewing IP")" 20 70
# IP=`ip route 2>/dev/null | sed -n 's/.* via .* dev \(.*\) src \(.*\) metric .*/\1: \2 /p' | head -1`
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Cmdline")" \
--yesno "$(TEXT "Continue to custom MAC?")" 0 0
[ $? -ne 0 ] && break
fi
;;
3) # extra-button
sn=$(generateSerial "${MODEL}")
MACS=($(generateMacAddress "${MODEL}" 1))
mac1=${MACS[0]}
;;
1) # cancel-button
break
;;
255) # ESC
break
;;
esac
done
;;
v)
@ -996,7 +979,7 @@ function advancedMenu() {
echo "k \"$(TEXT "kernel switching method:") \Z4${KERNELWAY}\Zn\"" >>"${TMP_PATH}/menu"
fi
fi
echo "m \"$(TEXT "Switch 'Do not set MACs':") \Z4${NOTSETMACS}\Zn\"" >>"${TMP_PATH}/menu"
echo "m \"$(TEXT "Set static IP")\"" >>"${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 "s \"$(TEXT "Show SATA(s) # ports and drives")\"" >>"${TMP_PATH}/menu"
@ -1064,8 +1047,44 @@ function advancedMenu() {
NEXT="e"
;;
m)
[ "${NOTSETMACS}" = "false" ] && NOTSETMACS='true' || NOTSETMACS='false'
writeConfigKey "notsetmacs" "${NOTSETMACS}" "${USER_CONFIG_FILE}"
MSG="$(TEXT "Temporary IP: (UI will not refresh)")"
ITEMS=""
IDX=0
ETHX=($(ls /sys/class/net/ | grep eth)) # real network cards list
for ETH in ${ETHX[@]}; do
[ ${IDX} -gt 7 ] && break # Currently, only up to 8 are supported. (<==> boot.sh L96, <==> lkm: MAX_NET_IFACES)
IDX=$((${IDX} + 1))
MACR="$(cat /sys/class/net/${ETH}/address | sed 's/://g')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
ITEMS+="${ETH}(${MACR}) ${IDX} 1 ${IPR:-\"\"} ${IDX} 22 20 16 "
done
echo ${ITEMS} >"${TMP_PATH}/opts"
dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Advanced")" \
--form "${MSG}" 10 44 ${IDX} --file "${TMP_PATH}/opts" \
2>"${TMP_PATH}/resp"
[ $? -ne 0 ] && continue
(
IDX=1
for ETH in ${ETHX[@]}; do
MACR="$(cat /sys/class/net/${ETH}/address | sed 's/://g')"
IPR="$(readConfigKey "network.${MACR}" "${USER_CONFIG_FILE}")"
IPC="$(cat "${TMP_PATH}/resp" | sed -n "${IDX}p")"
if [ -n "${IPC}" -a "${IPR}" != "${IPC}" ]; then
if ! echo "${IPC}" | grep -q "/"; then
IPC="${IPC}/24"
fi
ip addr add ${IPC} dev ${ETH}
writeConfigKey "network.${MACR}" "${IPC}" "${USER_CONFIG_FILE}"
sleep 1
elif [ -z "${IPC}" ]; then
deleteConfigKey "network.${MACR}" "${USER_CONFIG_FILE}"
fi
IDX=$((${IDX} + 1))
done
sleep 1
IP=$(ip route 2>/dev/null | sed -n 's/.* via .* dev \(.*\) src \(.*\) metric .*/\1: \2 /p' | head -1)
) | dialog --backtitle "$(backtitle)" --colors --title "$(TEXT "Advanced")" \
--progressbox "$(TEXT "Set IP..")" 20 70
NEXT="e"
;;
u)
@ -1135,8 +1154,8 @@ function advancedMenu() {
--form "${MSG}" 10 110 2 "URL" 1 1 "${PATURL}" 1 5 100 0 "MD5" 2 1 "${PATSUM}" 2 5 100 0 \
2>"${TMP_PATH}/resp"
[ $? -ne 0 ] && return
paturl="$(cat "${TMP_PATH}/resp" | tail -n +1 | head -1)"
patsum="$(cat "${TMP_PATH}/resp" | tail -n +2 | head -1)"
paturl="$(cat "${TMP_PATH}/resp" | sed -n '1p')"
patsum="$(cat "${TMP_PATH}/resp" | sed -n '2p')"
if [ ! ${paturl} = ${PATURL} ] || [ ! ${patsum} = ${PATSUM} ]; then
writeConfigKey "paturl" "${paturl}" "${USER_CONFIG_FILE}"
writeConfigKey "patsum" "${patsum}" "${USER_CONFIG_FILE}"

View File

@ -24,4 +24,13 @@ if loaderIsConfigured; then
fi
fi
# 23.9.7
deleteConfigKey "notsetmacs" "${USER_CONFIG_FILE}"
for N in $(1 8); do
deleteConfigKey "cmdline.mac${N}" "${USER_CONFIG_FILE}"
deleteConfigKey "original-mac${N}" "${USER_CONFIG_FILE}"
done
writeConfigKey "cmdline.netif_num" "1" "${USER_CONFIG_FILE}"
writeConfigKey "mac1" "001132$(printf '%02x%02x%02x' $((${RANDOM} % 256)) $((${RANDOM} % 256)) $((${RANDOM} % 256)))" "${USER_CONFIG_FILE}"
exit 0