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() {
|
|
|
|
VERSIONS="$(readConfigEntriesArray "productvers" "${CONFIGS}/${MODEL}.yml" | sort -r)"
|
|
|
|
echo "${VERSIONS}" >"${VERSIONSFILE}"
|
|
|
|
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-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 22:28:38 +07:00
|
|
|
PAT_MODEL=$(echo "${MODEL}" | sed -e 's/\./%2E/g' -e 's/+/%2B/g')
|
|
|
|
PAT_MAJOR=$(echo "${VERSION}" | cut -b 1)
|
|
|
|
PAT_MINOR=$(echo "${VERSION}" | cut -b 3)
|
2023-06-23 02:59:30 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
echo "${MODEL} ${VERSION}"
|
|
|
|
|
2023-07-05 22:28:38 +07:00
|
|
|
PAT_URL=$(curl -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${PAT_MODEL}&major=${PAT_MAJOR}&minor=${PAT_MINOR}" | jq -r '.info.system.detail[0].items[0].files[0].url')
|
|
|
|
HASH=$(curl -skL "https://www.synology.com/api/support/findDownloadInfo?lang=en-us&product=${PAT_MODEL}&major=${PAT_MAJOR}&minor=${PAT_MINOR}" | jq -r '.info.system.detail[0].items[0].files[0].checksum')
|
|
|
|
echo "${PAT_URL}"
|
|
|
|
echo "${HASH}"
|
2023-07-05 21:51:54 +07:00
|
|
|
PAT_URL=${PAT_URL%%\?*}
|
2023-06-23 02:59:30 +07:00
|
|
|
|
2023-07-05 22:28:38 +07:00
|
|
|
OLDURL="$(cat "${DESTINATION}/pat_url")"
|
|
|
|
OLDHASH="$(cat "${DESTINATION}/pat_hash")"
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
if [ "${HASH}" != "${OLDHASH}" ] || [ "${PAT_URL}" != "${OLDURL}" ]; then
|
2023-06-24 00:15:48 +07:00
|
|
|
|
2023-07-05 22:28:38 +07:00
|
|
|
echo "${HASH}" >"${DESTINATION}/pat_hash"
|
|
|
|
echo "${PAT_URL}" >"${DESTINATION}/pat_url"
|
2023-06-24 00:15:48 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
rm -rf "${UNTAR_PAT_PATH}"
|
|
|
|
mkdir -p "${UNTAR_PAT_PATH}"
|
|
|
|
echo -n "Disassembling ${PAT_FILE}: "
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
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
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
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"
|
2023-06-22 00:21:33 +07:00
|
|
|
fi
|
2023-07-05 21:51:54 +07:00
|
|
|
fi
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
echo -n "Checking hash of zImage: "
|
|
|
|
HASH=$(sha256sum ${UNTAR_PAT_PATH}/zImage | awk '{print$1}')
|
|
|
|
echo "OK"
|
2023-07-05 22:28:38 +07:00
|
|
|
echo "${HASH}" >"${DESTINATION}/zImage_hash"
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +07:00
|
|
|
echo -n "Checking hash of ramdisk: "
|
|
|
|
HASH=$(sha256sum ${UNTAR_PAT_PATH}/rd.gz | awk '{print$1}')
|
|
|
|
echo "OK"
|
2023-07-05 22:28:38 +07:00
|
|
|
echo "${HASH}" >"${DESTINATION}/ramdisk_hash"
|
2023-06-21 21:38:13 +07:00
|
|
|
|
2023-07-05 21:51:54 +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}"
|
|
|
|
tar -cf "${DESTINATIONFILES}/dsm.tar" .
|
|
|
|
rm -f "${PAT_PATH}"
|
|
|
|
rm -rf "${UNTAR_PAT_PATH}"
|
2023-07-05 22:17:37 +07:00
|
|
|
echo "DSM extract complete: ${MODEL}_${VERSION}"
|
2023-07-05 21:51:54 +07:00
|
|
|
else
|
2023-07-05 22:17:37 +07:00
|
|
|
echo "DSM extract Error: ${MODEL}_${VERSION}"
|
2023-06-22 00:21:33 +07:00
|
|
|
fi
|
2023-06-23 02:59:30 +07:00
|
|
|
cd ${HOME}
|
2023-07-05 22:11:46 +07:00
|
|
|
done <"${VERSIONSFILE}"
|
2023-07-05 21:51:54 +07:00
|
|
|
rm -f "${VERSIONSFILE}"
|
|
|
|
}
|
|
|
|
|
|
|
|
HOME=$(pwd)
|
|
|
|
CONFIGS="./configs"
|
2023-07-05 22:17:37 +07:00
|
|
|
rm -f "${CONFIGS}"
|
|
|
|
mkdir -p "${CONFIGS}"
|
2023-07-05 22:21:20 +07:00
|
|
|
git clone https://github.com/AuxXxilium/arc-configs -b dev "${CONFIGS}"
|
2023-07-05 21:51:54 +07:00
|
|
|
while read MODEL; do
|
|
|
|
MODEL="$(basename ${MODEL})"
|
|
|
|
MODEL="${MODEL::-4}"
|
|
|
|
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"
|
|
|
|
VERSIONSFILE="${CACHE_PATCH}/versions.yml"
|
|
|
|
getDSM
|
|
|
|
done < <(find "${CONFIGS}" -maxdepth 1 -name \*.yml | sort)
|
2023-06-22 00:21:33 +07:00
|
|
|
|
2023-07-05 22:13:17 +07:00
|
|
|
rm -rf "${CACHE_PATH}/dl"
|
|
|
|
rm -rf "${CONFIGS}"
|