dsm: update job

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2023-07-05 16:51:54 +02:00
parent b4b3db211f
commit 7097356a08
2 changed files with 104 additions and 133 deletions

View File

@ -22,22 +22,10 @@ on:
description: 'clean models'
default: false
type: boolean
newbuild:
description: 'add new build'
default: false
type: boolean
version:
description: '7.2'
required: false
type: string
buildupdated:
description: '64570-1'
required: false
type: string
build:
description: '64570'
required: false
type: string
jobs:
dsm-files:
@ -61,22 +49,12 @@ jobs:
run: |
sudo rm -rf ./files
sudo rm -rf ./dsm
sudo rm -f ./models.yml
- name: Clean Models
if: inputs.cleanmodels == true
run: |
sudo rm -f ./models.yml
- name: Models
if: inputs.newbuild == true
run: |
touch "./models.yml"
input_file="model.yml"
while read line
do
echo "${{ inputs.version }} ${{ inputs.buildupdated }} ${line} ${{ inputs.build }}" >>"./models.yml"
done < "$input_file"
sudo rm -f ./configs
git clone https://github.com/AuxXxilium/arc-configs -b main configs
- name: Update
run: |

211
update.sh
View File

@ -1,127 +1,120 @@
#!/usr/bin/bash
HOME=$(pwd)
MODELSFILE="models.yml"
function readConfigEntriesArray() {
yq eval '.'${1}' | explode(.) | to_entries | map([.key])[] | .[]' "${2}"
}
while IFS= read -r line; do
PAT_VERSION=$(echo "${line}" | cut -f 1 -d ' ')
PAT_BUILD=$(echo "${line}" | cut -f 2 -d ' ')
MODEL=$(echo "${line}" | cut -f 3 -d ' ')
BUILD=$(echo "${line}" | cut -f 4 -d ' ')
CACHE_PATH="${HOME}/cache"
RAMDISK_PATH="${CACHE_PATH}/ramdisk"
PAT_FILE="${MODEL}_${BUILD}.pat"
PAT_PATH="${CACHE_PATH}/dl/${PAT_FILE}"
EXTRACTOR_PATH="${CACHE_PATH}/extractor"
EXTRACTOR_BIN="syno_extract_system_patch"
UNTAR_PAT_PATH="${CACHE_PATH}/${MODEL}/${BUILD}"
DSMPATH="${HOME}/dsm"
DESTINATION="${DSMPATH}/${MODEL}/${BUILD}"
FILESPATH="${HOME}/files"
DESTINATIONFILES="${FILESPATH}/${MODEL}/${BUILD}"
if [ ! -f "${DESTINATIONFILES}/dsm.tar" ] || [ ! -f "${DESTINATION}" ]; then
PAT_MODEL="$(echo "${MODEL}" | sed 's/ /%20/')"
echo "${PAT_MODEL} ${PAT_VERSION} ${BUILD}"
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}"
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)
PAT_LINK="${PAT_VERSION}/${PAT_BUILD}/DSM_${PAT_MODEL}_${BUILD}.pat"
PAT_URL="https://global.synologydownload.com/download/DSM/release/${PAT_LINK}"
echo "${MODEL} ${VERSION}"
speed_a=$(ping -c 1 -W 5 global.synologydownload.com | awk '/time=/ {print $7}' | cut -d '=' -f 2)
speed_b=$(ping -c 1 -W 5 global.download.synology.com | awk '/time=/ {print $7}' | cut -d '=' -f 2)
fastest=$(echo -e "global.synologydownload.com ${speed_a:-999}\nglobal.download.synology.com ${speed_b:-999}" | sort -k2rn | head -1 | awk '{print $1}')
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%%\?*}
mirror=$(echo ${PAT_URL} | sed 's|^http[s]*://\([^/]*\).*|\1|')
echo "$(printf "Based on the current network situation, switch to %s mirror for download." "${fastest}")"
PAT_URL=$(echo ${PAT_URL} | sed "s/${mirror}/${fastest}/")
mkdir -p "${CACHE_PATH}/dl"
OLDURL=$(cat "${DESTINATION}/pat_url")
OLDHASH=$(cat "${DESTINATION}/pat_hash")
if [ ! -f "${PAT_PATH}" ]; then
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
mkdir -p "${DESTINATION}"
mkdir -p "${DESTINATIONFILES}"
if [ "${HASH}" != "${OLDHASH}" ] || [ "${PAT_URL}" != "${OLDURL}" ]; then
echo -n "Checking hash of pat: "
HASH=$(md5sum ${PAT_PATH} | awk '{print$1}')
echo "OK"
echo "${HASH}" >"${DESTINATION}/pat_hash"
echo "${PAT_URL}" >"${DESTINATION}/pat_url"
echo "${HASH}" >"${DESTINATION}/pat_hash"
echo "${PAT_URL}" >"${DESTINATION}/pat_url"
rm -rf "${UNTAR_PAT_PATH}"
mkdir -p "${UNTAR_PAT_PATH}"
echo -n "Disassembling ${PAT_FILE}: "
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
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
if [ "${isencrypted}" = "yes" ]; then
# Check existance of extractor
if [ -f "${EXTRACTOR_PATH}/${EXTRACTOR_BIN}" ]; then
echo "Extractor cached."
fi
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"
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}"
echo "DSM extract complete: ${MODEL}_${BUILD}"
# 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 "DSM extract Error: ${MODEL}_${BUILD}"
echo "Extracting..."
tar -xf "${PAT_PATH}" -C "${UNTAR_PAT_PATH}"
if [ $? -ne 0 ]; then
echo "Error extracting"
fi
fi
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"
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}"
echo "DSM extract complete: ${MODEL}_${BUILD}"
else
echo "DSM extract Error: ${MODEL}_${BUILD}"
fi
cd ${HOME}
fi
done < ${MODELSFILE}
done < ${VERSIONSFILE}
rm -f "${VERSIONSFILE}"
}
HOME=$(pwd)
CONFIGS="./configs"
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)
rm -rf "${CACHE_PATH}/dl"