2023-06-21 21:38:13 +07:00
|
|
|
#!/usr/bin/bash
|
2023-06-23 02:59:30 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
function readConfigEntriesArray() {
|
|
|
|
yq eval '.'${1}' | explode(.) | to_entries | map([.key])[] | .[]' "${2}"
|
|
|
|
}
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
function getDSM() {
|
2024-05-10 02:42:00 +07:00
|
|
|
MODEL="${1}"
|
|
|
|
PLATFORM="${2}"
|
2024-05-10 02:21:55 +07:00
|
|
|
VERSIONS="$(readConfigEntriesArray "platforms.${PLATFORM}.productvers" "${P_FILE}" | sort -r)"
|
2024-05-10 02:42:00 +07:00
|
|
|
echo "${VERSIONS}" >"${TMP_PATH}/versions"
|
2023-07-05 21:51:54 +07:00
|
|
|
while IFS= read -r line; do
|
|
|
|
VERSION="${line}"
|
|
|
|
PAT_FILE="${MODEL}_${VERSION}.pat"
|
|
|
|
PAT_PATH="${CACHE_PATH}/dl/${PAT_FILE}"
|
|
|
|
UNTAR_PAT_PATH="${CACHE_PATH}/${MODEL}/${VERSION}"
|
|
|
|
DESTINATION="${DSMPATH}/${MODEL}/${VERSION}"
|
|
|
|
DESTINATIONFILES="${FILESPATH}/${MODEL}/${VERSION}"
|
2023-07-05 22:46:53 +07:00
|
|
|
# Make Destinations
|
2023-07-05 22:39:30 +07:00
|
|
|
mkdir -p "${DESTINATION}"
|
|
|
|
mkdir -p "${DESTINATIONFILES}"
|
2023-07-05 21:51:54 +07:00
|
|
|
echo "${MODEL} ${VERSION}"
|
2024-06-09 22:35:23 +07:00
|
|
|
echo "" >>"${TMP_PATH}/dsmdata.yml"
|
|
|
|
echo "${MODEL} ${VERSION}" >>"${TMP_PATH}/dsmdata.yml"
|
2023-07-05 22:46:53 +07:00
|
|
|
# Grep PAT_URL
|
2023-10-20 02:27:04 +07:00
|
|
|
PAT_URL="$(curl -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${MODEL/+/%2B}&major=${VERSION%%.*}&minor=${VERSION##*.}" | jq -r '.info.system.detail[0].items[0].files[0].url')"
|
|
|
|
PAT_HASH="$(curl -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${MODEL/+/%2B}&major=${VERSION%%.*}&minor=${VERSION##*.}" | jq -r '.info.system.detail[0].items[0].files[0].checksum')"
|
2023-07-05 22:39:30 +07:00
|
|
|
PAT_URL="${PAT_URL%%\?*}"
|
2023-07-05 22:28:38 +07:00
|
|
|
echo "${PAT_URL}"
|
2024-06-09 22:35:23 +07:00
|
|
|
echo "URL: ${PAT_URL}" >>"${TMP_PATH}/dsmdata.yml"
|
2023-07-08 01:58:08 +07:00
|
|
|
echo "${PAT_HASH}"
|
2024-06-09 22:35:23 +07:00
|
|
|
echo "HASH: ${PAT_HASH}" >>"${TMP_PATH}/dsmdata.yml"
|
2023-07-05 22:46:53 +07:00
|
|
|
if [ -f "${DESTINATION}/pat_url" ] && [ -f "${DESTINATION}/pat_hash" ]; then
|
|
|
|
OLDURL="$(cat "${DESTINATION}/pat_url")"
|
|
|
|
OLDHASH="$(cat "${DESTINATION}/pat_hash")"
|
|
|
|
else
|
|
|
|
OLDURL="0"
|
|
|
|
OLDHASH="0"
|
|
|
|
fi
|
|
|
|
# Check for Update
|
2023-07-08 01:58:08 +07:00
|
|
|
if [ "${PAT_HASH}" != "${OLDHASH}" ] || [ "${PAT_URL}" != "${OLDURL}" ]; then
|
2023-07-05 22:39:30 +07:00
|
|
|
mkdir -p "${CACHE_PATH}/dl"
|
|
|
|
echo "Downloading ${PAT_FILE}"
|
|
|
|
# Discover remote file size
|
|
|
|
STATUS=$(curl -k -w "%{http_code}" -L "${PAT_URL}" -o "${PAT_PATH}" --progress-bar)
|
|
|
|
if [ $? -ne 0 -o ${STATUS} -ne 200 ]; then
|
|
|
|
rm "${PAT_PATH}"
|
|
|
|
echo "Error downloading"
|
|
|
|
fi
|
|
|
|
if [ -f "${PAT_PATH}" ]; then
|
2023-07-05 22:46:53 +07:00
|
|
|
# Export Values
|
2023-07-08 01:58:08 +07:00
|
|
|
echo "${PAT_HASH}" >"${DESTINATION}/pat_hash"
|
2023-07-05 22:39:30 +07:00
|
|
|
echo "${PAT_URL}" >"${DESTINATION}/pat_url"
|
2023-07-05 22:46:53 +07:00
|
|
|
# Extract Files
|
2023-07-05 22:39:30 +07:00
|
|
|
rm -rf "${UNTAR_PAT_PATH}"
|
|
|
|
mkdir -p "${UNTAR_PAT_PATH}"
|
|
|
|
echo -n "Disassembling ${PAT_FILE}: "
|
|
|
|
header=$(od -bcN2 ${PAT_PATH} | head -1 | awk '{print $3}')
|
|
|
|
case ${header} in
|
|
|
|
105)
|
|
|
|
echo "Uncompressed tar"
|
|
|
|
isencrypted="no"
|
|
|
|
;;
|
|
|
|
213)
|
|
|
|
echo "Compressed tar"
|
|
|
|
isencrypted="no"
|
|
|
|
;;
|
|
|
|
255)
|
|
|
|
echo "Encrypted"
|
|
|
|
isencrypted="yes"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo -e "Could not determine if pat file is encrypted or not, maybe corrupted, try again!"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
if [ "${isencrypted}" = "yes" ]; then
|
|
|
|
# Check existance of extractor
|
|
|
|
if [ -f "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" ]; then
|
|
|
|
echo "Extractor cached."
|
|
|
|
fi
|
|
|
|
# Uses the extractor to untar pat file
|
|
|
|
echo "Extracting..."
|
|
|
|
LD_LIBRARY_PATH="${EXTRACTOR_PATH}" "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" "${PAT_PATH}" "${UNTAR_PAT_PATH}"
|
|
|
|
else
|
|
|
|
echo "Extracting..."
|
|
|
|
tar -xf "${PAT_PATH}" -C "${UNTAR_PAT_PATH}"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "Error extracting"
|
|
|
|
fi
|
2023-06-22 00:21:33 +07:00
|
|
|
fi
|
2023-07-05 22:46:53 +07:00
|
|
|
# Export Hash
|
2023-07-05 22:39:30 +07:00
|
|
|
echo -n "Checking hash of zImage: "
|
|
|
|
HASH=$(sha256sum ${UNTAR_PAT_PATH}/zImage | awk '{print$1}')
|
|
|
|
echo "OK"
|
|
|
|
echo "${HASH}" >"${DESTINATION}/zImage_hash"
|
|
|
|
echo -n "Checking hash of ramdisk: "
|
|
|
|
HASH=$(sha256sum ${UNTAR_PAT_PATH}/rd.gz | awk '{print$1}')
|
|
|
|
echo "OK"
|
|
|
|
echo "${HASH}" >"${DESTINATION}/ramdisk_hash"
|
2023-07-05 22:46:53 +07:00
|
|
|
# Copy Files to Destination
|
2023-07-05 22:39:30 +07:00
|
|
|
echo -n "Copying files: "
|
|
|
|
cp "${UNTAR_PAT_PATH}/grub_cksum.syno" "${DESTINATION}"
|
|
|
|
cp "${UNTAR_PAT_PATH}/GRUB_VER" "${DESTINATION}"
|
|
|
|
cp "${UNTAR_PAT_PATH}/grub_cksum.syno" "${DESTINATION}"
|
|
|
|
cp "${UNTAR_PAT_PATH}/GRUB_VER" "${DESTINATION}"
|
|
|
|
cp "${UNTAR_PAT_PATH}/zImage" "${DESTINATION}"
|
|
|
|
cp "${UNTAR_PAT_PATH}/rd.gz" "${DESTINATION}"
|
|
|
|
cd "${DESTINATION}"
|
2023-10-20 02:27:04 +07:00
|
|
|
tar -cf "${DESTINATIONFILES}/${PAT_HASH}.tar" .
|
2023-07-05 22:39:30 +07:00
|
|
|
rm -f "${PAT_PATH}"
|
|
|
|
rm -rf "${UNTAR_PAT_PATH}"
|
2023-07-05 21:51:54 +07:00
|
|
|
fi
|
2023-07-08 01:55:47 +07:00
|
|
|
echo "DSM Extraction complete: ${MODEL}_${VERSION}"
|
2023-07-05 21:51:54 +07:00
|
|
|
else
|
2023-07-08 01:55:47 +07:00
|
|
|
echo "No DSM Update found: ${MODEL}_${VERSION}"
|
2023-06-22 00:21:33 +07:00
|
|
|
fi
|
2023-06-23 02:59:30 +07:00
|
|
|
cd ${HOME}
|
2024-05-10 02:42:00 +07:00
|
|
|
done <<<$(cat "${TMP_PATH}/versions")
|
|
|
|
rm -f "${TMP_PATH}/versions"
|
2023-07-05 21:51:54 +07:00
|
|
|
}
|
|
|
|
|
2023-07-05 22:46:53 +07:00
|
|
|
# Init DSM Files
|
2023-07-05 21:51:54 +07:00
|
|
|
HOME=$(pwd)
|
|
|
|
CONFIGS="./configs"
|
2024-05-10 02:21:55 +07:00
|
|
|
TMP_PATH="${HOME}/tmp"
|
|
|
|
mkdir -p "${TMP_PATH}"
|
2023-07-05 22:17:37 +07:00
|
|
|
rm -f "${CONFIGS}"
|
|
|
|
mkdir -p "${CONFIGS}"
|
2024-06-09 23:09:08 +07:00
|
|
|
touch "${TMP_PATH}/dsmdata.yml"
|
2024-05-05 17:20:37 +07:00
|
|
|
TAG="$(curl --insecure -m 5 -s https://api.github.com/repos/AuxXxilium/arc-configs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}')"
|
|
|
|
curl --insecure -s -w "%{http_code}" -L "https://github.com/AuxXxilium/arc-configs/releases/download/${TAG}/configs.zip" -o "./configs.zip"
|
|
|
|
unzip -oq "./configs.zip" -d "${CONFIGS}" >/dev/null 2>&1
|
2024-05-10 02:21:55 +07:00
|
|
|
P_FILE="${CONFIGS}/platforms.yml"
|
|
|
|
PS="$(readConfigEntriesArray "platforms" "${P_FILE}" | sort)"
|
|
|
|
MJ="$(python include/functions.py getmodels -p "${PS[*]}")"
|
|
|
|
if [[ -z "${MJ}" || "${MJ}" = "[]" ]]; then
|
|
|
|
dialog --backtitle "$(backtitle)" --title "Model" --title "Model" \
|
|
|
|
--msgbox "Failed to get models, please try again!" 0 0
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo -n "" >"${TMP_PATH}/modellist"
|
|
|
|
echo "${MJ}" | jq -c '.[]' | while read -r item; do
|
|
|
|
name=$(echo "$item" | jq -r '.name')
|
|
|
|
arch=$(echo "$item" | jq -r '.arch')
|
|
|
|
echo "${name} ${arch}" >>"${TMP_PATH}/modellist"
|
|
|
|
done
|
|
|
|
while read -r M A; do
|
2023-07-05 21:51:54 +07:00
|
|
|
CACHE_PATH="${HOME}/cache"
|
|
|
|
RAMDISK_PATH="${CACHE_PATH}/ramdisk"
|
|
|
|
EXTRACTOR_PATH="${CACHE_PATH}/extractor"
|
|
|
|
EXTRACTOR_BIN="syno_extract_system_patch"
|
|
|
|
DSMPATH="${HOME}/dsm"
|
|
|
|
FILESPATH="${HOME}/files"
|
2024-06-09 22:35:23 +07:00
|
|
|
MODEL=$(echo ${M} | sed 's/d$/D/; s/rp$/RP/; s/rp+/RP+/')
|
|
|
|
getDSM "${MODEL}" "${A}"
|
2024-05-10 02:21:55 +07:00
|
|
|
done <<<$(cat "${TMP_PATH}/modellist")
|
2024-06-09 22:35:23 +07:00
|
|
|
cp -f "${TMP_PATH}/dsmdata.yml" "${HOME}/dsmdata.yml"
|
2023-07-05 22:46:53 +07:00
|
|
|
# Cleanup DSM Files
|
2023-07-05 22:13:17 +07:00
|
|
|
rm -rf "${CACHE_PATH}/dl"
|
2024-05-10 02:42:00 +07:00
|
|
|
rm -rf "${CONFIGS}"
|
2024-06-09 23:09:08 +07:00
|
|
|
rm -rf "${TMP_PATH}"
|