Skip to content

Commit

Permalink
优化脚本,修复条件判断,增强代码可读性和执行效率
Browse files Browse the repository at this point in the history
  • Loading branch information
wjz304 committed Nov 23, 2024
1 parent 0605583 commit 90bce4a
Show file tree
Hide file tree
Showing 25 changed files with 6,377 additions and 6,254 deletions.
32 changes: 29 additions & 3 deletions files/initrd/opt/rr/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rm -rf "${PART1_PATH}/logs" /sys/fs/pstore/* >/dev/null 2>&1 || true

# Check if machine has EFI
EFI=$([ -d /sys/firmware/efi ] && echo 1 || echo 0)

FBI=$(cat /sys/class/graphics/fb*/name 2>/dev/null | head -1)
BUS=$(getBus "${LOADER_DISK}")

# Print text centralized
Expand Down Expand Up @@ -167,13 +167,31 @@ CMDLINE['console']="ttyS0,115200n8"
CMDLINE['consoleblank']="600"
# CMDLINE['no_console_suspend']="1"
CMDLINE['root']="/dev/md0"
CMDLINE['rootwait']=""
CMDLINE['loglevel']="15"
CMDLINE['log_buf_len']="32M"
CMDLINE['rootwait']=""
CMDLINE['panic']="${KERNELPANIC:-0}"
# CMDLINE['nointremap']="" # no need
# CMDLINE['split_lock_detect']="off" # no need
CMDLINE['pcie_aspm']="off"
# CMDLINE['intel_pstate']="disable"
# CMDLINE['nox2apic']="" # check platform
# CMDLINE['nomodeset']=""
CMDLINE['modprobe.blacklist']="${MODBLACKLIST}"

if echo "apollolake geminilake purley" | grep -wq "${PLATFORM}"; then
CMDLINE["nox2apic"]=""
fi

# # Save command line to grubenv RR_CMDLINE= ... nox2apic
# if echo "apollolake geminilake purley" | grep -wq "${PLATFORM}"; then
# if grep -q "^flags.*x2apic.*" /proc/cpuinfo; then
# checkCmdline "rr_cmdline" "nox2apic" || addCmdline "rr_cmdline" "nox2apic"
# fi
# else
# checkCmdline "rr_cmdline" "nox2apic" && delCmdline "rr_cmdline" "nox2apic"
# fi

# if [ -n "$(ls /dev/mmcblk* 2>/dev/null)" ] && [ ! "${BUS}" = "mmc" ] && [ ! "${EMMCBOOT}" = "true" ]; then
# if ! echo "${CMDLINE['modprobe.blacklist']}" | grep -q "sdhci"; then
# [ ! "${CMDLINE['modprobe.blacklist']}" = "" ] && CMDLINE['modprobe.blacklist']+=","
Expand Down Expand Up @@ -217,6 +235,8 @@ for KEY in "${!CMDLINE[@]}"; do
done
CMDLINE_LINE=$(echo "${CMDLINE_LINE}" | sed 's/^ //') # Remove leading space
printf "%s:\n \033[1;36m%s\033[0m\n" "$(TEXT "Cmdline")" "${CMDLINE_LINE}"

