mirror of
https://github.com/RROrg/rr.git
synced 2025-06-21 05:51:05 +08:00
chore: Merge config strings in multiple functions to improve code readability and maintainability
This commit is contained in:
parent
8931af4fe3
commit
6898e5b2fa
31
.github/workflows/issues.yml
vendored
31
.github/workflows/issues.yml
vendored
@ -157,6 +157,13 @@ jobs:
|
||||
[ "${RESULT}" == "null" ] && echo "" || echo "${RESULT}"
|
||||
}
|
||||
|
||||
function mergeConfigStr() {
|
||||
local JF=$(mktemp)
|
||||
echo "${2}" | yq -p ${1} -o y > "${JF}"
|
||||
yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${3}" "${JF}" 2>/dev/null
|
||||
rm -f "${JF}"
|
||||
}
|
||||
|
||||
REPO="${{ github.server_url }}/${{ github.repository }}"
|
||||
MODEL="${{ env.model }}"
|
||||
VERSION="${{ env.version }}"
|
||||
@ -200,10 +207,9 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ -n "${{ env.kernel }}" ]; then
|
||||
echo -en "set kernel"
|
||||
echo "set kernel"
|
||||
USER_CONFIG_FILE="rr/ws/mnt/p1/user-config.yml"
|
||||
writeConfigKey "kernel" "${{ env.kernel }}" "${USER_CONFIG_FILE}"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
sudo ./localbuild.sh config "${MODEL}" "${VERSION}"
|
||||
@ -213,29 +219,20 @@ jobs:
|
||||
fi
|
||||
|
||||
if [ -n "${{ env.addons }}" ]; then
|
||||
echo -en "set addons"
|
||||
echo "set addons: ${{ env.addons }}"
|
||||
USER_CONFIG_FILE="rr/ws/mnt/p1/user-config.yml"
|
||||
writeConfigKey "addons" "{}" "${USER_CONFIG_FILE}"
|
||||
echo -en ': '
|
||||
for A in $(echo "${{ env.addons }}" | tr ',' ' '); do
|
||||
echo -en "${A} "
|
||||
VALUE=""
|
||||
writeConfigKey "addons.\"${A}\"" "${VALUE}" "${USER_CONFIG_FILE}"
|
||||
for A in $(echo "${{ env.addons }}" | sed 's/,/ /g'); do
|
||||
writeConfigKey "addons.\"${A}\"" "" "${USER_CONFIG_FILE}"
|
||||
done
|
||||
echo ""
|
||||
fi
|
||||
|
||||
if [ ! "custom" = "${{ env.kernel }}" ] && [ -n "${{ env.modules }}" ]; then
|
||||
echo -en "set modules"
|
||||
echo "set modules: ${{ env.modules }}"
|
||||
USER_CONFIG_FILE="rr/ws/mnt/p1/user-config.yml"
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
echo -en ': '
|
||||
for M in $(echo "${{ env.modules }}" | tr ',' ' '); do
|
||||
echo -en "${M} "
|
||||
VALUE=""
|
||||
writeConfigKey "modules.\"${M}\"" "${VALUE}" "${USER_CONFIG_FILE}"
|
||||
done
|
||||
echo ""
|
||||
L="$(for I in $(echo "${{ env.modules }}" | sed 's/,/ /g'); do echo "modules.${I}:"; done)"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
fi
|
||||
|
||||
sudo ./localbuild.sh build
|
||||
|
@ -25,6 +25,17 @@ function readConfigKey() {
|
||||
[ "${RESULT}" == "null" ] && echo "" || echo "${RESULT}"
|
||||
}
|
||||
|
||||
# Write to yaml config file
|
||||
# 1 - format
|
||||
# 2 - string
|
||||
# 3 - Path of yaml config file
|
||||
function mergeConfigStr() {
|
||||
local JF=$(mktemp)
|
||||
echo "${2}" | yq -p ${1} -o y > "${JF}"
|
||||
yq eval-all --inplace '. as $item ireduce ({}; . * $item)' --inplace "${3}" "${JF}" 2>/dev/null
|
||||
rm -f "${JF}"
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Write to yaml config file if key not exists
|
||||
# 1 - Path of Key
|
||||
|
@ -346,9 +346,8 @@ function productversMenu() {
|
||||
done <<<$(readConfigMap "addons" "${USER_CONFIG_FILE}")
|
||||
# Rewrite 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}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${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
|
||||
@ -424,9 +423,8 @@ function setConfigFromDSM() {
|
||||
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}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
touch ${PART1_PATH}/.build
|
||||
return 0
|
||||
}
|
||||
@ -702,19 +700,16 @@ function moduleMenu() {
|
||||
RET=$?
|
||||
case ${RET} in
|
||||
0) # ok-button
|
||||
resp=$(cat ${TMP_PATH}/resp)
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
for ID in ${resp}; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done
|
||||
L="$(for I in $(cat ${TMP_PATH}/resp 2>/dev/null); do echo "modules.${I}:"; done)"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
touch ${PART1_PATH}/.build
|
||||
break
|
||||
;;
|
||||
3) # extra-button
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
while read ID DESC; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done <<<${ALLMODULES}
|
||||
L="$(echo "${ALLMODULES}" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
touch ${PART1_PATH}/.build
|
||||
;;
|
||||
2) # help-button
|
||||
@ -3012,9 +3007,8 @@ function updateRR() {
|
||||
KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")"
|
||||
if [ -n "${PLATFORM}" -a -n "${KVER}" ]; then
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
while read ID DESC; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done <<<$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@ -3149,9 +3143,8 @@ function updateModules() {
|
||||
KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")"
|
||||
if [ -n "${PLATFORM}" -a -n "${KVER}" ]; then
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
while read ID DESC; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done <<<$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
fi
|
||||
fi
|
||||
rm -rf "${TMP_PATH}/update"
|
||||
@ -3271,9 +3264,8 @@ function updateCKs() {
|
||||
KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")"
|
||||
if [ -n "${PLATFORM}" -a -n "${KVER}" ]; then
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
while read ID DESC; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done <<<$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
fi
|
||||
fi
|
||||
rm -rf "${TMP_PATH}/update"
|
||||
@ -3552,9 +3544,8 @@ else
|
||||
fi
|
||||
if [ -n "${PLATFORM}" -a -n "${KVER}" ]; then
|
||||
writeConfigKey "modules" "{}" "${USER_CONFIG_FILE}"
|
||||
while read ID DESC; do
|
||||
writeConfigKey "modules.\"${ID}\"" "" "${USER_CONFIG_FILE}"
|
||||
done <<<$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")
|
||||
L="$(echo "$(getAllModules "${PLATFORM}" "$([ -n "${KPRE}" ] && echo "${KPRE}-")${KVER}")" | awk '{print "modules."$1":"}')"
|
||||
mergeConfigStr p "${L}" "${USER_CONFIG_FILE}"
|
||||
fi
|
||||
touch ${PART1_PATH}/.build
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user