Skip to content

Commit

Permalink
更新工作流配置,优化标签提取逻辑,修复脚本中的命令替换方式
Browse files Browse the repository at this point in the history
  • Loading branch information
wjz304 committed Dec 11, 2024
1 parent c41ba55 commit 94133a3
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
TAG=""
if [ "${PRERELEASE}" = "true" ]; then
TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep /refs/tags/.*\.zip | sed -r 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep /refs/tags/.*\.zip | sed -E 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
else
LATESTURL="$(curl -skL --connect-timeout 10 -w %{url_effective} -o /dev/null "${REPO}/releases/latest")"
TAG="${LATESTURL##*/}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
TAG=""
if [ "${PRERELEASE}" = "true" ]; then
TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep /refs/tags/.*\.zip | sed -r 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep /refs/tags/.*\.zip | sed -E 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
else
LATESTURL="$(curl -skL --connect-timeout 10 -w %{url_effective} -o /dev/null "${REPO}/releases/latest")"
TAG="${LATESTURL##*/}"
Expand Down
Binary file modified files/initrd/opt/rr/kpatch
Binary file not shown.
64 changes: 37 additions & 27 deletions files/initrd/opt/rr/menu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ flock -n 304 || {
dialog --colors --aspect 50 --title "$(TEXT "Error")" --msgbox "${MSG}" 0 0
exit 1
}
trap 'rm -f $LOCKFILE' EXIT
trap 'rm -f $LOCKFILE; exit' INT TERM HUP
trap 'flock -u 304; rm -f "${WORK_PATH}/menu.lock"' EXIT INT TERM HUP

