dsm: format job

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2023-07-05 17:46:53 +02:00
parent d82ff66d6f
commit 10ae67063b

View File

@ -14,29 +14,30 @@ function getDSM() {
UNTAR_PAT_PATH="${CACHE_PATH}/${MODEL}/${VERSION}"
DESTINATION="${DSMPATH}/${MODEL}/${VERSION}"
DESTINATIONFILES="${FILESPATH}/${MODEL}/${VERSION}"
# Make Destinations
mkdir -p "${DESTINATION}"
mkdir -p "${DESTINATIONFILES}"
# Grep Values
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)"
echo "${MODEL} ${VERSION}"
# Grep PAT_URL
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')
PAT_URL="${PAT_URL%%\?*}"
echo "${PAT_URL}"
echo "${HASH}"
OLDURL="$(cat "${DESTINATION}/pat_url")"
OLDHASH="$(cat "${DESTINATION}/pat_hash")"
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
if [ "${HASH}" != "${OLDHASH}" ] || [ "${PAT_URL}" != "${OLDURL}" ]; then
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)
@ -45,14 +46,13 @@ function getDSM() {
echo "Error downloading"
fi
if [ -f "${PAT_PATH}" ]; then
# Export Values
echo "${HASH}" >"${DESTINATION}/pat_hash"
echo "${PAT_URL}" >"${DESTINATION}/pat_url"
# Extract Files
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)
@ -71,7 +71,6 @@ function getDSM() {
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
@ -87,17 +86,16 @@ function getDSM() {
echo "Error extracting"
fi
fi
# Export Hash
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"
# Copy Files to Destination
echo -n "Copying files: "
cp "${UNTAR_PAT_PATH}/grub_cksum.syno" "${DESTINATION}"
cp "${UNTAR_PAT_PATH}/GRUB_VER" "${DESTINATION}"
@ -110,19 +108,16 @@ function getDSM() {
rm -f "${PAT_PATH}"
rm -rf "${UNTAR_PAT_PATH}"
fi
echo "DSM extract complete: ${MODEL}_${VERSION}"
else
echo "DSM extract Error: ${MODEL}_${VERSION}"
fi
cd ${HOME}
done <"${VERSIONSFILE}"
rm -f "${VERSIONSFILE}"
}
# Init DSM Files
HOME=$(pwd)
CONFIGS="./configs"
rm -f "${CONFIGS}"
@ -140,6 +135,6 @@ while read MODEL; do
VERSIONSFILE="${CACHE_PATCH}/versions.yml"
getDSM
done < <(find "${CONFIGS}" -maxdepth 1 -name \*.yml | sort)
# Cleanup DSM Files
rm -rf "${CACHE_PATH}/dl"
rm -rf "${CONFIGS}"