2024-05-05 06:16:56 +07:00
|
|
|
#!/usr/bin/env ash
|
|
|
|
#
|
|
|
|
# Copyright (C) 2023 AuxXxilium <https://github.com/AuxXxilium> and Ing <https://github.com/wjz304>
|
|
|
|
#
|
|
|
|
# This is free software, licensed under the MIT License.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
2024-06-29 00:27:16 +07:00
|
|
|
# Get values in synoinfo.conf K=V file
|
|
|
|
# 1 - key
|
|
|
|
function _get_conf_kv() {
|
|
|
|
grep "${1}=" /etc/synoinfo.conf 2>/dev/null | sed "s|^${1}=\"\(.*\)\"$|\1|g"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Replace/add values in synoinfo.conf K=V file
|
|
|
|
# Args: $1 rd|hd, $2 key, $3 val
|
|
|
|
function _set_conf_kv() {
|
|
|
|
local ROOT
|
|
|
|
local FILE
|
|
|
|
[ "$1" = "rd" ] && ROOT="" || ROOT="/tmpRoot"
|
|
|
|
for SD in etc etc.defaults; do
|
|
|
|
FILE="${ROOT}/${SD}/synoinfo.conf"
|
|
|
|
# Replace
|
|
|
|
if grep -q "^$2=" ${FILE}; then
|
|
|
|
sed -i ${FILE} -e "s\"^$2=.*\"$2=\\\"$3\\\"\""
|
|
|
|
else
|
|
|
|
# Add if doesn't exist
|
|
|
|
echo "$2=\"$3\"" >>${FILE}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2024-05-05 06:16:56 +07:00
|
|
|
if [ "${1}" = "patches" ]; then
|
|
|
|
echo "Installing addon sortnetif - ${1}"
|
|
|
|
|
|
|
|
ETHLIST=""
|
2024-05-19 21:50:55 +07:00
|
|
|
ETHX="$(ls /sys/class/net/ 2>/dev/null | grep eth)" # real network cards list
|
2024-05-05 06:16:56 +07:00
|
|
|
for ETH in ${ETHX}; do
|
|
|
|
MAC="$(cat /sys/class/net/${ETH}/address 2>/dev/null | sed 's/://g' | tr '[:upper:]' '[:lower:]')"
|
2024-05-19 21:50:55 +07:00
|
|
|
BUS="$(ethtool -i ${ETH} 2>/dev/null | grep bus-info | cut -d' ' -f2)"
|
2024-05-05 06:16:56 +07:00
|
|
|
ETHLIST="${ETHLIST}${BUS} ${MAC} ${ETH}\n"
|
|
|
|
done
|
2024-06-29 00:27:16 +07:00
|
|
|
ETHLISTTMPM=""
|
|
|
|
ETHLISTTMPB="$(echo -e "${ETHLIST}" | sort)"
|
2024-05-05 06:16:56 +07:00
|
|
|
if [ -n "${2}" ]; then
|
2024-05-19 21:50:55 +07:00
|
|
|
MACS="$(echo "${2}" | sed 's/://g' | tr '[:upper:]' '[:lower:]' | tr ',' ' ')"
|
2024-05-05 06:16:56 +07:00
|
|
|
for MACX in ${MACS}; do
|
2024-06-29 00:27:16 +07:00
|
|
|
ETHLISTTMPM="${ETHLISTTMPM}$(echo -e "${ETHLISTTMPB}" | grep "${MACX}")\n"
|
|
|
|
ETHLISTTMPB="$(echo -e "${ETHLISTTMPB}" | grep -v "${MACX}")\n"
|
2024-05-05 06:16:56 +07:00
|
|
|
done
|
2024-06-29 00:27:16 +07:00
|
|
|
fi
|
|
|
|
ETHLIST="$(echo -e "${ETHLISTTMPM}${ETHLISTTMPB}" | grep -v '^$')"
|
|
|
|
ETHSEQ="$(echo -e "${ETHLIST}" | awk '{print $3}' | sed 's/eth//g' | tr '\n' ' ')"
|
|
|
|
ETHNUM="$(echo -e "${ETHLIST}" | wc -l)"
|
|
|
|
|
|
|
|
_set_conf_kv rd netif_seq "${ETHSEQ}"
|
2024-05-05 06:16:56 +07:00
|
|
|
|
2024-06-29 00:27:16 +07:00
|
|
|
if [ -x /usr/syno/bin/synonetseqadj ]; then
|
|
|
|
/usr/syno/bin/synonetseqadj
|
2024-05-05 06:16:56 +07:00
|
|
|
else
|
2024-06-29 00:27:16 +07:00
|
|
|
echo "sortnetif error: synonetseqadj not found!"
|
2024-05-05 06:16:56 +07:00
|
|
|
fi
|
|
|
|
|
2024-06-29 00:27:16 +07:00
|
|
|
elif [ "${1}" = "late" ]; then
|
|
|
|
echo "Installing addon sortnetif - ${1}"
|
2024-05-05 06:16:56 +07:00
|
|
|
|
2024-06-29 00:27:16 +07:00
|
|
|
ETHSEQ="$(_get_conf_kv netif_seq)"
|
|
|
|
_set_conf_kv hd netif_seq "${ETHSEQ}"
|
|
|
|
fi
|