# Check partition 3 space, if < 2GiB is necessary clean cache folder
SPACELEFT=$(df -m ${PART3_PATH} 2>/dev/null | awk 'NR==2 {print $4}')
Expand Down Expand Up @@ -1338,16 +1337,15 @@ function make() {
extractDsmFiles || return 1
fi

while true; do
SIZE=256 # initrd-dsm + zImage-dsm ≈ 210M
SPACELEFT=$(df -m ${PART3_PATH} 2>/dev/null | awk 'NR==2 {print $4}')
ZIMAGESIZE=$(du -m ${MOD_ZIMAGE_FILE} 2>/dev/null | awk '{print $1}')
RDGZSIZE=$(du -m ${MOD_RDGZ_FILE} 2>/dev/null | awk '{print $1}')
SPACEALL=$((${SPACELEFT:-0} + ${ZIMAGESIZE:-0} + ${RDGZSIZE:-0}))
[ ${SPACEALL:-0} -ge ${SIZE} ] && break
SIZE=256 # initrd-dsm + zImage-dsm ≈ 210M
SPACELEFT=$(df -m ${PART3_PATH} 2>/dev/null | awk 'NR==2 {print $4}')
ZIMAGESIZE=$(du -m ${MOD_ZIMAGE_FILE} 2>/dev/null | awk '{print $1}')
RDGZSIZE=$(du -m ${MOD_RDGZ_FILE} 2>/dev/null | awk '{print $1}')
SPACEALL=$((${SPACELEFT:-0} + ${ZIMAGESIZE:-0} + ${RDGZSIZE:-0}))
if [ ${SPACEALL:-0} -lt ${SIZE} ]; then
echo -e "$(TEXT "No disk space left, please clean the cache and try again!")" >"${LOG_FILE}"
return 1
done
fi

${WORK_PATH}/zimage-patch.sh || {
printf "%s\n%s\n%s:\n%s\n" "$(TEXT "DSM zImage not patched")" "$(TEXT "Please upgrade the bootloader version and try again.")" "$(TEXT "Error")" "$(cat "${LOG_FILE}")" >"${LOG_FILE}"
Expand Down Expand Up @@ -2032,7 +2030,7 @@ function languageMenu() {
while read -r L; do
A="$(echo "$(strings "${WORK_PATH}/lang/${L}/LC_MESSAGES/rr.mo" 2>/dev/null | grep "Last-Translator" | sed "s/Last-Translator://")")"
echo "${L} \"${A:-"anonymous"}\"" >>"${TMP_PATH}/menu"
done <<<$(ls ${WORK_PATH}/lang/*/LC_MESSAGES/rr.mo 2>/dev/null | sort | sed -r 's/.*\/lang\/(.*)\/LC_MESSAGES\/rr\.mo$/\1/')
done <<<$(ls ${WORK_PATH}/lang/*/LC_MESSAGES/rr.mo 2>/dev/null | sort | sed -E 's/.*\/lang\/(.*)\/LC_MESSAGES\/rr\.mo$/\1/')

DIALOG --title "$(TEXT "Settings")" \
--default-item "${LAYOUT}" --menu "$(TEXT "Choose a language")" 0 0 20 --file "${TMP_PATH}/menu" \
Expand Down Expand Up @@ -2268,11 +2266,18 @@ function cloneBootloaderDisk() {
ENDSECTOR=$(($(fdisk -l ${RESP} | grep "${NEW_BLDISK_P3}" | awk '{print $3}') + 1))

if [ ${SIZEOFDISK}0 -ne ${ENDSECTOR}0 ]; then
echo -e "\033[1;36mResizing ${NEW_BLDISK_P3}\033[0m"
echo -e "d\n\nn\n\n\n\n\nn\nw" | fdisk "${RESP}" >/dev/null 2>&1
resize2fs "${NEW_BLDISK_P3}"
fdisk -l "${RESP}"
sleep 1
if [ -f "/mnt/p1/.noresize" ] || [ ${SIZEOFDISK:-0} -gt $((32 * 1024 * 1024 * 2)) ]; then
# Create partition 4 with remaining space
echo -e "\033[1;36mCreating partition 4 with remaining space.\033[0m"
echo -e "n\n\n\n\n\nw" | fdisk "${RESP}" >/dev/null 2>&1
PART4="${RESP}4"
mkfs.ext4 -F "${PART4}" # mkfs.ext4 -F -L "RR4" "${PART4}"
else
echo -e "\033[1;36mResizing ${NEW_BLDISK_P3}\033[0m"
echo -e "d\n\nn\n\n\n\n\nn\nw" | fdisk "${RESP}" >/dev/null 2>&1
resize2fs "${NEW_BLDISK_P3}"
fdisk -l "${RESP}"
fi
fi

function __umountNewBlDisk() {
Expand Down Expand Up @@ -2745,9 +2750,12 @@ function changePassword() {
# Change ports of TTYD/DUFS/HTTP
function changePorts() {
local MSG="$(TEXT "Please fill in a number between 0-65535: (Empty for default value.)")"
local HTTP=$(grep -i '^HTTP_PORT=' /etc/rrorg.conf 2>/dev/null | cut -d'=' -f2)
local DUFS=$(grep -i '^DUFS_PORT=' /etc/rrorg.conf 2>/dev/null | cut -d'=' -f2)
local TTYD=$(grep -i '^TTYD_PORT=' /etc/rrorg.conf 2>/dev/null | cut -d'=' -f2)
unset HTTP_PORT DUFS_PORT TTYD_PORT
[ -f "/etc/rrorg.conf" ] && source "/etc/rrorg.conf" 2>/dev/null
local HTTP=${HTTP_PORT:-7080}
local DUFS=${DUFS_PORT:-7304}
local TTYD=${TTYD_PORT:-7681}

while true; do
DIALOG --title "$(TEXT "Settings")" \
--form "${MSG}" 11 70 3 "HTTP" 1 1 "${HTTP:-7080}" 1 10 55 0 "DUFS" 2 1 "${DUFS:-7304}" 2 10 55 0 "TTYD" 3 1 "${TTYD:-7681}" 3 10 55 0 \
Expand Down Expand Up @@ -2826,14 +2834,17 @@ function changePorts() {
rm -f "${RR_RAMUSER_FILE}"
fi
rm -rf "${RDXZ_PATH}"
{
[ ! "${HTTP:-7080}" = "7080" ] && /etc/init.d/S90thttpd restart
[ ! "${DUFS:-7304}" = "7304" ] && /etc/init.d/S99dufs restart
[ ! "${TTYD:-7681}" = "7681" ] && /etc/init.d/S99ttyd restart
} >/dev/null 2>&1 &
[ ! -f "/etc/rrorg.conf" ] && MSG="$(TEXT "Ports for TTYD/DUFS/HTTP restored.")" || MSG="$(TEXT "Ports for TTYD/DUFS/HTTP changed.")"
DIALOG --title "$(TEXT "Settings")" \
--msgbox "${MSG}" 0 0
rm -f "${TMP_PATH}/restartS.sh"
{
[ ! "${HTTP:-7080}" = "${HTTP_PORT:-7080}" ] && echo "/etc/init.d/S90thttpd restart"
[ ! "${DUFS:-7304}" = "${DUFS_PORT:-7304}" ] && echo "/etc/init.d/S99dufs restart"
[ ! "${TTYD:-7681}" = "${TTYD_PORT:-7681}" ] && echo "/etc/init.d/S99ttyd restart"
} >"${TMP_PATH}/restartS.sh"
chmod +x "${TMP_PATH}/restartS.sh"
nohup "${TMP_PATH}/restartS.sh" >/dev/null 2>&1
break
;;
1)
Expand Down Expand Up @@ -2872,7 +2883,7 @@ function advancedMenu() {
echo "k \"$(TEXT "Kernel switching method:") \Z4${KERNELWAY}\Zn\""
# Some GPU have compatibility issues, so this function is temporarily disabled. RR_CMDLINE= ... nomodeset
# checkCmdline "rr_cmdline" "nomodeset" && POWEROFFDISPLAY="false" || POWEROFFDISPLAY="true"
# echo "v \"$(TEXT "Power off display after boot:") \Z4${POWEROFFDISPLAY}\Zn\"" >>"${TMP_PATH}/menu"
# echo "v \"$(TEXT "Power off display after boot:") \Z4${POWEROFFDISPLAY}\Zn\""
fi
echo "n \"$(TEXT "Reboot on kernel panic:") \Z4${KERNELPANIC}\Zn\""
if [ -n "$(ls /dev/mmcblk* 2>/dev/null)" ]; then
Expand Down Expand Up @@ -3250,7 +3261,7 @@ function downloadExts() {
TAG=""
if [ "${PRERELEASE}" = "true" ]; then
# TAG="$(curl -skL --connect-timeout 10 "${PROXY}${3}/tags" | pup 'a[class="Link--muted"] attr{href}' | grep ".zip" | head -1)"
TAG="$(curl -skL --connect-timeout 10 "${PROXY}${3}/tags" | grep /refs/tags/.*\.zip | sed -r 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
TAG="$(curl -skL --connect-timeout 10 "${PROXY}${3}/tags" | grep /refs/tags/.*\.zip | sed -E 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/' | sort -rV | head -1)"
else
LATESTURL="$(curl -skL --connect-timeout 10 -w %{url_effective} -o /dev/null "${PROXY}${3}/releases/latest")"
TAG="${LATESTURL##*/}"
Expand Down Expand Up @@ -4045,7 +4056,6 @@ else
settingsMenu
NEXT="m"
;;

c)
cleanCache
NEXT="d"
Expand Down
19 changes: 12 additions & 7 deletions files/initrd/opt/rr/ramdisk-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,21 @@ for KEY in "${!SYNOINFO[@]}"; do
done

# Patch /sbin/init.post
# Apply config manipulators
grep -v -e '^[\t ]*#' -e '^$' "${WORK_PATH}/patch/config-manipulators.sh" >"${TMP_PATH}/rp.txt"
sed -e "/@@@CONFIG-MANIPULATORS-TOOLS@@@/ {" -e "r ${TMP_PATH}/rp.txt" -e 'd' -e '}' -i "${RAMDISK_PATH}/sbin/init.post"
rm -f "${TMP_PATH}/rp.txt"
touch "${TMP_PATH}/rp.txt"
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc/synoinfo.conf'" >>"${TMP_PATH}/rp.txt"
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc.defaults/synoinfo.conf'" >>"${TMP_PATH}/rp.txt"
for KEY in "${!SYNOINFO[@]}"; do
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc/synoinfo.conf'" >>"${TMP_PATH}/rp.txt"
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc.defaults/synoinfo.conf'" >>"${TMP_PATH}/rp.txt"
done

# Generate synoinfo configurations
{
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc/synoinfo.conf'"
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc.defaults/synoinfo.conf'"
for KEY in "${!SYNOINFO[@]}"; do
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc/synoinfo.conf'"
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc.defaults/synoinfo.conf'"
done
} >"${TMP_PATH}/rp.txt"

sed -e "/@@@CONFIG-GENERATED@@@/ {" -e "r ${TMP_PATH}/rp.txt" -e 'd' -e '}' -i "${RAMDISK_PATH}/sbin/init.post"
rm -f "${TMP_PATH}/rp.txt"

Expand Down
40 changes: 33 additions & 7 deletions files/initrd/opt/rr/vmlinux-to-bzImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@

[ -z "${WORK_PATH}" ] || [ ! -d "${WORK_PATH}/include" ] && WORK_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

. "${WORK_PATH}/include/functions.sh"
calculate_run_size() {
NUM='\([0-9a-fA-F]*[ \t]*\)'
OUT=$(sed -n 's/^[ \t0-9]*.b[sr][sk][ \t]*'"${NUM}${NUM}${NUM}${NUM}"'.*/0x\1 0x\4/p')

PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")"
PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")"
KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kver" "${WORK_PATH}/platforms.yml")"
KPRE="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kpre" "${WORK_PATH}/platforms.yml")"
if [ -z "${OUT}" ]; then
echo "Never found .bss or .brk file offset" >&2
return 1
fi

read -r sizeA offsetA sizeB offsetB <<<$(echo ${OUT} | awk '{printf "%d %d %d %d", strtonum($1), strtonum($2), strtonum($3), strtonum($4)}')

runSize=$((offsetA + sizeA + sizeB))

# BFD linker shows the same file offset in ELF.
if [ "${offsetA}" -ne "${offsetB}" ]; then
# Gold linker shows them as consecutive.
endSize=$((offsetB + sizeB))
if [ "${endSize}" -ne "${runSize}" ]; then
printf "sizeA: 0x%x\n" ${sizeA} >&2
printf "offsetA: 0x%x\n" ${offsetA} >&2
printf "sizeB: 0x%x\n" ${sizeB} >&2
printf "offsetB: 0x%x\n" ${offsetB} >&2
echo ".bss and .brk are non-contiguous" >&2
return 1
fi
fi

printf "%d\n" ${runSize}
return 0
}

# Adapted from: scripts/Makefile.lib
# Usage: size_append FILE [FILE2] [FILEn]...
Expand All @@ -35,6 +59,8 @@ size_le() {

VMLINUX_MOD=${1}
ZIMAGE_MOD=${2}

KVER=$(strings "${VMLINUX_MOD}" | grep -Eo "Linux version [0-9]+\.[0-9]+\.[0-9]+" | head -1 | awk '{print $3}')
if [ "$(echo "${KVER:-4}" | cut -d'.' -f1)" -lt 5 ]; then
# Kernel version 4.x or 3.x (bromolow)
# zImage_head 16494
Expand All @@ -57,7 +83,7 @@ if [ "$(echo "${KVER:-4}" | cut -d'.' -f1)" -lt 5 ]; then
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745134 seek=1 conv=notrunc || exit 1
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745244 seek=1 conv=notrunc || exit 1

RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | sh "${WORK_PATH}/calc_run_size.sh")
RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | calc_run_size)
size_le "${RUN_SIZE}" | dd of="${ZIMAGE_MOD}" bs=15745210 seek=1 conv=notrunc || exit 1
size_le "$((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}') ^ 0xFFFFFFFF))" | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
else
Expand All @@ -67,7 +93,7 @@ else
dd if="${VMLINUX_MOD}" of="${ZIMAGE_MOD}" bs=14561 seek=1 conv=notrunc || exit 1
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34463421 seek=1 conv=notrunc || exit 1
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34479132 seek=1 conv=notrunc || exit 1
# RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | sh "${WORK_PATH}/calc_run_size.sh")
# RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | calc_run_size)
# size_le "${RUN_SIZE}" | dd of="${ZIMAGE_MOD}" bs=34626904 seek=1 conv=notrunc || exit 1
size_le "$((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}') ^ 0xFFFFFFFF))" | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
fi
6 changes: 3 additions & 3 deletions guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@
* RR 备份 (Any version):
```shell
# 备份为 disk.img.gz, 自行导出.
dd if=`blkid | grep 'LABEL="RR3"' | cut -d3 -f1` | gzip > disk.img.gz
dd if="$(blkid | grep 'LABEL="RR3"' | cut -d3 -f1)" | gzip > disk.img.gz
# 结合 transfer.sh 直接导出链接
curl -skL --insecure -w '\n' --upload-file disk.img.gz https://transfer.sh
```

* RR 开机强行进入到 RR shell:
```shell
# 在 wait IP 的时候, 快速的连上, 杀死 boot.sh 进程.
kill `ps | grep -v grep | grep boot.sh | awk '{print $1}'`
kill $(ps | grep -v grep | grep boot.sh | awk '{print $1}')
```

# SYNO:
Expand Down Expand Up @@ -109,7 +109,7 @@
SN=xxxxxxxxxx # 输入你要设置的SN
echo 1 > /proc/sys/kernel/syno_install_flag
[ -b "/dev/synoboot1" ] && (mkdir -p /tmp/synoboot1; mount /dev/synoboot1 /tmp/synoboot1)
[ -f "/tmp/synoboot1/user-config.yml" ] && OLD_SN=`grep '^sn:' /tmp/synoboot1/user-config.yml | sed -r 's/sn:(.*)/\1/; s/[\" ]//g'`
[ -f "/tmp/synoboot1/user-config.yml" ] && OLD_SN=$(sed -E 's/^sn:(.*)/\1/; s/[\" ]//g' /tmp/synoboot1/user-config.yml)
[ -n "${OLD_SN}" ] && sed -i "s/${OLD_SN}/${SN}/g" /tmp/synoboot1/user-config.yml
reboot
```
Expand Down
Binary file removed kpatch/kpatch
Binary file not shown.

0 comments on commit 94133a3

Please sign in to comment.