diff --git a/files/initrd/opt/arc/arc.sh b/files/initrd/opt/arc/arc.sh index 1dc8e40c..1a7bf851 100755 --- a/files/initrd/opt/arc/arc.sh +++ b/files/initrd/opt/arc/arc.sh @@ -263,6 +263,7 @@ function arcVersion() { MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")" PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")" PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")" + # Check for Custom Build if [ "${CUSTOM}" = "false" ]; then # Select Build for DSM ITEMS="$(readConfigEntriesArray "platforms.${PLATFORM}.productvers" "${P_FILE}" | sort -r)" @@ -281,25 +282,6 @@ function arcVersion() { fi fi PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")" - else - if [[ -f "${ORI_ZIMAGE_FILE}" || -f "${ORI_RDGZ_FILE}" || -f "${MOD_ZIMAGE_FILE}" || -f "${MOD_RDGZ_FILE}" ]]; then - # Delete old files - rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" - fi - fi - KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.[${PRODUCTVER}].kver" "${P_FILE}")" - # Modify KVER for Epyc7002 - if [ "${PLATFORM}" = "epyc7002" ]; then - KVERP="${PRODUCTVER}-${KVER}" - else - KVERP="${KVER}" - fi - if [ "${ONLYVERSION}" = "true" ]; then - # Build isn't done - writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" - BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" - ONLYVERSION="" - return 0 fi dialog --backtitle "$(backtitle)" --title "Arc Config" \ --infobox "Reconfiguring Addons, Modules and Synoinfo" 3 50 @@ -308,8 +290,7 @@ function arcVersion() { while IFS=': ' read -r KEY VALUE; do writeConfigKey "synoinfo.\"${KEY}\"" "${VALUE}" "${USER_CONFIG_FILE}" done <<<$(readConfigMap "platforms.${PLATFORM}.synoinfo" "${P_FILE}") - # Reset Addons - writeConfigKey "addons" "{}" "${USER_CONFIG_FILE}" + # Check Addons for Platform while IFS=': ' read -r ADDON PARAM; do [ -z "${ADDON}" ] && continue if ! checkAddonExist "${ADDON}" "${PLATFORM}"; then @@ -317,6 +298,13 @@ function arcVersion() { fi done <<<$(readConfigMap "addons" "${USER_CONFIG_FILE}") # Reset Modules + KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.[${PRODUCTVER}].kver" "${P_FILE}")" + # Modify KVER for Epyc7002 + if [ "${PLATFORM}" = "epyc7002" ]; then + KVERP="${PRODUCTVER}-${KVER}" + else + KVERP="${KVER}" + fi echo "$(lsmod | awk '{print $1}' | sort)" >>"${TMP_PATH}/lsmod" cp -f "${ARC_PATH}/include/modulelist" "${TMP_PATH}/modulelist.user" echo -e "\n\n# User Modules" >>"${TMP_PATH}/modulelist.user" @@ -330,7 +318,16 @@ function arcVersion() { [ ! -d "${USER_UP_PATH}" ] && mkdir -p "${USER_UP_PATH}" mv -f "${TMP_PATH}/modulelist.user" "${USER_UP_PATH}/modulelist" dos2unix "${USER_UP_PATH}/modulelist" 2>/dev/null - arcPatch + # Check for Only Version + if [ "${ONLYVERSION}" = "true" ]; then + # Build isn't done + writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" + BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" + ONLYVERSION="" + return 0 + else + arcPatch + fi } ############################################################################### @@ -341,6 +338,7 @@ function arcPatch() { MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")" DT="$(readConfigKey "platforms.${PLATFORM}.dt" "${P_FILE}")" ARCCONF="$(readConfigKey "${MODEL}.serial" "${S_FILE}" 2>/dev/null)" + # Check for Custom Build if [ "${CUSTOM}" = "true" ]; then ARCPATCHPRE="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")" [ -n "${ARCCONF}" ] && ARCPATCH="true" || ARCPATCH="false" @@ -457,6 +455,7 @@ function arcSettings() { sleep 2 getmapSelection fi + # Check for Custom Build if [ "${CUSTOM}" = "false" ]; then dialog --backtitle "$(backtitle)" --colors --title "DSM Addons" \ --infobox "Loading Addons Table..." 3 35 @@ -486,10 +485,11 @@ function arcSettings() { # Config is done writeConfigKey "arc.confdone" "true" "${USER_CONFIG_FILE}" CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")" + # Check for Custom Build if [ "${CUSTOM}" = "false" ]; then # Ask for Build dialog --clear --backtitle "$(backtitle)" --title "Config done" \ - --menu "Build now?" 7 50 0 \ + --menu "Build now?" 5 40 0 \ 1 "Yes - Build Arc Loader now" \ 2 "No - I want to make changes" \ 2>"${TMP_PATH}/resp" @@ -522,6 +522,7 @@ function premake() { deleteConfigKey "modules.mmc_block" "${USER_CONFIG_FILE}" deleteConfigKey "modules.mmc_core" "${USER_CONFIG_FILE}" fi + # Check for Custom Build if [ "${CUSTOM}" = "true" ]; then # Build Loader make @@ -619,17 +620,14 @@ function make() { PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")" PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")" DT="$(readConfigKey "platforms.${PLATFORM}.dt" "${P_FILE}")" - OFFLINE="$(readConfigKey "arc.offline" "${USER_CONFIG_FILE}")" # Cleanup if [ -d "${UNTAR_PAT_PATH}" ]; then rm -rf "${UNTAR_PAT_PATH}" fi mkdir -p "${UNTAR_PAT_PATH}" - # Check for offline Mode - if [ "${OFFLINE}" = "true" ]; then - offlinemake - return 0 - else + # Check for Offline Mode + OFFLINE="$(readConfigKey "arc.offline" "${USER_CONFIG_FILE}")" + if [ "${OFFLINE}" = "false" ]; then # Get PAT Data from Config PAT_URL_CONF="$(readConfigKey "arc.paturl" "${USER_CONFIG_FILE}")" PAT_HASH_CONF="$(readConfigKey "arc.pathash" "${USER_CONFIG_FILE}")" @@ -695,185 +693,115 @@ function make() { fi fi done - if [[ "${PAT_HASH}" != "${PAT_HASH_CONF}" || ! -f "${ORI_ZIMAGE_FILE}" || ! -f "${ORI_RDGZ_FILE}" ]]; then + if [ "${PAT_HASH}" != "${PAT_HASH_CONF}" ] || [ ! -f "${ORI_ZIMAGE_FILE}" ] || [ ! -f "${ORI_RDGZ_FILE}" ]; then writeConfigKey "arc.paturl" "${PAT_URL}" "${USER_CONFIG_FILE}" writeConfigKey "arc.pathash" "${PAT_HASH}" "${USER_CONFIG_FILE}" # Check for existing Files DSM_FILE="${UNTAR_PAT_PATH}/${PAT_HASH}.tar" - # Get new Files - DSM_URL="https://raw.githubusercontent.com/AuxXxilium/arc-dsm/main/files/${MODELID/+/%2B}/${PRODUCTVER}/${PAT_HASH}.tar" - STATUS=$(curl --insecure -s -w "%{http_code}" -L "${DSM_URL}" -o "${DSM_FILE}") - if [[ $? -ne 0 || ${STATUS} -ne 200 ]]; then - dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ - --infobox "No DSM Image found!\nTry Syno Link." 0 0 - sleep 3 - # Grep PAT_URL - PAT_FILE="${TMP_PATH}/${PAT_HASH}.pat" - STATUS=$(curl -k -w "%{http_code}" -L "${PAT_URL}" -o "${PAT_FILE}" --progress-bar) + if [ -f "${DSM_FILE}" ]; then + tar -xf "${DSM_FILE}" -C "${UNTAR_PAT_PATH}" >"${LOG_FILE}" 2>&1 + else + # Get new Files + DSM_URL="https://raw.githubusercontent.com/AuxXxilium/arc-dsm/main/files/${MODELID/+/%2B}/${PRODUCTVER}/${PAT_HASH}.tar" + STATUS=$(curl --insecure -s -w "%{http_code}" -L "${DSM_URL}" -o "${DSM_FILE}") if [[ $? -ne 0 || ${STATUS} -ne 200 ]]; then dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ - --infobox "No DSM Image found!\nExit." 0 0 + --infobox "No DSM Image found!\nTry Syno Link." 0 0 + sleep 3 + # Grep PAT_URL + PAT_FILE="${TMP_PATH}/${PAT_HASH}.pat" + STATUS=$(curl -k -w "%{http_code}" -L "${PAT_URL}" -o "${PAT_FILE}" --progress-bar) + if [[ $? -ne 0 || ${STATUS} -ne 200 ]]; then + dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ + --infobox "No DSM Image found!\nExit." 0 0 + sleep 5 + return 1 + fi + # Extract Files + if extractDSMFiles "${PAT_FILE}" "${UNTAR_PAT_PATH}"; then + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "DSM Extraction successful!" 0 0 + else + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "DSM Extraction failed!\nExit." 0 0 + sleep 5 + return 1 + fi + fi + fi + fi + elif [ "${OFFLINE}" = "true" ]; then + if [ -f "${ORI_ZIMAGE_FILE}" ] && [ -f "${ORI_RDGZ_FILE}" ] && [ -f "${MOD_ZIMAGE_FILE}" ] && [ -f "${MOD_RDGZ_FILE}" ]; then + dialog --backtitle "$(backtitle)" --title "DSM Data" --aspect 18 \ + --infobox "DSM Model Data found." 0 0 + else + # Check for existing Files + mkdir -p "${UPLOAD_PATH}" + # Get new Files + dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ + --msgbox "Upload your DSM .pat File to /tmp/upload.\nUse SSH/SFTP to connect to ${IPCON}\nor use Webfilebrowser: ${IPCON}:7304.\nUser: root | Password: arc\nPress OK to continue!" 0 0 + # Grep PAT_FILE + PAT_FILE=$(ls ${UPLOAD_PATH}/*.pat) + if [ ! -f "${PAT_FILE}" ]; then + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "No DSM Image found!\nExit." 0 0 + sleep 5 + return 1 + else + # Remove PAT Data for Offline + writeConfigKey "arc.paturl" "" "${USER_CONFIG_FILE}" + writeConfigKey "arc.pathash" "" "${USER_CONFIG_FILE}" + # Extract Files + if extractDSMFiles "${PAT_FILE}" "${UNTAR_PAT_PATH}"; then + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "DSM Extraction successful!" 0 0 + else + dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ + --infobox "DSM Extraction failed!\nExit." 0 0 sleep 5 return 1 fi - # Extract Files - header=$(od -bcN2 ${PAT_FILE} | head -1 | awk '{print $3}') - case ${header} in - 105) - isencrypted="no" - ;; - 213) - isencrypted="no" - ;; - 255) - isencrypted="yes" - ;; - *) - echo -e "Could not determine if pat file is encrypted or not, maybe corrupted, try again!" - ;; - esac - if [ "${isencrypted}" = "yes" ]; then - # Uses the extractor to untar PAT file - LD_LIBRARY_PATH="${EXTRACTOR_PATH}" "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" "${PAT_FILE}" "${UNTAR_PAT_PATH}" - else - # Untar PAT file - tar -xf "${PAT_FILE}" -C "${UNTAR_PAT_PATH}" >"${LOG_FILE}" 2>&1 - fi - # Cleanup PAT Download - rm -f "${PAT_FILE}" - elif [ -f "${DSM_FILE}" ]; then - tar -xf "${DSM_FILE}" -C "${UNTAR_PAT_PATH}" >"${LOG_FILE}" 2>&1 - elif [ ! -f "${UNTAR_PAT_PATH}/zImage" ]; then - dialog --backtitle "$(backtitle)" --title "DSM Download" --aspect 18 \ - --infobox "ERROR: No DSM Image found!" 0 0 - sleep 5 - return 1 fi - # Copy DSM Files to Locations if DSM Files not found - cp -f "${UNTAR_PAT_PATH}/grub_cksum.syno" "${PART1_PATH}" - cp -f "${UNTAR_PAT_PATH}/GRUB_VER" "${PART1_PATH}" - cp -f "${UNTAR_PAT_PATH}/grub_cksum.syno" "${PART2_PATH}" - cp -f "${UNTAR_PAT_PATH}/GRUB_VER" "${PART2_PATH}" - cp -f "${UNTAR_PAT_PATH}/zImage" "${ORI_ZIMAGE_FILE}" - cp -f "${UNTAR_PAT_PATH}/rd.gz" "${ORI_RDGZ_FILE}" - rm -rf "${UNTAR_PAT_PATH}" - fi - ( - livepatch - sleep 3 - ) 2>&1 | dialog --backtitle "$(backtitle)" --colors --title "Build Loader" \ - --progressbox "Doing the Magic..." 20 70 - if [[ -f "${ORI_ZIMAGE_FILE}" && -f "${ORI_RDGZ_FILE}" && -f "${MOD_ZIMAGE_FILE}" && -f "${MOD_RDGZ_FILE}" ]]; then - # Build is done - writeConfigKey "arc.builddone" "true" "${USER_CONFIG_FILE}" - BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" - if grep -q "automated_arc" /proc/cmdline; then - if [ "${CUSTOM}" = "false" ]; then - rm -f "${PART3_PATH}/automated" - fi - boot && exit 0 - else - # Ask for Boot - dialog --clear --backtitle "$(backtitle)" --title "Build done"\ - --menu "Boot now?" 0 0 0 \ - 1 "Yes - Boot Arc Loader now" \ - 2 "No - I want to make changes" \ - 2>"${TMP_PATH}/resp" - resp=$(cat ${TMP_PATH}/resp) - [ -z "${resp}" ] && return 1 - if [ ${resp} -eq 1 ]; then - boot && exit 0 - elif [ ${resp} -eq 2 ]; then - return 0 - fi - fi - else - dialog --backtitle "$(backtitle)" --title "Error" --aspect 18 \ - --infobox "Build failed!\nPlease check your Connection and Diskspace!" 0 0 - sleep 5 - return 1 fi fi -} - -############################################################################### -# Building Loader Offline -function offlinemake() { - if [[ -f "${ORI_ZIMAGE_FILE}" && -f "${ORI_RDGZ_FILE}" && -f "${MOD_ZIMAGE_FILE}" && -f "${MOD_RDGZ_FILE}" ]]; then - dialog --backtitle "$(backtitle)" --title "DSM Data" --aspect 18 \ - --infobox "DSM Model Data found." 0 0 + # Copy DSM Files to Locations if DSM Files not found + if copyDSMFiles "${UNTAR_PAT_PATH}"; then + dialog --backtitle "$(backtitle)" --title "DSM Copy" --aspect 18 \ + --infobox "DSM Copy successful!" 0 0 + rm -rf "${UNTAR_PAT_PATH}" else - # Check for existing Files - mkdir -p "${UPLOAD_PATH}" - # Get new Files - dialog --backtitle "$(backtitle)" --title "DSM Upload" --aspect 18 \ - --msgbox "Upload your DSM .pat File to /tmp/upload.\nUse SSH/SFTP to connect to ${IPCON}\nor use Webfilebrowser: ${IPCON}:7304.\nUser: root | Password: arc\nPress OK to continue!" 0 0 - # Grep PAT_FILE - PAT_FILE=$(ls ${UPLOAD_PATH}/*.pat) - if [ ! -f "${PAT_FILE}" ]; then - dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ - --infobox "No DSM Image found!\nExit." 0 0 - sleep 5 - return 1 - else - # Remove PAT Data for Offline - writeConfigKey "arc.paturl" "" "${USER_CONFIG_FILE}" - writeConfigKey "arc.pathash" "" "${USER_CONFIG_FILE}" - # Extract Files - header=$(od -bcN2 ${PAT_FILE} | head -1 | awk '{print $3}') - case ${header} in - 105) - isencrypted="no" - ;; - 213) - isencrypted="no" - ;; - 255) - isencrypted="yes" - ;; - *) - echo -e "Could not determine if pat file is encrypted or not, maybe corrupted, try again!" - ;; - esac - if [ "${isencrypted}" = "yes" ]; then - # Uses the extractor to untar PAT file - LD_LIBRARY_PATH="${EXTRACTOR_PATH}" "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" "${PAT_FILE}" "${UNTAR_PAT_PATH}" - else - # Untar PAT file - tar -xf "${PAT_FILE}" -C "${UNTAR_PAT_PATH}" >"${LOG_FILE}" 2>&1 - fi - # Cleanup old PAT - rm -f "${PAT_FILE}" - dialog --backtitle "$(backtitle)" --title "DSM Extraction" --aspect 18 \ - --msgbox "DSM Extraction successful!" 0 0 - # Copy DSM Files to Locations if DSM Files not found - cp -f "${UNTAR_PAT_PATH}/grub_cksum.syno" "${PART1_PATH}" - cp -f "${UNTAR_PAT_PATH}/GRUB_VER" "${PART1_PATH}" - cp -f "${UNTAR_PAT_PATH}/grub_cksum.syno" "${PART2_PATH}" - cp -f "${UNTAR_PAT_PATH}/GRUB_VER" "${PART2_PATH}" - cp -f "${UNTAR_PAT_PATH}/zImage" "${ORI_ZIMAGE_FILE}" - cp -f "${UNTAR_PAT_PATH}/rd.gz" "${ORI_RDGZ_FILE}" - rm -rf "${UNTAR_PAT_PATH}" - fi + dialog --backtitle "$(backtitle)" --title "DSM Copy" --aspect 18 \ + --infobox "DSM Copy failed!\nExit." 0 0 + sleep 5 + return 1 fi ( livepatch sleep 3 ) 2>&1 | dialog --backtitle "$(backtitle)" --colors --title "Build Loader" \ --progressbox "Doing the Magic..." 20 70 + arcFinish +} + +############################################################################### +# Finish Building Loader +function arcFinish() { + # Verify Files exist if [[ -f "${ORI_ZIMAGE_FILE}" && -f "${ORI_RDGZ_FILE}" && -f "${MOD_ZIMAGE_FILE}" && -f "${MOD_RDGZ_FILE}" ]]; then # Build is done writeConfigKey "arc.builddone" "true" "${USER_CONFIG_FILE}" BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" + # Check for Automated Mode if grep -q "automated_arc" /proc/cmdline; then + # Check for Custom Build if [ "${CUSTOM}" = "false" ]; then - rm -f "${PART3_PATH}/automated" + [ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated" fi boot && exit 0 else # Ask for Boot - dialog --clear --backtitle "$(backtitle)" \ - --menu "Build done. Boot now?" 0 0 0 \ + dialog --clear --backtitle "$(backtitle)" --title "Build done"\ + --menu "Boot now?" 5 40 0 \ 1 "Yes - Boot Arc Loader now" \ 2 "No - I want to make changes" \ 2>"${TMP_PATH}/resp" @@ -887,7 +815,7 @@ function offlinemake() { fi else dialog --backtitle "$(backtitle)" --title "Error" --aspect 18 \ - --infobox "Build failed!\nPlease check your Diskspace!" 0 0 + --infobox "Build failed!\nPlease check your Connection and Diskspace!" 0 0 sleep 5 return 1 fi @@ -943,7 +871,9 @@ function boot() { ############################################################################### ############################################################################### # Main loop +# Check for Automated Mode if grep -q "automated_arc" /proc/cmdline; then + # Check for Custom Build if [ "${CUSTOM}" = "true" ]; then arcVersion else diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index a1483fd5..226380b1 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -350,6 +350,7 @@ function livepatch() { writeConfigKey "ramdisk-hash" "${RAMDISK_HASH_CUR}" "${USER_CONFIG_FILE}" FAIL=0 fi + OFFLINE="$(readConfigKey "arc.offline" "${USER_CONFIG_FILE}")" if [ "${OFFLINE}" = "false" ]; then # Looking for Update if [ ${FAIL} -eq 1 ]; then @@ -426,21 +427,57 @@ function rebootTo() { # Copy DSM files to the boot partition # 1 - DSM root path function copyDSMFiles() { - if [ -f "${1}/VERSION" ] && [ -f "${1}/grub_cksum.syno" ] && [ -f "${1}/GRUB_VER" ] && [ -f "${1}/zImage" ] && [ -f "${1}/rd.gz" ]; then - # Remove old model files - rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/grub_cksum.syno" "${PART2_PATH}/GRUB_VER" - rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" - # Remove old build files - rm -f "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null - # Copy new model files - cp -f "${1}/grub_cksum.syno" "${PART1_PATH}" - cp -f "${1}/GRUB_VER" "${PART1_PATH}" - cp -f "${1}/grub_cksum.syno" "${PART2_PATH}" - cp -f "${1}/GRUB_VER" "${PART2_PATH}" - cp -f "${1}/zImage" "${ORI_ZIMAGE_FILE}" - cp -f "${1}/rd.gz" "${ORI_RDGZ_FILE}" + if [ -f "${ORI_ZIMAGE_FILE}" ] || [ ! -f "${ORI_RDGZ_FILE}" ] || [ ! -f "${MOD_ZIMAGE_FILE}" ] || [ ! -f "${MOD_RDGZ_FILE}" ]; then + if [ -f "${1}/grub_cksum.syno" ] && [ -f "${1}/GRUB_VER" ] && [ -f "${1}/zImage" ] && [ -f "${1}/rd.gz" ]; then + # Remove old model files + rm -f "${PART1_PATH}/grub_cksum.syno" "${PART1_PATH}/GRUB_VER" "${PART2_PATH}/grub_cksum.syno" "${PART2_PATH}/GRUB_VER" + rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" + # Remove old build files + rm -f "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null + # Copy new model files + cp -f "${1}/grub_cksum.syno" "${PART1_PATH}" + cp -f "${1}/GRUB_VER" "${PART1_PATH}" + cp -f "${1}/grub_cksum.syno" "${PART2_PATH}" + cp -f "${1}/GRUB_VER" "${PART2_PATH}" + cp -f "${1}/zImage" "${ORI_ZIMAGE_FILE}" + cp -f "${1}/rd.gz" "${ORI_RDGZ_FILE}" + return 0 + else + return 1 + fi + else + return 0 + fi +} + +############################################################################### +# Extract DSM files +# 1 - PAT File +# 2 - Destination Path +function extractDSMFiles() { + header=$(od -bcN2 ${1} | head -1 | awk '{print $3}') + case ${header} in + 105) + isencrypted="no" + ;; + 213) + isencrypted="no" + ;; + 255) + isencrypted="yes" + ;; + *) + echo -e "Could not determine if pat file is encrypted or not, maybe corrupted, try again!" + ;; + esac + if [ "${isencrypted}" = "yes" ]; then + # Uses the extractor to untar PAT file + LD_LIBRARY_PATH="${EXTRACTOR_PATH}" "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" "${1}" "${2}" >"${LOG_FILE}" 2>&1 return 0 else - return 1 + # Untar PAT file + tar -xf "${1}" -C "${2}" >"${LOG_FILE}" 2>&1 + return 0 fi + return 1 } \ No newline at end of file