Skip to content

Commit

Permalink
更新 boot.sh 和 menu.sh,添加 bootwait 配置功能,优化启动等待逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wjz304 committed Nov 6, 2024
1 parent 751284f commit 99de5d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
43 changes: 25 additions & 18 deletions files/initrd/opt/rr/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,28 @@ done
CMDLINE_LINE=$(echo "${CMDLINE_LINE}" | sed 's/^ //') # Remove leading space
echo -e "$(TEXT "Cmdline:\n")\033[1;36m${CMDLINE_LINE}\033[0m"

function _bootwait() {
BOOTWAIT="$(readConfigKey "bootwait" "${USER_CONFIG_FILE}")"
[ -z "${BOOTWAIT}" ] && BOOTWAIT=10
busybox w 2>/dev/null | awk '{print $1" "$2" "$4" "$5" "$6}' >WB
MSG=""
while test ${BOOTWAIT} -ge 0; do
MSG="$(printf "\033[1;33m$(TEXT "%2ds (Changing access(ssh/web) status will interrupt boot)")\033[0m" "${BOOTWAIT}")"
echo -en "\r${MSG}"
busybox w 2>/dev/null | awk '{print $1" "$2" "$4" "$5" "$6}' >WC
if ! diff WB WC >/dev/null 2>&1; then
echo -en "\r\033[1;33m$(TEXT "access(ssh/web) status has changed and booting is interrupted.")\033[0m\n"
rm -f WB WC
return 1
fi
sleep 1
BOOTWAIT=$((BOOTWAIT - 1))
done
rm -f WB WC
echo -en "\r$(printf "%$((${#MSG} * 2))s" " ")\n"
return 0
}

DIRECT="$(readConfigKey "directboot" "${USER_CONFIG_FILE}")"
if [ "${DIRECT}" = "true" ]; then
grub-editenv ${USER_GRUBENVFILE} set rr_version="$([ -z "${RR_RELEASE}" ] && echo "${RR_TITLE}" || echo "${RR_TITLE}(${RR_RELEASE})")"
Expand All @@ -227,6 +249,7 @@ if [ "${DIRECT}" = "true" ]; then
grub-editenv ${USER_GRUBENVFILE} set dsm_cmdline="${CMDLINE_DIRECT}"
grub-editenv ${USER_GRUBENVFILE} set next_entry="direct"

_bootwait || exit 0
echo -e "\033[1;33m$(TEXT "Reboot to boot directly in DSM")\033[0m"
reboot
exit 0
Expand Down Expand Up @@ -297,25 +320,9 @@ else
sleep 1
done
done
BOOTWAIT="$(readConfigKey "bootwait" "${USER_CONFIG_FILE}")"
[ -z "${BOOTWAIT}" ] && BOOTWAIT=10
busybox w 2>/dev/null | awk '{print $1" "$2" "$4" "$5" "$6}' >WB
MSG=""
while test ${BOOTWAIT} -ge 0; do
MSG="$(printf "\033[1;33m$(TEXT "%2ds (Changing access(ssh/web) status will interrupt boot)")\033[0m" "${BOOTWAIT}")"
echo -en "\r${MSG}"
busybox w 2>/dev/null | awk '{print $1" "$2" "$4" "$5" "$6}' >WC
if ! diff WB WC >/dev/null 2>&1; then
echo -en "\r\033[1;33m$(TEXT "access(ssh/web) status has changed and booting is interrupted.")\033[0m\n"
rm -f WB WC
exit 0
fi
sleep 1
BOOTWAIT=$((BOOTWAIT - 1))
done
rm -f WB WC
echo -en "\r$(printf "%$((${#MSG} * 2))s" " ")\n"

_bootwait || exit 0

echo -e "\033[1;37m$(TEXT "Loading DSM kernel ...")\033[0m"

DSMLOGO="$(readConfigKey "dsmlogo" "${USER_CONFIG_FILE}")"
Expand Down
22 changes: 11 additions & 11 deletions files/initrd/opt/rr/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2748,9 +2748,9 @@ function advancedMenu() {
if [ -n "${PLATFORM}" ] && [ "true" = "$(readConfigKey "platforms.${PLATFORM}.dt" "${WORK_PATH}/platforms.yml")" ]; then
echo "d \"$(TEXT "Custom DTS")\"" >>"${TMP_PATH}/menu"
fi
echo "w \"$(TEXT "Timeout of boot wait:") \Z4${BOOTWAIT}\Zn\"" >>"${TMP_PATH}/menu"
if [ "${DIRECTBOOT}" = "false" ]; then
echo "i \"$(TEXT "Timeout of get ip in boot:") \Z4${BOOTIPWAIT}\Zn\"" >>"${TMP_PATH}/menu"
echo "w \"$(TEXT "Timeout of boot wait:") \Z4${BOOTWAIT}\Zn\"" >>"${TMP_PATH}/menu"
echo "k \"$(TEXT "kernel switching method:") \Z4${KERNELWAY}\Zn\"" >>"${TMP_PATH}/menu"
fi
echo "n \"$(TEXT "Reboot on kernel panic:") \Z4${KERNELPANIC}\Zn\"" >>"${TMP_PATH}/menu"
Expand Down Expand Up @@ -2831,29 +2831,29 @@ function advancedMenu() {
customDTS
NEXT="e"
;;
i)
w)
ITEMS="$(echo -e "1 \n5 \n10 \n30 \n60 \n")"
DIALOG --title "$(TEXT "Advanced")" \
--default-item "${BOOTIPWAIT}" --no-items --menu "$(TEXT "Choose a time(seconds)")" 0 0 0 ${ITEMS} \
--default-item "${BOOTWAIT}" --no-items --menu "$(TEXT "Choose a time(seconds)")" 0 0 0 ${ITEMS} \
2>${TMP_PATH}/resp
[ $? -ne 0 ] && continue
resp=$(cat ${TMP_PATH}/resp 2>/dev/null)
[ -z "${resp}" ] && continue
BOOTIPWAIT=${resp}
writeConfigKey "bootipwait" "${BOOTIPWAIT}" "${USER_CONFIG_FILE}"
NEXT="i"
BOOTWAIT=${resp}
writeConfigKey "bootwait" "${BOOTWAIT}" "${USER_CONFIG_FILE}"
NEXT="w"
;;
w)
i)
ITEMS="$(echo -e "1 \n5 \n10 \n30 \n60 \n")"
DIALOG --title "$(TEXT "Advanced")" \
--default-item "${BOOTWAIT}" --no-items --menu "$(TEXT "Choose a time(seconds)")" 0 0 0 ${ITEMS} \
--default-item "${BOOTIPWAIT}" --no-items --menu "$(TEXT "Choose a time(seconds)")" 0 0 0 ${ITEMS} \
2>${TMP_PATH}/resp
[ $? -ne 0 ] && continue
resp=$(cat ${TMP_PATH}/resp 2>/dev/null)
[ -z "${resp}" ] && continue
BOOTWAIT=${resp}
writeConfigKey "bootwait" "${BOOTWAIT}" "${USER_CONFIG_FILE}"
NEXT="w"
BOOTIPWAIT=${resp}
writeConfigKey "bootipwait" "${BOOTIPWAIT}" "${USER_CONFIG_FILE}"
NEXT="i"
;;
k)
[ "${KERNELWAY}" = "kexec" ] && KERNELWAY='power' || KERNELWAY='kexec'
Expand Down

0 comments on commit 99de5d8

Please sign in to comment.