# Check if user wants to modify at this stage
function _bootwait() {
BOOTWAIT="$(readConfigKey "bootwait" "${USER_CONFIG_FILE}")"
[ -z "${BOOTWAIT}" ] && BOOTWAIT=10
Expand Down Expand Up @@ -355,13 +375,19 @@ else
# show warning message
for T in $(busybox w 2>/dev/null | grep -v 'TTY' | awk '{print $2}'); do
if [ -w "/dev/${T}" ]; then
echo -e "\n\033[1;43m$(TEXT "Interface not operational. Wait a few minutes.\nFind DSM via http://find.synology.com/ or Synology Assistant.")\033[0m\n" > "/dev/${T}" 2>/dev/null || true
echo -e "\n\033[1;43m$(TEXT "Interface not operational. Wait a few minutes.\nFind DSM via http://find.synology.com/ or Synology Assistant.")\033[0m\n" >"/dev/${T}" 2>/dev/null || true
fi
done

# # Unload all network interfaces
# for D in $(readlink /sys/class/net/*/device/driver); do rmmod -f "$(basename ${D})" 2>/dev/null || true; done

# Unload all graphics drivers
# for D in $(lsmod | grep -E '^(nouveau|amdgpu|radeon|i915)' | awk '{print $1}'); do rmmod -f "${D}" 2>/dev/null || true; done
# for I in $(find /sys/devices -name uevent -exec bash -c 'cat {} 2>/dev/null | grep -Eq "PCI_CLASS=0?30[0|1|2]00" && dirname {}' \;); do
# [ -e ${I}/reset ] && cat ${I}/vendor >/dev/null | grep -iq 0x10de && echo 1 >${I}/reset || true # Proc open nvidia driver when booting
# done

# Reboot
KERNELWAY="$(readConfigKey "kernelway" "${USER_CONFIG_FILE}")"
[ "${KERNELWAY}" = "kexec" ] && kexec -e || poweroff
Expand Down
13 changes: 6 additions & 7 deletions files/initrd/opt/rr/include/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function _get_fastest() {
local speedlist=""
if command -v ping >/dev/null 2>&1; then
for I in "$@"; do
speed=$(ping -c 1 -W 5 "${I}" 2>/dev/null | awk -F'[= ]' '/time=/ {for(i=1;i<=NF;i++) if ($i=="time") print $(i+1)}')
speed=$(LC_ALL=C ping -c 1 -W 5 "${I}" 2>/dev/null | awk -F'[= ]' '/time=/ {for(i=1;i<=NF;i++) if ($i=="time") print $(i+1)}')
speedlist+="${I} ${speed:-999}\n" # Assign default value 999 if speed is empty
done
else
Expand All @@ -215,10 +215,10 @@ function _get_fastest() {
speedlist+="${I} ${speed:-999}\n" # Assign default value 999 if speed is empty
done
fi
local fastest="$(echo -e "${speedlist}" | tr -s '\n' | sort -k2n | head -1)"
local fastest="$(echo -e "${speedlist}" | tr -s '\n' | grep -v '999$' | sort -k2n | head -1)"
URL="$(echo "${fastest}" | awk '{print $1}')"
SPD="$(echo "${fastest}" | awk '{print $2}')" # It is a float type
echo "${URL}"
echo "${URL:-${1}}"
[ $(echo "${SPD:-999}" | cut -d. -f1) -ge 999 ] && return 1 || return 0
}

Expand Down Expand Up @@ -301,10 +301,9 @@ function getIP() {
function getLogo() {
local MODEL="${1}"
rm -f "${PART3_PATH}/logo.png"
local fastest="www.synology.com" # $(_get_fastest "www.synology.com" "www.synology.cn")
if [ $? -ne 0 ]; then
return 1
fi
local fastest="$(_get_fastest "www.synology.com" "www.synology.cn")"
# [ $? -ne 0 ] && return 1

local STATUS=$(curl -skL --connect-timeout 10 -w "%{http_code}" "https://${fastest}/api/products/getPhoto?product=${MODEL/+/%2B}&type=img_s&sort=0" -o "${PART3_PATH}/logo.png")
if [ $? -ne 0 ] || [ "${STATUS:-0}" -ne 200 ] || [ ! -f "${PART3_PATH}/logo.png" ]; then
rm -f "${PART3_PATH}/logo.png"
Expand Down
2 changes: 1 addition & 1 deletion files/initrd/opt/rr/include/modules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function installModules() {
local ODP="$(readConfigKey "odp" "${USER_CONFIG_FILE}")"
for F in $(ls "${TMP_PATH}/modules/"*.ko 2>/dev/null); do
local M=$(basename "${F}")
[ "${ODP}" == "true" ] && [ -f "${RAMDISK_PATH}/usr/lib/modules/${M}" ] && continue
[ "${ODP}" = "true" ] && [ -f "${RAMDISK_PATH}/usr/lib/modules/${M}" ] && continue
if echo "${MLIST}" | grep -wq "${M:0:-3}"; then
cp -f "${F}" "${RAMDISK_PATH}/usr/lib/modules/${M}" 2>"${LOG_FILE}"
else
Expand Down
Loading

0 comments on commit 90bce4a

Please sign in to comment.