From 74e7294491511f1a3a25bc7caee207c2f2508634 Mon Sep 17 00:00:00 2001 From: AuxXxilium Date: Fri, 2 Aug 2024 19:12:14 +0200 Subject: [PATCH] update: add custom to update section Signed-off-by: AuxXxilium --- files/initrd/opt/arc/arc-functions.sh | 24 ++++++++++ files/initrd/opt/arc/include/update.sh | 63 ++++++++++++++++++++++++++ files/initrd/opt/arc/update.sh | 1 + 3 files changed, 88 insertions(+) diff --git a/files/initrd/opt/arc/arc-functions.sh b/files/initrd/opt/arc/arc-functions.sh index cb490bbe..06608b77 100755 --- a/files/initrd/opt/arc/arc-functions.sh +++ b/files/initrd/opt/arc/arc-functions.sh @@ -831,6 +831,7 @@ function updateMenu() { 6 "Update LKMs" \ 7 "Update Modules" \ 8 "Update Patches" \ + 9 "Update Custom Kernel" \ 2>"${TMP_PATH}/resp" [ $? -ne 0 ] && break case "$(cat ${TMP_PATH}/resp)" in @@ -1006,6 +1007,29 @@ function updateMenu() { writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" ;; + 9) + # Ask for Tag + TAG="" + dialog --clear --backtitle "$(backtitle)" --title "Update Custom Kernel" \ + --menu "Which Version?" 0 0 0 \ + 1 "Latest" \ + 2 "Select Version" \ + 2>"${TMP_PATH}/opts" + opts=$(cat ${TMP_PATH}/opts) + [ -z "${opts}" ] && return 1 + if [ ${opts} -eq 1 ]; then + TAG="" + elif [ ${opts} -eq 2 ]; then + dialog --backtitle "$(backtitle)" --title "Update Custom Kernel" \ + --inputbox "Type the Version!" 0 0 \ + 2>"${TMP_PATH}/input" + TAG=$(cat "${TMP_PATH}/input") + [ -z "${TAG}" ] && return 1 + fi + updateCustom "${TAG}" + writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}" + BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")" + ;; esac done return diff --git a/files/initrd/opt/arc/include/update.sh b/files/initrd/opt/arc/include/update.sh index d9fa4430..84c51287 100755 --- a/files/initrd/opt/arc/include/update.sh +++ b/files/initrd/opt/arc/include/update.sh @@ -299,6 +299,69 @@ function updatePatches() { return 0 } +############################################################################### +# Update Custom +function updateCustom() { + local ARCNIC="$(readConfigKey "arc.nic" "${USER_CONFIG_FILE}")" + if [ -z "${1}" ]; then + # Check for new Version + idx=0 + while [ ${idx} -le 5 ]; do # Loop 5 times, if successful, break + if [ "${ARCNIC}" == "auto" ]; then + local TAG="$(curl -m 10 -skL "https://api.github.com/repos/AuxXxilium/arc-custom/releases" | jq -r ".[].tag_name" | sort -rV | head -1)" + else + local TAG="$(curl --interface ${ARCNIC} -m 10 -skL "https://api.github.com/repos/AuxXxilium/arc-custom/releases" | jq -r ".[].tag_name" | sort -rV | head -1)" + fi + if [ -n "${TAG}" ]; then + break + fi + sleep 3 + idx=$((${idx} + 1)) + done + else + local TAG="${1}" + fi + if [ -n "${TAG}" ]; then + ( + # Download update file + local URL="https://github.com/AuxXxilium/arc-custom/releases/download/${TAG}/custom.zip" + local SHA="https://github.com/AuxXxilium/arc-custom/releases/download/${TAG}/checksum.sha256" + echo "Downloading ${TAG}" + if [ "${ARCNIC}" == "auto" ]; then + curl -#kL "${URL}" -o "${TMP_PATH}/custom.zip" 2>&1 | while IFS= read -r -n1 char; do + [[ $char =~ [0-9] ]] && keep=1 ; + [[ $char == % ]] && echo "Download: $progress%" && progress="" && keep=0 ; + [[ $keep == 1 ]] && progress="$progress$char" ; + done + curl -skL "${SHA}" -o "${TMP_PATH}/checksum.sha256" + else + curl --interface ${ARCNIC} -#kL "${URL}" -o "${TMP_PATH}/custom.zip" 2>&1 | while IFS= read -r -n1 char; do + [[ $char =~ [0-9] ]] && keep=1 ; + [[ $char == % ]] && echo "Download: $progress%" && progress="" && keep=0 ; + [[ $keep == 1 ]] && progress="$progress$char" ; + done + curl --interface ${ARCNIC} -skL "${SHA}" -o "${TMP_PATH}/checksum.sha256" + fi + if [ "$(sha256sum "${TMP_PATH}/custom.zip" | awk '{print $1}')" = "$(cat ${TMP_PATH}/checksum.sha256 | awk '{print $1}')" ]; then + echo "Download successful!" + rm -rf "${CUSTOM_PATH}" + mkdir -p "${CUSTOM_PATH}" + echo "Installing new Custom Kernel..." + unzip -oq "${TMP_PATH}/custom.zip" -d "${CUSTOM_PATH}" + rm -f "${TMP_PATH}/custom.zip" + else + echo "Error extracting new Version!" + sleep 5 + updateFailed + fi + echo "Update done!" + sleep 2 + ) 2>&1 | dialog --backtitle "$(backtitle)" --title "Update Custom" \ + --progressbox "Updating Custom..." 20 70 + fi + return 0 +} + ############################################################################### # Update Modules function updateModules() { diff --git a/files/initrd/opt/arc/update.sh b/files/initrd/opt/arc/update.sh index 0d204a08..2f49647b 100755 --- a/files/initrd/opt/arc/update.sh +++ b/files/initrd/opt/arc/update.sh @@ -69,6 +69,7 @@ function arcUpdate() { updateLKMs updateModules updatePatches + updateCustom # Ask for Boot dialog --backtitle "$(backtitle)" --title "Update Loader" --aspect 18 \ --infobox "Update successful!" 0 0