Added a menu to try recovery info from installed DSM

This commit is contained in:
Fabio Belavenuto 2022-12-07 13:36:11 -03:00
parent 12876eb4a3
commit e3ad4ee347
5 changed files with 148 additions and 64 deletions

View File

@ -147,6 +147,14 @@ function arrayExistItem() {
return ${EXISTS}
}
###############################################################################
# Get values in .conf K=V file
# 1 - key
# 2 - file
function _get_conf_kv() {
grep "${1}" "${2}" | sed "s|^${1}=\"\(.*\)\"$|\1|g"
}
###############################################################################
# Replace/remove/add values in .conf K=V file
# 1 - name
@ -168,3 +176,18 @@ function _set_conf_kv() {
# Add if doesn't exist
echo "$1=\"$2\"" >> $3
}
###############################################################################
# Find and mount the DSM root filesystem
# (based on pocopico's TCRP code)
function findAndMountDSMRoot() {
[ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -gt 0 ] && return 0
dsmrootdisk="$(blkid /dev/sd* | grep -i raid | awk '{print $1 " " $4}' | grep UUID | grep sd[a-z]1 | head -1 | awk -F ":" '{print $1}')"
[ -z "${dsmrootdisk}" ] && return -1
[ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -eq 0 ] && mount -t ext4 $dsmrootdisk "${DSMROOT_PATH}"
if [ $(mount | grep -i "${DSMROOT_PATH}" | wc -l) -eq 0 ]; then
echo "Failed to mount"
return -1
fi
return 0
}

View File

@ -37,6 +37,7 @@ fsck.ext2 -p ${LOADER_DISK}3 >/dev/null 2>&1 || true
mkdir -p ${BOOTLOADER_PATH}
mkdir -p ${SLPART_PATH}
mkdir -p ${CACHE_PATH}
mkdir -p ${DSMROOT_PATH}
# Mount the partitions
mount ${LOADER_DISK}1 ${BOOTLOADER_PATH} || die "Can't mount ${BOOTLOADER_PATH}"
mount ${LOADER_DISK}2 ${SLPART_PATH} || die "Can't mount ${SLPART_PATH}"

View File

