From 5f29b8b3f8d0ab24ceafdd2a7e4f2e0b92854bf6 Mon Sep 17 00:00:00 2001 From: Ing Date: Sat, 30 Mar 2024 15:12:51 +0800 Subject: [PATCH] add rr custom --- .github/workflows/issues.yml | 154 +++++++++++++++++++++++-- docs/index.html | 2 +- docs/issues.html | 210 +++++++++++++++++++++++++++++++++++ files/initrd/opt/rr/menu.sh | 47 ++++---- localbuild.sh | 32 ++++-- 5 files changed, 409 insertions(+), 36 deletions(-) create mode 100644 docs/issues.html diff --git a/.github/workflows/issues.yml b/.github/workflows/issues.yml index fa4d2bb6..a730b1b3 100644 --- a/.github/workflows/issues.yml +++ b/.github/workflows/issues.yml @@ -14,6 +14,9 @@ jobs: build: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@main + - name: Init Env run: | git config --global user.email "github-actions[bot]@users.noreply.github.com" @@ -21,15 +24,37 @@ jobs: sudo timedatectl set-timezone "Asia/Shanghai" - name: Check Issues + shell: python run: | - if echo "${{ github.event.issue.body }}" | grep -q "ENV"; then - echo "FALG=true" >> $GITHUB_ENV - else - echo "FALG=false" >> $GITHUB_ENV - fi + # -*- coding: utf-8 -*- + import json, subprocess + def set_output(name, value): + subprocess.call(["echo '{}={}' >> $GITHUB_ENV".format(name, value)], shell=True) - - name: Create Issues comment - if: env.FALG == 'false' + issuetitle = ${{ toJSON(github.event.issue.title) }}; + issuebody = ${{ toJSON(github.event.issue.body) }}; + + iscustom = 'false' + warinfo = 'false' + model = '' + try: + if issuetitle.lower().startswith('custom'): + json_object = json.loads(issuebody) + iscustom = 'true' + model = json_object.get('model', '') + except ValueError as e: + pass + + if iscustom == 'false': + if issuebody.find('ENV') >= 0: + warinfo = 'true' + + set_output("iscustom", iscustom) + set_output("warinfo", warinfo) + set_output("model", model) + + - name: Update Comment Warinfo + if: env.warinfo == 'true' uses: actions-cool/issues-helper@v3 with: actions: "create-comment" @@ -68,3 +93,118 @@ jobs: ... If you can't provide detailed information, then wait for someone who is destined! emoji: heart + + - name: Update Comment Labels + if: env.iscustom == 'true' + uses: actions-cool/issues-helper@v3 + with: + actions: 'add-labels' + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + labels: 'custom,${{ env.model }}' + + - name: Update Comment Building + if: env.iscustom == 'true' + id: comment + uses: actions-cool/issues-helper@v3 + with: + actions: 'create-comment' + token: ${{ secrets.GITHUB_TOKEN }} + issue-number: ${{ github.event.issue.number }} + body: | + Hi @${{ github.event.issue.user.login }}. + RR-${{ env.model }} is being build and package and will be sent to your email later.. + > ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + ---- + emoji: heart + + - name: Run Build + if: env.iscustom == 'true' + run: | + # 累了, 毁灭吧 + + REPO=${{ github.server_url }}/${{ github.repository }} + MODEL=${{ env.model }} + PRERELEASE="false" + + TAG="" + if [ "${PRERELEASE}" = "true" ]; then + TAG="$(curl -skL --connect-timeout 10 "${REPO}/tags" | grep /refs/tags/.*\.zip | head -1 | sed -r 's/.*\/refs\/tags\/(.*)\.zip.*$/\1/')" + else + LATESTURL="$(curl -skL --connect-timeout 10 -w %{url_effective} -o /dev/null "${REPO}/releases/latest")" + TAG="${LATESTURL##*/}" + fi + [ "${TAG:0:1}" = "v" ] && TAG="${TAG:1}" + rm -f rr-${TAG}.img.zip + STATUS=$(curl -kL --connect-timeout 10 -w "%{http_code}" "${REPO}/releases/download/${TAG}/rr-${TAG}.img.zip" -o "rr-${TAG}.img.zip") + if [ $? -ne 0 -o ${STATUS:-0} -ne 200 ]; then + echo "Download failed" + exit 1 + fi + + unzip rr-${TAG}.img.zip -d "rr" + + export TERM=xterm + + sudo ./localbuild.sh init rr rr/rr.img + sudo ./localbuild.sh config ${MODEL} + sudo ./localbuild.sh pack rr/rr.img + + ls rr -al + zip -9 "rr-${MODEL}-${TAG}-${{ github.run_id }}.img.zip" -j rr/rr.img + + UPLOAD="$(curl -k -F "file=@rr-${MODEL}-${TAG}-${{ github.run_id }}.img.zip" -F "token=${{ secrets.TT_TOKEN }}" -F "model=0" -X POST "https://tmp-cli.vx-cdn.com/app/upload_cli")" + if ! echo "${UPLOAD}" | grep -q "Download Page"; then + echo "Upload failed" + exit 1 + fi + + EMAIL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/users/${{ github.event.issue.user.login }}" | jq -r '.email') + TTDLURL="$(echo "${UPLOAD}" | grep "Download Page" | head -1)" + echo "TAG=${TAG}" >> $GITHUB_ENV + echo "EMAIL=${EMAIL}" >> $GITHUB_ENV + echo "TTDLURL=${TTDLURL}" >> $GITHUB_ENV + + - name: Send mail + if: env.iscustom == 'true' && success() + uses: dawidd6/action-send-mail@v3 + with: + server_address: smtp-mail.outlook.com + server_port: 587 + username: ${{ secrets.MAIL_USERNAME }} + password: ${{ secrets.MAIL_PASSWORD }} + subject: rr-${{ env.model }}-${{ env.TAG }} + to: ${{ env.EMAIL }} + from: ${{ secrets.MAIL_USERNAME }} + body: | + ${{ env.TTDLURL }} + + - name: Update Comment Success + if: env.iscustom == 'true' && success() + uses: actions-cool/issues-helper@v3 + with: + actions: 'update-comment' + token: ${{ secrets.GITHUB_TOKEN }} + comment-id: ${{ steps.comment.outputs.comment-id }} + update-mode: replace + body: | + Hi @${{ github.event.issue.user.login }}. + RR-${{ env.model }} has been sent to your email. + > ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + ---- + emoji: hooray + + - name: Update Comment Fail + if: env.iscustom == 'true' && failure() + uses: actions-cool/issues-helper@v3 + with: + actions: 'update-comment' + token: ${{ secrets.GITHUB_TOKEN }} + comment-id: ${{ steps.comment.outputs.comment-id }} + update-mode: replace + body: | + Hi @${{ github.event.issue.user.login }}. + RR-${{ env.model }} failed to build and package, please try again. + > ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} + ---- + emoji: confused \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 64ea13aa..be1c0deb 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/docs/issues.html b/docs/issues.html new file mode 100644 index 00000000..7728cfec --- /dev/null +++ b/docs/issues.html @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + RR-CUSTOM + + + +
+ +
+ +
+
+
+ + + + + Public +
+ +
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+
+ + + + \ No newline at end of file diff --git a/files/initrd/opt/rr/menu.sh b/files/initrd/opt/rr/menu.sh index ddb4d972..38515b4c 100755 --- a/files/initrd/opt/rr/menu.sh +++ b/files/initrd/opt/rr/menu.sh @@ -140,9 +140,9 @@ function modelMenu() { DIALOG --title "$(TEXT "Model")" \ --menu "$(TEXT "Choose the model")" 0 0 0 --file "${TMP_PATH}/menu" \ 2>${TMP_PATH}/resp - [ $? -ne 0 ] && return + [ $? -ne 0 ] && return 0 resp=$(cat ${TMP_PATH}/resp) - [ -z "${resp}" ] && return + [ -z "${resp}" ] && return 1 if [ "${resp}" = "c" ]; then models=(DS918+ RS1619xs+ DS419+ DS1019+ DS719+ DS1621xs+) [ $(lspci -d ::300 2>/dev/null | grep 8086 | wc -l) -gt 0 ] && iGPU=1 || iGPU=0 @@ -195,6 +195,7 @@ function modelMenu() { break done else + [ ! -f "${WORK_PATH}/model-configs/${1}.yml" ] && return 1 resp="${1}" fi # If user change model, clean build* and pat* and SN @@ -224,6 +225,7 @@ function modelMenu() { rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/"* >/dev/null 2>&1 touch ${PART1_PATH}/.build fi + return 0 } ############################################################################### @@ -234,17 +236,17 @@ function productversMenu() { DIALOG --title "$(TEXT "Product Version")" \ --no-items --menu "$(TEXT "Choose a product version")" 0 0 0 ${ITEMS} \ 2>${TMP_PATH}/resp - [ $? -ne 0 ] && return + [ $? -ne 0 ] && return 0 resp=$(cat ${TMP_PATH}/resp) - [ -z "${resp}" ] && return + [ -z "${resp}" ] && return 1 if [ "${PRODUCTVER}" = "${resp}" ]; then DIALOG --title "$(TEXT "Product Version")" \ --yesno "$(printf "$(TEXT "The current version has been set to %s. Do you want to reset the version?")" "${PRODUCTVER}")" 0 0 - [ $? -ne 0 ] && return + [ $? -ne 0 ] && return 0 fi else - if ! arrayExistItem "${1}" ${ITEMS}; then return; fi + if ! arrayExistItem "${1}" ${ITEMS}; then return 1; fi resp="${1}" fi @@ -254,7 +256,7 @@ function productversMenu() { DIALOG --title "$(TEXT "Product Version")" \ --msgbox "$(TEXT "This version does not support UEFI startup, Please select another version or switch the startup mode.")" 0 0 fi - return + return 1 fi # if [ ! "usb" = "$(getBus "${LOADER_DISK}")" -a "${KVER:0:1}" = "5" ]; then # if [ -z "${1}" ]; then @@ -269,8 +271,10 @@ function productversMenu() { idx=1 NETERR=0 while [ ${idx} -le 3 ]; do # Loop 3 times, if successful, break - DIALOG --title "$(TEXT "Product Version")" \ - --infobox "$(TEXT "Get pat data ...") (${idx}/3)" 0 0 + if [ -z "${1}" ]; then + DIALOG --title "$(TEXT "Product Version")" \ + --infobox "$(TEXT "Get pat data ...") (${idx}/3)" 0 0 + fi idx=$((${idx} + 1)) NETERR=0 fastest=$(_get_fastest "www.synology.com" "www.synology.cn") @@ -316,7 +320,7 @@ function productversMenu() { fi [ ${RET} -eq 0 ] && break # ok-button [ ${RET} -eq 3 ] && continue # extra-button - return # 1 or 255 # cancel-button or ESC + return 0 # 1 or 255 # cancel-button or ESC done paturl="$(cat "${TMP_PATH}/resp" | sed -n '1p')" patsum="$(cat "${TMP_PATH}/resp" | sed -n '2p')" @@ -324,7 +328,7 @@ function productversMenu() { paturl="${2}" patsum="${3}" fi - [ -z "${paturl}" -o -z "${patsum}" ] && return + [ -z "${paturl}" -o -z "${patsum}" ] && return 1 writeConfigKey "paturl" "${paturl}" "${USER_CONFIG_FILE}" writeConfigKey "patsum" "${patsum}" "${USER_CONFIG_FILE}" PRODUCTVER=${resp} @@ -361,6 +365,7 @@ function productversMenu() { rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null 2>&1 rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/"* >/dev/null 2>&1 touch ${PART1_PATH}/.build + return 0 } ############################################################################### @@ -1281,8 +1286,7 @@ function extractDsmFiles() { # Where the magic happens! # 1 - silent function make() { - rm -f "${LOG_FILE}" - while true; do + function __make() { if [ ! -f "${ORI_ZIMAGE_FILE}" -o ! -f "${ORI_RDGZ_FILE}" ]; then extractDsmFiles [ $? -ne 0 ] && break @@ -1295,19 +1299,19 @@ function make() { [ -f ${MOD_ZIMAGE_FILE} ] && rm -f "${MOD_ZIMAGE_FILE}" && continue [ -f ${MOD_RDGZ_FILE} ] && rm -f "${MOD_RDGZ_FILE}" && continue echo -e "$(TEXT "No disk space left, please clean the cache and try again!")" >"${LOG_FILE}" - break 2 + return 1 done ${WORK_PATH}/zimage-patch.sh if [ $? -ne 0 ]; then echo -e "$(TEXT "zImage not patched,\nPlease upgrade the bootloader version and try again.\nPatch error:\n")$(cat "${LOG_FILE}")" >"${LOG_FILE}" - break + return 1 fi ${WORK_PATH}/ramdisk-patch.sh if [ $? -ne 0 ]; then echo -e "$(TEXT "Ramdisk not patched,\nPlease upgrade the bootloader version and try again.\nPatch error:\n")$(cat "${LOG_FILE}")" >"${LOG_FILE}" - break + return 1 fi rm -f ${PART1_PATH}/.build echo "$(TEXT "Cleaning ...")" @@ -1315,9 +1319,13 @@ function make() { rm -f "${LOG_FILE}" echo "$(TEXT "Ready!")" sleep 3 - break - done 2>&1 | DIALOG --title "$(TEXT "Main menu")" \ - --progressbox "$(TEXT "Making ... ('ctrl + c' to exit)")" 20 100 + return 0 + } + rm -f "${LOG_FILE}" + if [ ! "${1}" = "-1" ]; then + __make 2>&1 | DIALOG --title "$(TEXT "Main menu")" \ + --progressbox "$(TEXT "Making ... ('ctrl + c' to exit)")" 20 100 + fi if [ -f "${LOG_FILE}" ]; then if [ ! "${1}" = "-1" ]; then DIALOG --title "$(TEXT "Error")" \ @@ -3202,6 +3210,7 @@ function cleanCache() { rm -rfv "${TMP_PATH}/"* ) 2>&1 | DIALOG --title "$(TEXT "Main menu")" \ --progressbox "$(TEXT "Cleaning cache ...")" 20 100 + return } ############################################################################### diff --git a/localbuild.sh b/localbuild.sh index 0d710cf2..e96d14d9 100755 --- a/localbuild.sh +++ b/localbuild.sh @@ -6,7 +6,8 @@ # See /LICENSE for more information. # -if [ "$(id -u)" -ne 0 ]; then +PROMPT=$(sudo -nv 2>&1) +if [ $? -ne 0 ]; then echo "This script must be run as root" exit 1 fi @@ -15,7 +16,7 @@ function help() { echo "Usage: $0 [args]" echo "Commands:" echo " init [workspace] [rr.img] - Initialize the workspace" - echo " config - Configure the workspace" + echo " config [model] - Configure the workspace" echo " pack [rr.img] - Pack the workspace" echo " help - Show this help" exit 1 @@ -30,8 +31,8 @@ function init() { exit 1 fi - sudo apt update - sudo apt install -y locales busybox dialog curl xz cpio sed + sudo apt-get update + sudo apt-get install -y locales busybox dialog curl xz-utils cpio sed sudo locale-gen en_US.UTF-8 ko_KR.UTF-8 ru_RU.UTF-8 zh_CN.UTF-8 zh_HK.UTF-8 zh_TW.UTF-8 YQ=$(command -v yq) @@ -86,11 +87,24 @@ function config() { exit 1 fi . $(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/rr.env + RET=1 pushd "${CHROOT_PATH}/initrd/opt/rr" - ./init.sh - ./menu.sh + while true; do + if [ -z "${1}" ]; then + ./init.sh || break + ./menu.sh || break + else + ./init.sh || break + ./menu.sh modelMenu "${1}" || break + ./menu.sh productversMenu "7.2" || break + ./menu.sh make -1 || break + ./menu.sh cleanCache || break + RET=0 + fi + done popd - echo "OK." + [ ${RET} -ne 0 ] && echo "Failed." || echo "Success." + return ${RET} } function pack() { @@ -100,7 +114,7 @@ function pack() { fi . $(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)/rr.env - RRIMGPATH="$(realpath ${2:-"rr.img"})" + RRIMGPATH="$(realpath ${1:-"rr.img"})" if [ ! -f "${RRIMGPATH}" ]; then gzip -dc "${CHROOT_PATH}/initrd/opt/rr/grub.img.gz" >"${RRIMGPATH}" fi @@ -136,4 +150,4 @@ function pack() { echo "OK." } -$@ \ No newline at end of file +$@