From 874d14b948dbfed4d3554ea5d87b25a9a6d5b4da Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Thu, 29 Aug 2024 19:38:14 +0200 Subject: [PATCH] arc: more rework Signed-off-by: AuxXxilium --- files/initrd/opt/arc/arc.sh | 218 +++++++++++------------- files/initrd/opt/arc/include/consts.sh | 2 +- files/initrd/opt/arc/include/network.sh | 4 +- 3 files changed, 99 insertions(+), 125 deletions(-) diff --git a/files/initrd/opt/arc/arc.sh b/files/initrd/opt/arc/arc.sh index d933dc55..56ecb987 100755 --- a/files/initrd/opt/arc/arc.sh +++ b/files/initrd/opt/arc/arc.sh @@ -88,7 +88,7 @@ function backtitle() { ############################################################################### # Model Selection function arcModel() { - CHANGED=false + CHANGED="false" dialog --backtitle "$(backtitle)" --title "DSM Model" \ --infobox "Reading Models..." 3 25 # Loop menu @@ -213,14 +213,11 @@ function arcModel() { writeConfigKey "emmcboot" "false" "${USER_CONFIG_FILE}" writeConfigKey "hddsort" "false" "${USER_CONFIG_FILE}" writeConfigKey "modelid" "${MODELID}" "${USER_CONFIG_FILE}" - writeConfigKey "paturl" "" "${USER_CONFIG_FILE}" - writeConfigKey "pathash" "" "${USER_CONFIG_FILE}" writeConfigKey "platform" "${PLATFORM}" "${USER_CONFIG_FILE}" writeConfigKey "ramdisk-hash" "" "${USER_CONFIG_FILE}" writeConfigKey "smallnum" "" "${USER_CONFIG_FILE}" - writeConfigKey "sn" "" "${USER_CONFIG_FILE}" writeConfigKey "zimage-hash" "" "${USER_CONFIG_FILE}" - CHANGED=true + CHANGED="true" elif [ "${MODEL}" != "${resp}" ]; then PRODUCTVER="" MODEL="${resp}" @@ -244,7 +241,7 @@ function arcModel() { writeConfigKey "smallnum" "" "${USER_CONFIG_FILE}" writeConfigKey "sn" "" "${USER_CONFIG_FILE}" writeConfigKey "zimage-hash" "" "${USER_CONFIG_FILE}" - CHANGED=true + CHANGED="true" fi if [ "${CHANGED}" == "true" ]; then rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" 2>/dev/null || true @@ -265,14 +262,17 @@ function arcModel() { # Arc Version Section function arcVersion() { # Read Model Config - CHANGED=false + CHANGED="false" MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")" PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")" DT="$(readConfigKey "platforms.${PLATFORM}.dt" "${P_FILE}")" PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")" AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")" + # Get PAT Data from Config + PAT_URL_CONF="$(readConfigKey "paturl" "${USER_CONFIG_FILE}")" + PAT_HASH_CONF="$(readConfigKey "pathash" "${USER_CONFIG_FILE}")" # Check for Custom Build - if [ "${AUTOMATED}" == "false" ]; then + if [ "${AUTOMATED}" == "false" ] && [ "${OFFLINE}" == "false" ]; then # Select Build for DSM ITEMS="$(readConfigEntriesArray "platforms.${PLATFORM}.productvers" "${P_FILE}" | sort -r)" dialog --clear --no-items --nocancel --title "DSM Version" --backtitle "$(backtitle)" \ @@ -293,20 +293,18 @@ function arcVersion() { writeConfigKey "zimage-hash" "" "${USER_CONFIG_FILE}" writeConfigKey "arc.confdone" "false" "${USER_CONFIG_FILE}" CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")" - CHANGED=true + CHANGED="true" fi if [ "${CHANGED}" == "true" ]; then rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" 2>/dev/null || true rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/"* >/dev/null 2>&1 || true fi - fi - PAT_URL="" - PAT_HASH="" - URLVER="" - # Cleanup - [ -d "${UNTAR_PAT_PATH}" ] && rm -rf "${UNTAR_PAT_PATH}" - mkdir -p "${UNTAR_PAT_PATH}" - if [ "${OFFLINE}" == "false" ] && [ "${AUTOMATED}" == "false" ]; then + PAT_URL="" + PAT_HASH="" + URLVER="" + # Cleanup + [ -d "${UNTAR_PAT_PATH}" ] && rm -rf "${UNTAR_PAT_PATH}" + mkdir -p "${UNTAR_PAT_PATH}" while true; do PJ="$(python ${ARC_PATH}/include/functions.py getpats4mv -m "${MODEL}" -v "${PRODUCTVER}")" if [[ -z "${PJ}" || "${PJ}" = "{}" ]]; then @@ -332,35 +330,24 @@ function arcVersion() { [ -n "${PAT_URL}" ] && [ -n "${PAT_HASH}" ] && break fi done - elif [ "${OFFLINE}" == "false" ] && [ "${AUTOMATED}" == "true" ]; then - # Get PAT Data - dialog --backtitle "$(backtitle)" --colors --title "DSM Version" \ - --infobox "Get PAT Data from Local File..." 3 40 - NANOVER="$(readConfigKey "nanover" "${USER_CONFIG_FILE}")" - [ -n "${NANOVER}" ] && DSMVER="${PRODUCTVER}.${NANOVER}" || DSMVER="${PRODUCTVER}" - PAT_URL="$(readConfigKey "${MODEL}.\"${DSMVER}\".url" "${D_FILE}")" - PAT_HASH="$(readConfigKey "${MODEL}.\"${DSMVER}\".hash" "${D_FILE}")" - sleep 2 - # To-DO: add to custom build - fi - if [ -z "${PAT_URL}" ] && [ -z "${PAT_HASH}" ] && [ "${AUTOMATED}" == "false" ]; then - MSG="Failed to get PAT Data.\n" - MSG+="Please manually fill in the URL and Hash of PAT.\n" - MSG+="You will find these Data at: https://auxxxilium.tech/wiki/arc-loader-arc-loader/url-hash-liste" - dialog --backtitle "$(backtitle)" --colors --title "Arc Build" --default-button "OK" \ - --form "${MSG}" 11 120 2 "URL" 1 1 "${PAT_URL}" 1 8 110 0 "HASH" 2 1 "${PAT_HASH}" 2 8 110 0 \ - 2>"${TMP_PATH}/resp" - RET=$? - [ ${RET} -eq 0 ] # ok-button - return 1 # 1 or 255 # cancel-button or ESC - PAT_URL="$(cat "${TMP_PATH}/resp" | sed -n '1p')" - PAT_HASH="$(cat "${TMP_PATH}/resp" | sed -n '2p')" - elif [ -z "${PAT_URL}" ] && [ -z "${PAT_HASH}" ] && [ "${AUTOMATED}" == "true" ]; then - dialog --backtitle "$(backtitle)" --colors --title "DSM Version" \ - --infobox "Could not get PAT Data..." 4 30 - PAT_URL="#" - PAT_HASH="#" - sleep 5 + if [ -z "${PAT_URL}" ] || [ -z "${PAT_HASH}" ]; then + MSG="Failed to get PAT Data.\n" + MSG+="Please manually fill in the URL and Hash of PAT.\n" + MSG+="You will find these Data at: https://auxxxilium.tech/wiki/arc-loader-arc-loader/url-hash-liste" + dialog --backtitle "$(backtitle)" --colors --title "Arc Build" --default-button "OK" \ + --form "${MSG}" 11 120 2 "URL" 1 1 "${PAT_URL}" 1 8 110 0 "HASH" 2 1 "${PAT_HASH}" 2 8 110 0 \ + 2>"${TMP_PATH}/resp" + RET=$? + [ ${RET} -eq 0 ] # ok-button + return 1 # 1 or 255 # cancel-button or ESC + PAT_URL="$(cat "${TMP_PATH}/resp" | sed -n '1p')" + PAT_HASH="$(cat "${TMP_PATH}/resp" | sed -n '2p')" + fi + VALID="true" + elif [ "${AUTOMATED}" == "true" ]; then + PAT_URL="$(readConfigKey "paturl" "${USER_CONFIG_FILE}")" + PAT_HASH="$(readConfigKey "pathash" "${USER_CONFIG_FILE}")" + VALID="true" fi # Check PAT URL if [ "${OFFLINE}" == "false" ]; then @@ -370,59 +357,48 @@ function arcVersion() { if echo "${URLCHECK}" | grep -q 404; then VALID="false" else - sleep 2 - # Get PAT Data from Config - PAT_URL_CONF="$(readConfigKey "paturl" "${USER_CONFIG_FILE}")" - PAT_HASH_CONF="$(readConfigKey "pathash" "${USER_CONFIG_FILE}")" - dialog --backtitle "$(backtitle)" --colors --title "DSM Version" \ - --infobox "Try to get DSM Image..." 3 40 - if [ "${PAT_HASH}" != "${PAT_HASH_CONF}" ] || [ "${PAT_URL}" != "${PAT_URL_CONF}" ] || [ ! -f "${ORI_ZIMAGE_FILE}" ] || [ ! -f "${ORI_RDGZ_FILE}" ]; then - # Write new PAT Data to Config - writeConfigKey "paturl" "${PAT_URL}" "${USER_CONFIG_FILE}" - writeConfigKey "pathash" "${PAT_HASH}" "${USER_CONFIG_FILE}" - # Get new Files - DSM_FILE="${UNTAR_PAT_PATH}/${PAT_HASH}.tar" - DSM_URL="https://raw.githubusercontent.com/AuxXxilium/arc-dsm/main/files/${MODEL/+/%2B}/${PRODUCTVER}/${PAT_HASH}.tar" - if curl -skL "${DSM_URL}" -o "${DSM_FILE}"; then + VALID="true" + fi + fi + sleep 2 + DSM_FILE="${USER_UP_PATH}/${PAT_HASH}.tar" + if [ ! -f "${DSM_FILE}" ] && && [ "${OFFLINE}" == "false" ] && [ "${VALID}" == "true" ]; then + dialog --backtitle "$(backtitle)" --colors --title "DSM Version" \ + --infobox "Try to get DSM Image..." 3 40 + if [ "${PAT_HASH}" != "${PAT_HASH_CONF}" ] || [ "${PAT_URL}" != "${PAT_URL_CONF}" ] || [ ! -f "${ORI_ZIMAGE_FILE}" ] || [ ! -f "${ORI_RDGZ_FILE}" ]; then + # Write new PAT Data to Config + writeConfigKey "paturl" "${PAT_URL}" "${USER_CONFIG_FILE}" + writeConfigKey "pathash" "${PAT_HASH}" "${USER_CONFIG_FILE}" + # Get new Files + DSM_URL="https://raw.githubusercontent.com/AuxXxilium/arc-dsm/main/files/${MODEL/+/%2B}/${PRODUCTVER}/${PAT_HASH}.tar" + if curl -skL "${DSM_URL}" -o "${DSM_FILE}"; then + VALID="true" + elif curl --interface ${ARCNIC} -skL "${DSM_URL}" -o "${DSM_FILE}"; then + VALID="true" + else + dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ + --infobox "No DSM Image found!\nTry to get .pat from Syno." 4 40 + sleep 5 + # Grep PAT_URL + PAT_FILE="${USER_UP_PATH}/${PAT_HASH}.pat" + if curl -skL "${PAT_URL}" -o "${PAT_FILE}"; then VALID="true" - elif curl --interface ${ARCNIC} -skL "${DSM_URL}" -o "${DSM_FILE}"; then + elif curl --interface ${ARCNIC} -skL "${PAT_URL}" -o "${PAT_FILE}"; then VALID="true" else dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ - --infobox "No DSM Image found!\nTry to get .pat from Syno." 4 40 - sleep 5 - # Grep PAT_URL - PAT_FILE="${TMP_PATH}/${PAT_HASH}.pat" - if curl -skL "${PAT_URL}" -o "${PAT_FILE}"; then - VALID="true" - elif curl --interface ${ARCNIC} -skL "${PAT_URL}" -o "${PAT_FILE}"; then - VALID="true" - else - dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ - --infobox "No DSM Image found!\nExit." 4 40 - VALID="false" - sleep 5 - fi - fi - if [ -f "${DSM_FILE}" ] && [ "${VALID}" == "true" ]; then - tar -xf "${DSM_FILE}" -C "${UNTAR_PAT_PATH}" 2>/dev/null - VALID="true" - elif [ -f "${PAT_FILE}" ] && [ "${VALID}" == "true" ]; then - extractDSMFiles "${PAT_FILE}" "${UNTAR_PAT_PATH}" 2>/dev/null - VALID="true" - else - dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ - --infobox "DSM Extraction failed!\nExit." 4 40 + --infobox "No DSM Image found!\nExit." 4 40 VALID="false" sleep 5 fi fi fi - elif [ "${OFFLINE}" == "true" ] && [ "${AUTOMATED}" == "false" ]; then + elif [ ! -f "${DSM_FILE}" ] && [ "${OFFLINE}" == "true" ] && [ "${AUTOMATED}" == "false" ]; then + PAT_FILE=$(ls ${USER_UP_PATH}/*.pat | head -n 1) if [ -f "${ORI_ZIMAGE_FILE}" ] && [ -f "${ORI_RDGZ_FILE}" ]; then rm -f "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" 2>/dev/null || true VALID="true" - else + elif [ ! -f "${PAT_FILE}" ]; then # Check for existing Files mkdir -p "${USER_UP_PATH}" # Get new Files @@ -434,38 +410,36 @@ function arcVersion() { MSG+="Press OK to continue!" dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ --msgbox "${MSG}" 9 80 - # Grep PAT_FILE - PAT_FILE=$(ls ${USER_UP_PATH}/*.pat | head -n 1) - if [ -f "${PAT_FILE}" ] && [ $(wc -c "${PAT_FILE}" | awk '{print $1}') -gt 300000000 ]; then - dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ - --infobox "DSM Image found!" 3 40 - # Remove PAT Data for Offline - [ -z "${PAT_URL}" ] && writeConfigKey "paturl" "#" "${USER_CONFIG_FILE}" - [ -z "${PAT_HASH}" ] && writeConfigKey "pathash" "#" "${USER_CONFIG_FILE}" - # Extract Files - if extractDSMFiles "${PAT_FILE}" "${UNTAR_PAT_PATH}"; then - VALID="true" - else - dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ - --infobox "DSM Extraction failed!\nExit." 4 40 - VALID="false" - sleep 5 - fi - elif [ ! -f "${PAT_FILE}" ]; then - dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ - --infobox "No DSM Image found!\nExit." 4 40 - VALID="false" - sleep 5 - else - dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ - --infobox "Incorrect DSM Image (.pat) found!\nExit." 4 40 - VALID="false" - sleep 5 - fi fi + # Grep PAT_FILE + if [ -f "${PAT_FILE}" ] && [ $(wc -c "${PAT_FILE}" | awk '{print $1}') -gt 300000000 ]; then + dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ + --infobox "DSM Image found!" 3 40 + # Remove PAT Data for Offline + writeConfigKey "paturl" "#" "${USER_CONFIG_FILE}" + writeConfigKey "pathash" "#" "${USER_CONFIG_FILE}" + VALID="true" + elif [ ! -f "${PAT_FILE}" ]; then + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "No DSM Image found!\nExit." 4 40 + VALID="false" + sleep 5 + else + dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ + --infobox "Incorrect DSM Image (.pat) found!\nExit." 4 40 + VALID="false" + sleep 5 + fi + fi + if [ -f "${DSM_FILE}" ] && [ "${VALID}" == "true" ]; then + tar -xf "${DSM_FILE}" -C "${UNTAR_PAT_PATH}" 2>/dev/null + VALID="true" + elif [ -f "${PAT_FILE}" ] && [ "${VALID}" == "true" ]; then + extractDSMFiles "${PAT_FILE}" "${UNTAR_PAT_PATH}" 2>/dev/null + VALID="true" else - dialog --backtitle "$(backtitle)" --title "Arc Build" --aspect 18 \ - --infobox "Can't build Custom Loader while Offline!\nExit." 4 40 + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "DSM Extraction failed!\nExit." 4 40 VALID="false" sleep 5 fi @@ -527,10 +501,10 @@ function arcPatch() { SN="$(readConfigKey "sn" "${USER_CONFIG_FILE}")" if [ "${AUTOMATED}" == "true" ] && [ -z "${SN}" ]; then if [ -n "${ARCCONF}" ]; then - SN=$(generateSerial "${MODEL}" true) + SN=$(generateSerial "${MODEL}" "true") writeConfigKey "arc.patch" "true" "${USER_CONFIG_FILE}" else - SN=$(generateSerial "${MODEL}" false) + SN=$(generateSerial "${MODEL}" "false") writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}" fi elif [ "${AUTOMATED}" == "false" ]; then @@ -546,11 +520,11 @@ function arcPatch() { [ -z "${resp}" ] && return 1 if [ ${resp} -eq 1 ]; then # Read Arc Patch from File - SN=$(generateSerial "${MODEL}" true) + SN=$(generateSerial "${MODEL}" "true") writeConfigKey "arc.patch" "true" "${USER_CONFIG_FILE}" elif [ ${resp} -eq 2 ]; then # Generate random Serial - SN=$(generateSerial "${MODEL}" false) + SN=$(generateSerial "${MODEL}" "false") writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}" elif [ ${resp} -eq 3 ]; then while true; do @@ -578,7 +552,7 @@ function arcPatch() { [ -z "${resp}" ] && return 1 if [ ${resp} -eq 1 ]; then # Generate random Serial - SN=$(generateSerial "${MODEL}" false) + SN=$(generateSerial "${MODEL}" "false") writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}" elif [ ${resp} -eq 2 ]; then while true; do diff --git a/files/initrd/opt/arc/include/consts.sh b/files/initrd/opt/arc/include/consts.sh index ac48b755..873fac3d 100755 --- a/files/initrd/opt/arc/include/consts.sh +++ b/files/initrd/opt/arc/include/consts.sh @@ -7,7 +7,6 @@ PART2_PATH="/mnt/p2" PART3_PATH="/mnt/p3" TMP_PATH="/tmp" -UNTAR_PAT_PATH="${TMP_PATH}/DSM" RAMDISK_PATH="${TMP_PATH}/ramdisk" LOG_FILE="${TMP_PATH}/log.txt" TMP_UP_PATH="${TMP_PATH}/upload" @@ -32,6 +31,7 @@ PATCH_PATH="${PART3_PATH}/patches" LKMS_PATH="${PART3_PATH}/lkms" CUSTOM_PATH="${PART3_PATH}/custom" USER_UP_PATH="${PART3_PATH}/users" +UNTAR_PAT_PATH="${PART3_PATH}/DSM" S_FILE="${MODEL_CONFIG_PATH}/serials.yml" S_FILE_ARC="${MODEL_CONFIG_PATH}/arc_serials.yml" diff --git a/files/initrd/opt/arc/include/network.sh b/files/initrd/opt/arc/include/network.sh index 217ebd18..900de9e9 100755 --- a/files/initrd/opt/arc/include/network.sh +++ b/files/initrd/opt/arc/include/network.sh @@ -6,13 +6,13 @@ function getnet() { NICPORTS="$(readConfigKey "${MODEL}.ports" "${S_FILE}" 2>/dev/null)" if [ "${ARCPATCH}" == "true" ]; then ETHN="$(echo ${ETHX} | wc -w)" - MACS=($(generateMacAddress "${MODEL}" "${ETHN}" true)) + MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "true")) for I in $(seq 1 ${ETHN}); do writeConfigKey "eth$((${I} - 1))" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}" done elif [ "${ARCPATCH}" == "false" ]; then ETHN="$(echo ${ETHX} | wc -w)" - MACS=($(generateMacAddress "${MODEL}" "${ETHN}" false)) + MACS=($(generateMacAddress "${MODEL}" "${ETHN}" "false")) for I in $(seq 1 ${ETHN}); do writeConfigKey "eth$((${I} - 1))" "${MACS[$((${I} - 1))]}" "${USER_CONFIG_FILE}" done