@ -61,6 +61,7 @@ function backtitle() {
###############################################################################
# Shows available models to user choose one
function modelMenu() {
if [ -z "${1}" ]; then
RESTRICT=1
FLGBETA=0
dialog --backtitle "`backtitle`" --title "Model" --aspect 18 \
@ -104,6 +105,11 @@ function modelMenu() {
FLGBETA=1
continue
fi
break
done
else
resp="${1}"
fi
# If user change model, clean buildnumber and S/N
if [ "${MODEL}" != "${resp}" ]; then
MODEL=${resp}
@ -116,19 +122,22 @@ function modelMenu() {
rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}"
DIRTY=1
fi
break
done
}
###############################################################################
# Shows available buildnumbers from a model to user choose one
function buildMenu() {
ITEMS="`readConfigEntriesArray "builds" "${MODEL_CONFIG_PATH}/${MODEL}.yml" | sort -r`"
if [ -z "${1}" ]; then
dialog --clear --no-items --backtitle "`backtitle`" \
--menu "Choose a build number" 0 0 0 ${ITEMS} 2>${TMP_PATH}/resp
[ $? -ne 0 ] && return
resp=$(<${TMP_PATH}/resp)
[ -z "${resp}" ] && return
else
if ! arrayExistItem "${1}" ${ITEMS}; then return; fi
resp="${1}"
fi
if [ "${BUILD}" != "${resp}" ]; then
dialog --backtitle "`backtitle`" --title "Build Number" \
--infobox "Reconfiguring Synoinfo, Addons and Modules" 0 0
@ -753,6 +762,7 @@ function advancedMenu() {
echo "r \"Switch direct boot: \Z4${DIRECTBOOT}\Zn\"" >> "${TMP_PATH}/menu"
fi
echo "u \"Edit user config file manually\"" >> "${TMP_PATH}/menu"
echo "t \"Try to recovery a DSM installed system\"" >> "${TMP_PATH}/menu"
echo "e \"Exit\"" >> "${TMP_PATH}/menu"
dialog --default-item ${NEXT} --backtitle "`backtitle`" --title "Advanced" \
@ -771,11 +781,55 @@ function advancedMenu() {
NEXT="u"
;;
u) editUserConfig; NEXT="e" ;;
t) tryRecoveryDSM ;;
e) break ;;
esac
done
}
###############################################################################
# Try to recovery a DSM already installed
function tryRecoveryDSM() {
dialog --backtitle "`backtitle`" --title "Try recovery DSM" --aspect 18 \
--infobox "Trying to recovery a DSM installed system" 0 0
if findAndMountDSMRoot; then
MODEL=""
BUILD=""
if [ -f "${DSMROOT_PATH}/.syno/patch/VERSION" ]; then
eval `cat ${DSMROOT_PATH}/.syno/patch/VERSION | grep unique`
eval `cat ${DSMROOT_PATH}/.syno/patch/VERSION | grep base`
if [ -n "${unique}" ] ; then
while read F; do
M="`basename ${F}`"
M="${M::-4}"
UNIQUE=`readModelKey "${M}" "unique"`
[ "${unique}" = "${UNIQUE}" ] || continue
# Found
modelMenu "${M}"
done < <(find "${MODEL_CONFIG_PATH}" -maxdepth 1 -name \*.yml | sort)
if [ -n "${MODEL}" ]; then
buildMenu ${base}
if [ -n "${BUILD}" ]; then
cp "${DSMROOT_PATH}/.syno/patch/zImage" "${SLPART_PATH}"
cp "${DSMROOT_PATH}/.syno/patch/rd.gz" "${SLPART_PATH}"
MSG="Found a installation:\nModel: ${MODEL}\nBuildnumber: ${BUILD}"
SN=`_get_conf_kv SN "${DSMROOT_PATH}/etc/synoinfo.conf"`
if [ -n "${SN}" ]; then
writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}"
MSG+="\nSerial: ${SN}"
fi
dialog --backtitle "`backtitle`" --title "Try recovery DSM" \
--aspect 18 --msgbox "${MSG}" 0 0
fi
fi
fi
fi
else
dialog --backtitle "`backtitle`" --title "Try recovery DSM" --aspect 18 \
--msgbox "Unfortunately I couldn't mount the DSM partition!" 0 0
fi
}
###############################################################################
# Permit user select the modules to include
function selectModules() {
@ -980,7 +1034,7 @@ function updateMenu() {
dialog --backtitle "`backtitle`" --title "Update arpl" --aspect 18 \
--yesno "Arpl updated with success to ${TAG}!\nReboot?" 0 0
[ $? -ne 0 ] && continue
reboot
arpl-reboot.sh config
exit
;;

View File

@ -25,6 +25,7 @@ mkdir -p "${RAMDISK_PATH}"
MODEL="`readConfigKey "model" "${USER_CONFIG_FILE}"`"
BUILD="`readConfigKey "build" "${USER_CONFIG_FILE}"`"
LKM="`readConfigKey "lkm" "${USER_CONFIG_FILE}"`"
SN="`readConfigKey "sn" "${USER_CONFIG_FILE}"`"
if [ ${BUILD} -ne ${buildnumber} ]; then
echo -e "\033[A\n\033[1;32mBuild number changed from \033[1;31m${BUILD}\033[1;32m to \033[1;31m${buildnumber}\033[0m"
@ -72,6 +73,8 @@ echo -n "."
for KEY in ${!SYNOINFO[@]}; do
_set_conf_kv "${KEY}" "${SYNOINFO[${KEY}]}" "${RAMDISK_PATH}/etc/synoinfo.conf" >"${LOG_FILE}" 2>&1 || dieLog
done
# Add serial number to synoinfo.conf, to help to recovery a installed DSM
_set_conf_kv "SN" "${SN}" "${RAMDISK_PATH}/etc/synoinfo.conf" >"${LOG_FILE}" 2>&1 || dieLog
# Patch /sbin/init.post
echo -n "."
@ -83,6 +86,8 @@ for KEY in ${!SYNOINFO[@]}; do
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc/synoinfo.conf'" >> "${TMP_PATH}/rp.txt"
echo "_set_conf_kv '${KEY}' '${SYNOINFO[${KEY}]}' '/tmpRoot/etc.defaults/synoinfo.conf'" >> "${TMP_PATH}/rp.txt"
done
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc/synoinfo.conf'" >> "${TMP_PATH}/rp.txt"
echo "_set_conf_kv 'SN' '${SN}' '/tmpRoot/etc.defaults/synoinfo.conf'" >> "${TMP_PATH}/rp.txt"
sed -e "/@@@CONFIG-GENERATED@@@/ {" -e "r ${TMP_PATH}/rp.txt" -e 'd' -e '}' -i "${RAMDISK_PATH}/sbin/init.post"
rm "${TMP_PATH}/rp.txt"

View File

@ -18,6 +18,7 @@ export EDITOR="/bin/nano"
export BOOTLOADER_PATH="/mnt/p1"
export SLPART_PATH="/mnt/p2" # Synologic partition
export CACHE_PATH="/mnt/p3"
export DSMROOT_PATH="/mnt/dsmroot"
export PATH="${PATH}:/opt/arpl"
if [ ! -f ${HOME}/.initialized ]; then