tree: cleanup and rewrite logic

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-09-29 15:45:49 +02:00
parent 8a1ea9bd53
commit 9448e3f298
6 changed files with 61 additions and 46 deletions

View File

@ -2252,7 +2252,7 @@ function governorMenu () {
function governorSelection () {
rm -f "${TMP_PATH}/opts" >/dev/null
touch "${TMP_PATH}/opts"
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
# Selectable CPU governors
[ "${PLATFORM}" == "epyc7002" ] && echo -e "schedutil \"use schedutil to scale frequency *\"" >>"${TMP_PATH}/opts"
[ "${PLATFORM}" != "epyc7002" ] && echo -e "ondemand \"use ondemand to scale frequency *\"" >>"${TMP_PATH}/opts"

View File

@ -20,8 +20,7 @@ systemCheck
offlineCheck "false"
ARCNIC="$(readConfigKey "arc.nic" "${USER_CONFIG_FILE}")"
OFFLINE="$(readConfigKey "arc.offline" "${USER_CONFIG_FILE}")"
AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
UPDATEMODE="false"
MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
# Get DSM Data from Config
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
@ -38,6 +37,7 @@ fi
ARCKEY="$(readConfigKey "arc.key" "${USER_CONFIG_FILE}")"
ARCPATCH="$(readConfigKey "arc.patch" "${USER_CONFIG_FILE}")"
ARCDYN="$(readConfigKey "arc.dynamic" "${USER_CONFIG_FILE}")"
IPV6="$(readConfigKey "arc.ipv6" "${USER_CONFIG_FILE}")"
BOOTIPWAIT="$(readConfigKey "bootipwait" "${USER_CONFIG_FILE}")"
DIRECTBOOT="$(readConfigKey "directboot" "${USER_CONFIG_FILE}")"
EMMCBOOT="$(readConfigKey "emmcboot" "${USER_CONFIG_FILE}")"
@ -107,7 +107,7 @@ function arcModel() {
arch=$(echo "${item}" | jq -r '.arch')
echo "${name} ${arch}" >>"${TMP_PATH}/modellist"
done
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
while true; do
echo -n "" >"${TMP_PATH}/menu"
while read -r M A; do
@ -201,7 +201,7 @@ function arcModel() {
done
fi
# Reset Model Config if changed
if [ "${AUTOMATED}" == "false" ] && [ "${MODEL}" != "${resp}" ]; then
if [ "${MODE}" == "config" ] && [ "${MODEL}" != "${resp}" ]; then
MODEL="${resp}"
PLATFORM="$(grep -w "${MODEL}" "${TMP_PATH}/modellist" | awk '{print $2}' | head -n 1)"
writeConfigKey "addons" "{}" "${USER_CONFIG_FILE}"
@ -251,7 +251,7 @@ function arcVersion() {
PAT_URL_CONF="$(readConfigKey "paturl" "${USER_CONFIG_FILE}")"
PAT_HASH_CONF="$(readConfigKey "pathash" "${USER_CONFIG_FILE}")"
# Check for Custom Build
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
# Select Build for DSM
ITEMS="$(readConfigEntriesArray "platforms.${PLATFORM}.productvers" "${P_FILE}" | sort -r)"
dialog --clear --no-items --nocancel --title "DSM Version" --backtitle "$(backtitle)" \
@ -337,12 +337,12 @@ function arcVersion() {
dialog --backtitle "$(backtitle)" --colors --title "Automated Mode" \
--yesno "${MSG}" 6 55
if [ $? -eq 0 ]; then
AUTOMATED="true"
MODE="automated"
else
AUTOMATED="false"
MODE="config"
fi
writeConfigKey "automated" "${AUTOMATED}" "${USER_CONFIG_FILE}"
elif [ "${AUTOMATED}" == "true" ]; then
writeConfigKey "arc.mode" "automated" "${USER_CONFIG_FILE}"
elif [ "${MODE}" == "automated" ]; then
PAT_URL="$(readConfigKey "paturl" "${USER_CONFIG_FILE}")"
PAT_HASH="$(readConfigKey "pathash" "${USER_CONFIG_FILE}")"
VALID="true"
@ -398,7 +398,7 @@ function arcVersion() {
fi
fi
fi
elif [ ! -f "${DSM_FILE}" ] && [ "${OFFLINE}" == "true" ] && [ "${AUTOMATED}" == "false" ]; then
elif [ ! -f "${DSM_FILE}" ] && [ "${OFFLINE}" == "true" ] && [ "${MODE}" == "config" ]; then
PAT_FILE=$(ls ${USER_UP_PATH}/*.pat | head -n 1)
if [ ! -f "${PAT_FILE}" ]; then
mkdir -p "${USER_UP_PATH}"
@ -547,7 +547,7 @@ function arcPatch() {
ARCCONF="$(readConfigKey "${MODEL}.serial" "${S_FILE}")"
# Check for Custom Build
SN="$(readConfigKey "sn" "${USER_CONFIG_FILE}")"
if [ "${AUTOMATED}" == "true" ]; then
if [ "${MODE}" == "automated" ]; then
if [ -n "${ARCCONF}" ]; then
SN=$(generateSerial "${MODEL}" "true")
writeConfigKey "arc.patch" "true" "${USER_CONFIG_FILE}"
@ -555,7 +555,7 @@ function arcPatch() {
SN=$(generateSerial "${MODEL}" "false")
writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}"
fi
elif [ "${AUTOMATED}" == "false" ]; then
elif [ "${MODE}" == "config" ]; then
if [ -n "${ARCCONF}" ]; then
dialog --clear --backtitle "$(backtitle)" \
--nocancel --title "SN/Mac Options"\
@ -650,7 +650,7 @@ function arcSettings() {
[ $? -ne 0 ] && return 1
fi
# Check for Custom Build
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
# Select Addons
dialog --backtitle "$(backtitle)" --colors --title "DSM Addons" \
--infobox "Loading Addons Table..." 3 40
@ -658,12 +658,12 @@ function arcSettings() {
[ $? -ne 0 ] && return 1
fi
# Check for CPU Frequency Scaling & Governor
if [ "${AUTOMATED}" == "false" ] && [ "${CPUFREQ}" == "true" ] && [ "${ACPISYS}" == "true" ] && readConfigMap "addons" "${USER_CONFIG_FILE}" | grep -q "cpufreqscaling"; then
if [ "${MODE}" == "config" ] && [ "${CPUFREQ}" == "true" ] && [ "${ACPISYS}" == "true" ] && readConfigMap "addons" "${USER_CONFIG_FILE}" | grep -q "cpufreqscaling"; then
dialog --backtitle "$(backtitle)" --colors --title "CPU Frequency Scaling" \
--infobox "Generating Governor Table..." 3 40
governorSelection
[ $? -ne 0 ] && return 1
elif [ "${AUTOMATED}" == "true" ] && [ "${CPUFREQ}" == "true" ] && [ "${ACPISYS}" == "true" ] && readConfigMap "addons" "${USER_CONFIG_FILE}" | grep -q "cpufreqscaling"; then
elif [ "${MODE}" == "automated" ] && [ "${CPUFREQ}" == "true" ] && [ "${ACPISYS}" == "true" ] && readConfigMap "addons" "${USER_CONFIG_FILE}" | grep -q "cpufreqscaling"; then
if [ "${PLATFORM}" == "epyc7002" ]; then
writeConfigKey "addons.cpufreqscaling" "schedutil" "${USER_CONFIG_FILE}"
else
@ -672,7 +672,7 @@ function arcSettings() {
else
deleteConfigKey "addons.cpufreqscaling" "${USER_CONFIG_FILE}"
fi
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
# Check for DT and HBA/Raid Controller
if [ "${PLATFORM}" != "epyc7002" ]; then
if [ "${DT}" == "true" ] && [ "${EXTERNALCONTROLLER}" == "true" ]; then
@ -719,7 +719,7 @@ function arcSettings() {
writeConfigKey "arc.confdone" "true" "${USER_CONFIG_FILE}"
CONFDONE="$(readConfigKey "arc.confdone" "${USER_CONFIG_FILE}")"
# Check for Custom Build
if [ "${AUTOMATED}" == "false" ]; then
if [ "${MODE}" == "config" ]; then
# Ask for Build
dialog --clear --backtitle "$(backtitle)" --title "Config done" \
--no-cancel --menu "Build now?" 7 40 0 \
@ -875,7 +875,7 @@ function arcFinish() {
rm -f "${LOG_FILE}" >/dev/null 2>&1 || true
writeConfigKey "arc.builddone" "true" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
if [ "${AUTOMATED}" == "true" ]; then
if [ "${MODE}" == "automated" ]; then
boot
else
# Ask for Boot
@ -978,7 +978,7 @@ function updateboot() {
###############################################################################
# Main loop
# Check for Arc Mode
if grep -q "update_arc" /proc/cmdline; then
if [ "${MODE}" == "update" ]; then
UPDATEMODE="true"
# Check for Offline Mode
if [ "${OFFLINE}" == "false" ]; then
@ -989,7 +989,7 @@ if grep -q "update_arc" /proc/cmdline; then
sleep 5
exec reboot
fi
elif grep -q "automated_arc" /proc/cmdline; then
elif [ "${MODE}" == "automated" ]; then
# Check for Custom Build
if [ "${BUILDDONE}" == "false" ] || [ "${MODEL}" != "${MODELID}" ]; then
arcModel

View File

@ -634,20 +634,26 @@ function systemCheck () {
fi
# Check for CPU Frequency Scaling
CPUFREQUENCIES=$(ls -ltr /sys/devices/system/cpu/cpufreq/* 2>/dev/null | wc -l)
if [ ${CPUFREQUENCIES} -gt 0 ]; then
if [ ${CPUFREQUENCIES} -gt 0 ] && [ "${ACPISYS}" == "true" ]; then
CPUFREQ="true"
else
CPUFREQ="false"
fi
# Check for ARCKEY
ARCKEY="$(readConfigKey "arc.key" "${USER_CONFIG_FILE}")"
if openssl enc -in "${S_FILE_ENC}" -out "${S_FILE_ARC}" -d -aes-256-cbc -k "${ARCKEY}" 2>/dev/null; then
cp -f "${S_FILE_ARC}" "${S_FILE}"
writeConfigKey "arc.key" "${ARCKEY}" "${USER_CONFIG_FILE}"
else
[ -f "${S_FILE}.bak" ] && cp -f "${S_FILE}" "${S_FILE}.bak"
writeConfigKey "arc.key" "" "${USER_CONFIG_FILE}"
writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}"
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
if [ -n "${MODEL}" ]; then
ARCCONF="$(readConfigKey "${MODEL}.serial" "${S_FILE}" 2>/dev/null)"
fi
if [ -z "${ARCCONF}" ] && [ -n "${ARCKEY}" ]; then
if openssl enc -in "${S_FILE_ENC}" -out "${S_FILE_ARC}" -d -aes-256-cbc -k "${ARCKEY}" 2>/dev/null; then
cp -f "${S_FILE_ARC}" "${S_FILE}"
writeConfigKey "arc.key" "${ARCKEY}" "${USER_CONFIG_FILE}"
else
[ -f "${S_FILE}.bak" ] && cp -f "${S_FILE}" "${S_FILE}.bak"
writeConfigKey "arc.key" "" "${USER_CONFIG_FILE}"
writeConfigKey "arc.patch" "false" "${USER_CONFIG_FILE}"
fi
fi
}

View File

@ -141,8 +141,8 @@ function getmapSelection() {
SATAPORTMAP="$(awk '{print $1}' "${TMP_PATH}/drivescon")"
SATAREMAP="$(awk '{print $1}' "${TMP_PATH}/remap" | sed 's/.$//')"
EXTERNALCONTROLLER="$(readConfigKey "device.externalcontroller" "${USER_CONFIG_FILE}")"
AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
if [ "${AUTOMATED}" == "false" ]; then
MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
if [ "${MODE}" == "config" ]; then
# Show recommended Option to user
if [ -n "${SATAREMAP}" ] && [ "${EXTERNALCONTROLLER}" == "true" ] && [ "${MACHINE}" == "Native" ]; then
REMAP2="*"

View File

@ -2,7 +2,6 @@
# Upgrade Loader
function upgradeLoader () {
local ARCNIC="$(readConfigKey "arc.nic" "${USER_CONFIG_FILE}")"
local AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
local ARCBRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
rm -f "${TMP_PATH}/check.update"
rm -f "${TMP_PATH}/arc.img.zip"
@ -97,7 +96,7 @@ function upgradeLoader () {
# Update Loader
function updateLoader() {
local ARCNIC="$(readConfigKey "arc.nic" "${USER_CONFIG_FILE}")"
local AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
local MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
local ARCBRANCH="$(readConfigKey "arc.branch" "${USER_CONFIG_FILE}")"
rm -f "${TMP_PATH}/check.update"
rm -f "${TMP_PATH}/checksum.sha256"
@ -125,7 +124,7 @@ function updateLoader() {
if [ -f "${TMP_PATH}/check.update" ]; then
local UPDATE_VERSION=$(cat "${TMP_PATH}/check.update" | sed -e 's/\.//g' )
local ARC_VERSION=$(cat "${PART1_PATH}/ARC-VERSION" | sed -e 's/\.//g' )
if [ ${ARC_VERSION} -lt ${UPDATE_VERSION} ] && [ "${AUTOMATED}" == "false" ]; then
if [ ${ARC_VERSION} -lt ${UPDATE_VERSION} ] && [ "${MODE}" == "config" ]; then
dialog --backtitle "$(backtitle)" --title "Upgrade Loader" \
--yesno "Config is not compatible to new Version!\nPlease reconfigure Loader after Update!\nDo you want to update?" 0 0
if [ $? -eq 0 ]; then
@ -133,7 +132,7 @@ function updateLoader() {
else
return 1
fi
elif [ ${ARC_VERSION} -lt ${UPDATE_VERSION} ] && [ "${AUTOMATED}" == "true" ]; then
elif [ ${ARC_VERSION} -lt ${UPDATE_VERSION} ] && [ "${MODE}" == "automated" ]; then
dialog --backtitle "$(backtitle)" --title "Full-Update Loader" \
--infobox "Config is not compatible to new Version!\nUpdate not possible!\nPlease reflash Loader." 0 0
sleep 5
@ -171,13 +170,15 @@ function updateLoader() {
echo "Download successful!"
if [ "$(sha256sum "${TMP_PATH}/update.zip" | awk '{print $1}')" == "$(cat ${TMP_PATH}/checksum.sha256 | awk '{print $1}')" ]; then
echo "Download successful!"
unzip -oq "${TMP_PATH}/update.zip" -d "${PART3_PATH}"
echo "Backup Arc Config File..."
cp -f "${S_FILE_ARC}" "/tmp/arc_serials.yml"
echo "Cleaning up..."
rm -rf "${ADDONS_PATH}"
mkdir -p "${ADDONS_PATH}"
rm -rf "${MODULES_PATH}"
mkdir -p "${MODULES_PATH}"
echo "Installing new Loader Image..."
unzip -oq "${TMP_PATH}/update.zip" -d "${PART3_PATH}"
mv -f "${PART3_PATH}/grub.cfg" "${USER_GRUB_CONFIG}"
mv -f "${PART3_PATH}/ARC-VERSION" "${PART1_PATH}/ARC-VERSION"
mv -f "${PART3_PATH}/ARC-BRANCH" "${PART1_PATH}/ARC-BRANCH"
@ -196,6 +197,8 @@ function updateLoader() {
writeConfigKey "modules.${ID}" "" "${USER_CONFIG_FILE}"
done < <(getAllModules "${PLATFORM}" "${KVERP}")
fi
echo "Restore Arc Config File..."
cp -f "/tmp/arc_serials.yml" "${S_FILE_ARC}"
echo "Update done!"
sleep 2
else
@ -642,8 +645,8 @@ function updateLKMs() {
###############################################################################
# Update Failed
function updateFailed() {
local AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
if [ "${AUTOMATED}" == "true" ]; then
local MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
if [ "${MODE}" == "automated" ]; then
echo "Update failed!"
sleep 5
exec reboot
@ -655,8 +658,8 @@ function updateFailed() {
}
function updateFaileddialog() {
local AUTOMATED="$(readConfigKey "automated" "${USER_CONFIG_FILE}")"
if [ "${AUTOMATED}" == "true" ]; then
local MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
if [ "${MODE}" == "automated" ]; then
dialog --backtitle "$(backtitle)" --title "Update Failed" \
--infobox "Update failed!" 0 0
sleep 5

View File

@ -41,6 +41,7 @@ initConfigKey "arc.branch" "" "${USER_CONFIG_FILE}"
initConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
initConfigKey "arc.confdone" "false" "${USER_CONFIG_FILE}"
initConfigKey "arc.dynamic" "false" "${USER_CONFIG_FILE}"
initConfigKey "arc.ipv6" "false" "${USER_CONFIG_FILE}"
initConfigKey "arc.key" "" "${USER_CONFIG_FILE}"
initConfigKey "arc.nic" "" "${USER_CONFIG_FILE}"
initConfigKey "arc.offline" "false" "${USER_CONFIG_FILE}"
@ -80,10 +81,14 @@ initConfigKey "synoinfo" "{}" "${USER_CONFIG_FILE}"
initConfigKey "time" "{}" "${USER_CONFIG_FILE}"
initConfigKey "usbmount" "auto" "${USER_CONFIG_FILE}"
initConfigKey "zimage-hash" "" "${USER_CONFIG_FILE}"
if cat /proc/cmdline | grep -q "automated_arc"; then
writeConfigKey "automated" "true" "${USER_CONFIG_FILE}"
if grep -q "automated_arc" /proc/cmdline; then
writeConfigKey "arc.mode" "automated" "${USER_CONFIG_FILE}"
elif grep -q "update_arc" /proc/cmdline; then
writeConfigKey "arc.mode" "update" "${USER_CONFIG_FILE}"
elif grep -q "force_arc" /proc/cmdline; then
writeConfigKey "arc.mode" "config" "${USER_CONFIG_FILE}"
else
writeConfigKey "automated" "false" "${USER_CONFIG_FILE}"
writeConfigKey "arc.mode" "dsm" "${USER_CONFIG_FILE}"
fi
[ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated" >/dev/null 2>&1 || true
if [ -f "${PART1_PATH}/ARC-BRANCH" ]; then
@ -161,11 +166,12 @@ echo
# Decide if boot automatically
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
if grep -q "force_arc" /proc/cmdline; then
MODE="$(readConfigKey "arc.mode" "${USER_CONFIG_FILE}")"
if [ "${MODE}" == "config" ]; then
echo -e "\033[1;34mStarting Config Mode...\033[0m"
elif grep -q "automated_arc" /proc/cmdline; then
elif [ "${MODE}" == "automated" ]; then
echo -e "\033[1;34mStarting automated Build Mode...\033[0m"
elif grep -q "update_arc" /proc/cmdline; then
elif [ "${MODE}" == "update" ]; then
echo -e "\033[1;34mStarting Update Mode...\033[0m"
elif [ "${BUILDDONE}" == "true" ]; then
echo -e "\033[1;34mStarting DSM Mode...\033[0m"