From e1ebf309e90f41f44a6ff5a4ed56ecfcaf9236df Mon Sep 17 00:00:00 2001 From: Ing Date: Tue, 3 Dec 2024 07:10:40 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E9=85=8D=E7=BD=AE=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=90=88=E5=B9=B6=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issues.yml | 18 +++++++++++----- files/initrd/opt/rr/boot.sh | 2 +- files/initrd/opt/rr/include/configFile.sh | 16 ++++++++------ files/initrd/opt/rr/menu.sh | 26 ++++++++--------------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index db76a1ef..3a785800 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -149,6 +149,10 @@ jobs: # 累了, 毁灭吧! # yq need sudo !!! + function deleteConfigKey() { + sudo yq eval "del(.${1})" --inplace "${2}" 2>/dev/null + } + function writeConfigKey() { local value="${2}" [ "${value}" = "{}" ] && sudo yq eval ".${1} = {}" --inplace "${3}" 2>/dev/null || sudo yq eval ".${1} = \"${value}\"" --inplace "${3}" 2>/dev/null @@ -159,10 +163,15 @@ jobs: [ "${result}" = "null" ] && echo "" || echo "${result}" } - function mergeConfigStr() { + function mergeConfigModules() { + # Error: bad file '-': cannot index array with '8139cp' (strconv.ParseInt: parsing "8139cp": invalid syntax) + # When the first key is a pure number, yq will not process it as a string by default. The current solution is to insert a placeholder key. + local MS="RRORG\n${1// /\\n}" + local L="$(echo -en "${MS}" | awk '{print "modules."$1":"}')" local xmlfile=$(mktemp) - echo "${2}" | sudo yq -p "${1}" -o y >"${xmlfile}" - sudo yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${3}" "${xmlfile}" 2>/dev/null + echo -en "${L}" | sudo yq -p p -o y >"${xmlfile}" + deleteConfigKey "modules.\"RRORG\"" "${xmlfile}" + sudo yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${2}" "${xmlfile}" 2>/dev/null rm -f "${xmlfile}" } @@ -233,8 +242,7 @@ jobs: echo "set modules: ${{ env.modules }}" USER_CONFIG_FILE="rr/ws/mnt/p1/user-config.yml" writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(for I in $(echo "${{ env.modules }}" | sed 's/,/ /g'); do echo "modules.${I}:"; done)" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(echo "${{ env.modules }}" | sed 's/,/\n/g')" "${USER_CONFIG_FILE}" # for M in $(echo "${{ env.modules }}" | sed 's/,/ /g'); do # writeConfigKey "modules.\"${M}\"" "" "${USER_CONFIG_FILE}" # done diff --git a/files/initrd/opt/rr/boot.sh b/files/initrd/opt/rr/boot.sh index 8c963a9b..91efa72b 100755 --- a/files/initrd/opt/rr/boot.sh +++ b/files/initrd/opt/rr/boot.sh @@ -174,7 +174,7 @@ CMDLINE['log_buf_len']="32M" CMDLINE['rootwait']="" CMDLINE['panic']="${KERNELPANIC:-0}" # CMDLINE['nointremap']="" # no need -# CMDLINE['split_lock_detect']="off" # no need +# CMDLINE['split_lock_detect']="off" # check KVER CMDLINE['pcie_aspm']="off" # CMDLINE['intel_pstate']="disable" # CMDLINE['nox2apic']="" # check platform diff --git a/files/initrd/opt/rr/include/configFile.sh b/files/initrd/opt/rr/include/configFile.sh index c434b7db..7d577ba4 100755 --- a/files/initrd/opt/rr/include/configFile.sh +++ b/files/initrd/opt/rr/include/configFile.sh @@ -28,13 +28,17 @@ function readConfigKey() { ############################################################################### # Write to yaml config file -# 1 - format -# 2 - string -# 3 - Path of yaml config file -function mergeConfigStr() { +# 1 - Modules +# 2 - Path of yaml config file +function mergeConfigModules() { + # Error: bad file '-': cannot index array with '8139cp' (strconv.ParseInt: parsing "8139cp": invalid syntax) + # When the first key is a pure number, yq will not process it as a string by default. The current solution is to insert a placeholder key. + local MS="RRORG\n${1// /\\n}" + local L="$(echo -en "${MS}" | awk '{print "modules."$1":"}')" local xmlfile=$(mktemp) - echo "${2}" | yq -p "${1}" -o y >"${xmlfile}" - yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${3}" "${xmlfile}" 2>/dev/null + echo -en "${L}" | yq -p p -o y >"${xmlfile}" + deleteConfigKey "modules.\"RRORG\"" "${xmlfile}" + yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${2}" "${xmlfile}" 2>/dev/null rm -f "${xmlfile}" } diff --git a/files/initrd/opt/rr/menu.sh b/files/initrd/opt/rr/menu.sh index 6c675d56..219deee3 100755 --- a/files/initrd/opt/rr/menu.sh +++ b/files/initrd/opt/rr/menu.sh @@ -329,8 +329,7 @@ function productversMenu() { done <<<$(readConfigMap "addons" "${USER_CONFIG_FILE}") # Rewrite modules writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" # Remove old files rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null 2>&1 || true rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/"* >/dev/null 2>&1 || true @@ -409,8 +408,7 @@ function setConfigFromDSM() { done <<<$(readConfigMap "addons" "${USER_CONFIG_FILE}") # Rebuild modules writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" touch ${PART1_PATH}/.build return 0 } @@ -692,16 +690,14 @@ function moduleMenu() { 0) # ok-button writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(for I in $(cat ${TMP_PATH}/resp 2>/dev/null); do echo "modules.${I}:"; done)" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(cat "${TMP_PATH}/resp" 2>/dev/null)" "${USER_CONFIG_FILE}" touch ${PART1_PATH}/.build break ;; 3) # extra-button writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "${ALLMODULES}" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(echo "${ALLMODULES}" | awk '{print $1}')" "${USER_CONFIG_FILE}" touch ${PART1_PATH}/.build ;; 2) @@ -2141,7 +2137,7 @@ function tryRecoveryDSM() { --msgbox "$(TEXT "No DSM system partition(md0) found!\nPlease insert all disks before continuing.")" 0 0 return fi - + mkdir -p "${TMP_PATH}/mdX" fixDSMRootPart "${DSMROOTPART}" mount -t ext4 "${DSMROOTPART}" "${TMP_PATH}/mdX" @@ -3450,8 +3446,7 @@ function updateRR() { KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")" if [ -n "${PLATFORM}" ] && [ -n "${KVER}" ]; then writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" fi fi fi @@ -3588,8 +3583,7 @@ function updateModules() { KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")" if [ -n "${PLATFORM}" ] && [ -n "${KVER}" ]; then writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" fi fi rm -rf "${TMP_PATH}/update" @@ -3711,8 +3705,7 @@ function updateCKs() { KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")" if [ -n "${PLATFORM}" ] && [ -n "${KVER}" ]; then writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" fi fi rm -rf "${TMP_PATH}/update" @@ -4005,8 +3998,7 @@ else fi if [ -n "${PLATFORM}" ] && [ -n "${KVER}" ]; then writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}" - L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')" - mergeConfigStr p "${L}" "${USER_CONFIG_FILE}" + mergeConfigModules "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}" | awk '{print $1}')" "${USER_CONFIG_FILE}" fi touch ${PART1_PATH}/.build