tree: cleanup and rewrite

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-05-22 19:37:04 +02:00
parent 93aaf3a7a0
commit 185381aff6
3 changed files with 39 additions and 67 deletions

View File

@ -17,7 +17,7 @@ function editUserConfig() {
SN="$(readConfigKey "arc.sn" "${USER_CONFIG_FILE}")"
if [ "${MODEL}" != "${OLDMODEL}" ] || [ "${PRODUCTVER}" != "${OLDPRODUCTVER}" ]; then
# Delete old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null
fi
writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
@ -44,7 +44,7 @@ function addonSelection() {
while IFS=': ' read -r KEY VALUE; do
[ -n "${KEY}" ] && ADDONS["${KEY}"]="${VALUE}"
done <<<$(readConfigMap "addons" "${USER_CONFIG_FILE}")
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
touch "${TMP_PATH}/opts"
while read -r ADDON DESC; do
arrayExistItem "${ADDON}" "${!ADDONS[@]}" && ACT="on" || ACT="off"
@ -151,7 +151,7 @@ function modulesMenu() {
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
;;
5)
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
while read -r ID DESC; do
arrayExistItem "${ID}" "${!USERMODULES[@]}" && ACT="on" || ACT="off"
echo "${ID} ${DESC} ${ACT}" >>"${TMP_PATH}/opts"
@ -185,8 +185,8 @@ function modulesMenu() {
[ $? -ne 0 ] && return
TMP_UP_PATH=${TMP_PATH}/users
USER_FILE=""
rm -rf ${TMP_UP_PATH}
mkdir -p ${TMP_UP_PATH}
rm -rf "${TMP_UP_PATH}" >/dev/null
mkdir -p "${TMP_UP_PATH}"
dialog --backtitle "$(backtitle)" --title "External Modules" \
--ok-label "Proceed" --msgbox "Please upload the *.ko file to /tmp/users.\n- Use SFTP at ${IPCON}:22 User: root PW: arc\n- Use Webclient at http://${IPCON}:7304" 7 50
for F in $(ls "${TMP_UP_PATH}" 2>/dev/null); do
@ -202,7 +202,7 @@ function modulesMenu() {
addToModules "${PLATFORM}" "${KVERP}" "${TMP_UP_PATH}/${USER_FILE}"
dialog --backtitle "$(backtitle)" --title "External Modules" \
--msgbox "Module: ${USER_FILE}\nadded to ${PLATFORM}-${KVERP}" 7 50
rm -f "${TMP_UP_PATH}/${USER_FILE}"
rm -f "${TMP_UP_PATH}/${USER_FILE}" >/dev/null
else
dialog --backtitle "$(backtitle)" --title "External Modules" \
--msgbox "Not a valid file, please try again!" 7 50
@ -416,7 +416,7 @@ function cmdlineMenu() {
--aspect 18 --msgbox "${ITEMS}" 0 0
;;
8)
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
echo "5 \"Reboot after 5 seconds\"" >>"${TMP_PATH}/opts"
echo "0 \"No reboot\"" >>"${TMP_PATH}/opts"
echo "-1 \"Restart immediately\"" >>"${TMP_PATH}/opts"
@ -707,7 +707,7 @@ function backupMenu() {
fi
umount "${TMP_PATH}/mdX"
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Backup Encrytion Key" \
--progressbox "Backup Encryption Key ..." 20 70
if [ "${BACKUPKEY}" = "true" ]; then
@ -781,7 +781,7 @@ function updateMenu() {
return 1
fi
unzip -oq "${TMP_PATH}/arc-${TAG}.img.zip" -d "${TMP_PATH}"
rm -f "${TMP_PATH}/arc-${TAG}.img.zip"
rm -f "${TMP_PATH}/arc-${TAG}.img.zip" >/dev/null
if [ $? -ne 0 ]; then
echo "Error extracting Updatefile!"
sleep 5
@ -792,7 +792,7 @@ function updateMenu() {
umount "${PART1_PATH}" "${PART2_PATH}" "${PART3_PATH}"
dd if="${TMP_PATH}/arc.img" of=$(blkid | grep 'LABEL="ARC3"' | cut -d3 -f1) bs=1M conv=fsync
# Ask for Boot
rm -f "${TMP_PATH}/arc.img"
rm -f "${TMP_PATH}/arc.img" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Full-Upgrade Loader" \
--progressbox "Upgrading ..." 20 70
dialog --backtitle "$(backtitle)" --title "Upgrade Loader" --aspect 18 \
@ -1403,7 +1403,7 @@ function fullsysinfo() {
done
fi
TEXT+="\nDrives total: ${NUMPORTS}"
[ -f "${TMP_PATH}/diag" ] && rm -f "${TMP_PATH}/diag"
[ -f "${TMP_PATH}/diag" ] && rm -f "${TMP_PATH}/diag" >/dev/null
echo -e "${TEXT}" >"${TMP_PATH}/diag"
dialog --backtitle "$(backtitle)" --colors --title "Full Sysinfo" \
--extra-button --extra-label "Upload" --no-cancel --textbox "${TMP_PATH}/diag" 0 0
@ -1584,12 +1584,12 @@ function downgradeMenu() {
for I in ${DSMROOTS}; do
mount -t ext4 "${I}" "${TMP_PATH}/mdX"
[ $? -ne 0 ] && continue
[ -f "${TMP_PATH}/mdX/etc/VERSION" ] && rm -f "${TMP_PATH}/mdX/etc/VERSION"
[ -f "${TMP_PATH}/mdX/etc.defaults/VERSION" ] && rm -f "${TMP_PATH}/mdX/etc.defaults/VERSION"
[ -f "${TMP_PATH}/mdX/etc/VERSION" ] && rm -f "${TMP_PATH}/mdX/etc/VERSION" >/dev/null
[ -f "${TMP_PATH}/mdX/etc.defaults/VERSION" ] && rm -f "${TMP_PATH}/mdX/etc.defaults/VERSION" >/dev/null
sync
umount "${TMP_PATH}/mdX"
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Allow Downgrade" \
--progressbox "Removing ..." 20 70
dialog --backtitle "$(backtitle)" --title "Allow Downgrade" \
@ -1606,7 +1606,7 @@ function resetPassword() {
--msgbox "No DSM system partition(md0) found!\nPlease insert all disks before continuing." 0 0
return
fi
rm -f "${TMP_PATH}/menu"
rm -f "${TMP_PATH}/menu" >/dev/null
mkdir -p "${TMP_PATH}/mdX"
for I in ${DSMROOTS}; do
mount -t ext4 "${I}" "${TMP_PATH}/mdX"
@ -1624,7 +1624,7 @@ function resetPassword() {
umount "${TMP_PATH}/mdX"
[ -f "${TMP_PATH}/menu" ] && break
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
if [ ! -f "${TMP_PATH}/menu" ]; then
dialog --backtitle "$(backtitle)" --title "Reset Password" \
--msgbox "All existing users have been disabled. Please try adding new user." 0 0
@ -1661,7 +1661,7 @@ function resetPassword() {
sync
umount "${TMP_PATH}/mdX"
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Reset Password" \
--progressbox "Resetting ..." 20 100
dialog --backtitle "$(backtitle)" --title "Reset Password" \
@ -1706,7 +1706,7 @@ EOF
fi
umount "${TMP_PATH}/mdX"
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Add DSM User" \
--progressbox "Adding ..." 20 100
[ "$(cat ${TMP_PATH}/isEnable 2>/dev/null)" = "true" ] && MSG="Add DSM User successful." || MSG="Add DSM User failed."
@ -1739,10 +1739,10 @@ function saveMenu() {
RDXZ_PATH="${TMP_PATH}/rdxz_tmp"
mkdir -p "${RDXZ_PATH}"
(cd "${RDXZ_PATH}"; xz -dc <"${PART3_PATH}/initrd-arc" | cpio -idm) >/dev/null 2>&1 || true
rm -rf "${RDXZ_PATH}/opt/arc"
rm -rf "${RDXZ_PATH}/opt/arc" >/dev/null
cp -Rf "$(dirname ${ARC_PATH})" "${RDXZ_PATH}"
(cd "${RDXZ_PATH}"; find . 2>/dev/null | cpio -o -H newc -R root:root | xz --check=crc32 >"${PART3_PATH}/initrd-arc") || true
rm -rf "${RDXZ_PATH}"
rm -rf "${RDXZ_PATH}" >/dev/null
dialog --backtitle "$(backtitle)" --colors --aspect 18 \
--msgbox "Save to Disk is complete." 0 0
return
@ -1751,7 +1751,7 @@ function saveMenu() {
###############################################################################
# let user format disks from inside arc
function formatdisks() {
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
while read -r KNAME KMODEL PKNAME TYPE; do
[ -z "${KNAME}" ] && continue
[ "${KNAME}" = "${LOADER_DISK}" ] || [ "${PKNAME}" = "${LOADER_DISK}" ] || [ "${KMODEL}" = "${LOADER_DISK}" ] && continue
@ -1841,7 +1841,7 @@ EOF
fi
umount "${TMP_PATH}/mdX"
done
rm -rf "${TMP_PATH}/mdX"
rm -rf "${TMP_PATH}/mdX" >/dev/null
) 2>&1 | dialog --backtitle "$(backtitle)" --title "Force enable SSH" \
--progressbox "$(TEXT "Enabling ...")" 20 100
[ "$(cat ${TMP_PATH}/isEnable 2>/dev/null)" = "true" ] && MSG="Enable Telnet&SSH successfully." || MSG="Enable Telnet&SSH failed."
@ -1853,7 +1853,7 @@ EOF
###############################################################################
# Clone Loader Disk
function cloneLoader() {
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
while read -r KNAME KMODEL PKNAME TYPE; do
[ -z "${KNAME}" ] && continue
[ -z "${KMODEL}" ] && KMODEL="${TYPE}"
@ -1888,7 +1888,7 @@ function cloneLoader() {
[ $? -ne 0 ] && return
fi
(
rm -rf "${PART3_PATH}/dl"
rm -rf "${PART3_PATH}/dl" >/dev/null
CLEARCACHE=0
gzip -dc "${ARC_PATH}/grub.img.gz" | dd of="${resp}" bs=1M conv=fsync status=progress
@ -1927,10 +1927,10 @@ function cloneLoader() {
function resetLoader() {
if [ -f "${ORI_ZIMAGE_FILE}" ] || [ -f "${ORI_RDGZ_FILE}" ] || [ -f "${MOD_ZIMAGE_FILE}" ] || [ -f "${MOD_RDGZ_FILE}" ]; then
# Clean old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null
fi
[ -d "${UNTAR_PAT_PATH}" ] && rm -rf "${UNTAR_PAT_PATH}"
[ -f "${USER_CONFIG_FILE}" ] && rm -f "${USER_CONFIG_FILE}"
[ -d "${UNTAR_PAT_PATH}" ] && rm -rf "${UNTAR_PAT_PATH}" >/dev/null
[ -f "${USER_CONFIG_FILE}" ] && rm -f "${USER_CONFIG_FILE}" >/dev/null
dialog --backtitle "$(backtitle)" --title "Reset Loader" --aspect 18 \
--yesno "Reset successful.\nReboot required!" 0 0
[ $? -ne 0 ] && return
@ -1954,8 +1954,7 @@ function editGrubCfg() {
# Grep Logs from dbgutils
function greplogs() {
if [ -d "${PART1_PATH}/logs" ]; then
rm -f "${TMP_PATH}/log.tar.gz"
rm -f "${PART1_PATH}/log.tar.gz"
rm -f "${PART1_PATH}/log.tar.gz" >/dev/null
tar -czf "${PART1_PATH}/log.tar.gz" "${PART1_PATH}/logs"
if [ -z "${SSH_TTY}" ]; then # web
mv -f "${PART1_PATH}/log.tar.gz" "/var/www/data/log.tar.gz"
@ -1985,7 +1984,7 @@ function greplogs() {
# Get DSM Config File from dsmbackup
function getbackup() {
if [ -d "${PART1_PATH}/dsmbackup" ]; then
rm -f "${TMP_PATH}/dsmconfig.tar.gz"
rm -f "${TMP_PATH}/dsmconfig.tar.gz" >/dev/null
tar -czf "${TMP_PATH}/dsmconfig.tar.gz" -C "${PART1_PATH}" dsmbackup
if [ -z "${SSH_TTY}" ]; then # web
mv -f "${TMP_PATH}/dsmconfig.tar.gz" "/var/www/data/dsmconfig.tar.gz"
@ -2014,7 +2013,7 @@ function getbackup() {
###############################################################################
# SataDOM Menu
function satadomMenu() {
rm -f "${TMP_PATH}/opts"
rm -f "${TMP_PATH}/opts" >/dev/null
echo "0 \"Create SATA node(ARC)\"" >>"${TMP_PATH}/opts"
echo "1 \"Native SATA Disk(SYNO)\"" >>"${TMP_PATH}/opts"
echo "2 \"Fake SATA DOM(Redpill)\"" >>"${TMP_PATH}/opts"

View File

@ -265,7 +265,7 @@ function arcModel() {
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"
if [[ -f "${ORI_ZIMAGE_FILE}" || -f "${ORI_RDGZ_FILE}" || -f "${MOD_ZIMAGE_FILE}" || -f "${MOD_RDGZ_FILE}" ]]; then
# Delete old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null
fi
fi
arcVersion
@ -294,7 +294,7 @@ function arcVersion() {
writeConfigKey "productver" "${PRODUCTVER}" "${USER_CONFIG_FILE}"
if [ -f "${ORI_ZIMAGE_FILE}" ] || [ -f "${ORI_RDGZ_FILE}" ] || [ -f "${MOD_ZIMAGE_FILE}" ] || [ -f "${MOD_RDGZ_FILE}" ]; then
# Delete old files
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" >/dev/null
fi
fi
PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")"
@ -622,9 +622,7 @@ function make() {
DT="$(readConfigKey "platforms.${PLATFORM}.dt" "${P_FILE}")"
CUSTOM="$(readConfigKey "arc.custom" "${USER_CONFIG_FILE}")"
# Cleanup
if [ -d "${UNTAR_PAT_PATH}" ]; then
rm -rf "${UNTAR_PAT_PATH}"
fi
[ -d "${UNTAR_PAT_PATH}" ] && rm -rf "${UNTAR_PAT_PATH}" >/dev/null
mkdir -p "${UNTAR_PAT_PATH}"
if [ "${OFFLINE}" = "false" ]; then
# Get PAT Data from Config
@ -787,7 +785,7 @@ function make() {
if copyDSMFiles "${UNTAR_PAT_PATH}"; then
dialog --backtitle "$(backtitle)" --title "DSM Copy" --aspect 18 \
--infobox "DSM Copy successful!" 0 0
rm -rf "${UNTAR_PAT_PATH}"
rm -rf "${UNTAR_PAT_PATH}" >/dev/null
else
dialog --backtitle "$(backtitle)" --title "DSM Copy" --aspect 18 \
--infobox "DSM Copy failed!\nExit." 0 0
@ -816,7 +814,7 @@ function arcFinish() {
if grep -q "automated_arc" /proc/cmdline; then
# Check for Custom Build
if [ "${CUSTOM}" = "false" ]; then
[ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated"
[ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated" >/dev/null
fi
boot && exit 0
else
@ -1040,7 +1038,7 @@ else
if [ "${CUSTOM}" = "true" ]; then
[ ! -f "${PART3_PATH}/automated" ] && echo "${ARC_VERSION}-${MODEL}-{PRODUCTVER}-custom" >"${PART3_PATH}/automated"
elif [ "${CUSTOM}" = "false" ]; then
[ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated"
[ -f "${PART3_PATH}/automated" ] && rm -f "${PART3_PATH}/automated" >/dev/null
fi
NEXT="R"
;;
@ -1173,10 +1171,6 @@ else
# Loader Settings
x) backupMenu; NEXT="x" ;;
9) [ "${OFFLINE}" = "true" ] && OFFLINE='false' || OFFLINE='true'
[ -f "${ORI_ZIMAGE_FILE}" ] && rm -f "${ORI_ZIMAGE_FILE}"
[ -f "${ORI_RDGZ_FILE}" ] && rm -f "${ORI_RDGZ_FILE}"
[ -f "${MOD_ZIMAGE_FILE}" ] && rm -f "${MOD_ZIMAGE_FILE}"
[ -f "${MOD_RDGZ_FILE}" ] && rm -f "${MOD_RDGZ_FILE}"
writeConfigKey "arc.offline" "${OFFLINE}" "${USER_CONFIG_FILE}"
writeConfigKey "arc.builddone" "false" "${USER_CONFIG_FILE}"
BUILDDONE="$(readConfigKey "arc.builddone" "${USER_CONFIG_FILE}")"

View File

@ -4,6 +4,7 @@
. ${ARC_PATH}/include/consts.sh
. ${ARC_PATH}/include/configFile.sh
. ${ARC_PATH}/include/addons.sh
. ${ARC_PATH}/include/update.sh
###############################################################################
# Just show error message and dies
@ -368,31 +369,9 @@ function livepatch() {
# Looking for Update
if [ ${FAIL} -eq 1 ]; then
# Update Configs
TAG="$(curl --insecure -m 5 -s https://api.github.com/repos/AuxXxilium/arc-configs/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}')"
if [[ $? -ne 0 || -z "${TAG}" ]]; then
return 1
fi
STATUS=$(curl --insecure -s -w "%{http_code}" -L "https://github.com/AuxXxilium/arc-configs/releases/download/${TAG}/configs.zip" -o "${TMP_PATH}/configs.zip")
if [[ $? -ne 0 || ${STATUS} -ne 200 ]]; then
return 1
fi
rm -rf "${MODEL_CONFIG_PATH}"
mkdir -p "${MODEL_CONFIG_PATH}"
unzip -oq "${TMP_PATH}/configs.zip" -d "${MODEL_CONFIG_PATH}" >/dev/null 2>&1
rm -f "${TMP_PATH}/configs.zip"
updateConfigs
# Update Patches
TAG="$(curl --insecure -m 5 -s https://api.github.com/repos/AuxXxilium/arc-patches/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}')"
if [[ $? -ne 0 || -z "${TAG}" ]]; then
return 1
fi
STATUS=$(curl --insecure -s -w "%{http_code}" -L "https://github.com/AuxXxilium/arc-patches/releases/download/${TAG}/patches.zip" -o "${TMP_PATH}/patches.zip")
if [[ $? -ne 0 || ${STATUS} -ne 200 ]]; then
return 1
fi
rm -rf "${PATCH_PATH}"
mkdir -p "${PATCH_PATH}"
unzip -oq "${TMP_PATH}/patches.zip" -d "${PATCH_PATH}" >/dev/null 2>&1
rm -f "${TMP_PATH}/patches.zip"
updatePatches
# Patch zImage
if ! ${ARC_PATH}/zimage-patch.sh; then
FAIL=1