diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3dfeeb56..78030ab2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,7 @@ jobs: # Copy files echo "Copying files" sed 's/^ARPL_VERSION=.*/ARPL_VERSION="'${VERSION}'"/' -i files/board/arpl/overlayfs/opt/arpl/include/consts.sh + echo "${VERSION}" > files/board/arpl/p1/ARPL-VERSION cp -Ru files/* .buildroot/ cd .buildroot echo "Generating default config" diff --git a/VERSION b/VERSION index e60bb9e8..0deec97f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0-beta7 +1.0-beta8 diff --git a/files/board/arpl/overlayfs/opt/arpl/include/consts.sh b/files/board/arpl/overlayfs/opt/arpl/include/consts.sh index 09677e80..003bdf05 100644 --- a/files/board/arpl/overlayfs/opt/arpl/include/consts.sh +++ b/files/board/arpl/overlayfs/opt/arpl/include/consts.sh @@ -1,5 +1,5 @@ -ARPL_VERSION="1.0-beta7" +ARPL_VERSION="1.0-beta8" # Define paths TMP_PATH="/tmp" diff --git a/files/board/arpl/overlayfs/opt/arpl/include/functions.sh b/files/board/arpl/overlayfs/opt/arpl/include/functions.sh index 9b7b3d5d..d9bd5d29 100644 --- a/files/board/arpl/overlayfs/opt/arpl/include/functions.sh +++ b/files/board/arpl/overlayfs/opt/arpl/include/functions.sh @@ -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 +} diff --git a/files/board/arpl/overlayfs/opt/arpl/init.sh b/files/board/arpl/overlayfs/opt/arpl/init.sh index b2703e26..8853c5ef 100755 --- a/files/board/arpl/overlayfs/opt/arpl/init.sh +++ b/files/board/arpl/overlayfs/opt/arpl/init.sh @@ -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}" diff --git a/files/board/arpl/overlayfs/opt/arpl/menu.sh b/files/board/arpl/overlayfs/opt/arpl/menu.sh index 2a9d4767..523d386e 100755 --- a/files/board/arpl/overlayfs/opt/arpl/menu.sh +++ b/files/board/arpl/overlayfs/opt/arpl/menu.sh @@ -61,74 +61,83 @@ function backtitle() { ############################################################################### # Shows available models to user choose one function modelMenu() { - RESTRICT=1 - FLGBETA=0 - dialog --backtitle "`backtitle`" --title "Model" --aspect 18 \ - --infobox "Reading models" 0 0 - while true; do - echo "" > "${TMP_PATH}/menu" - FLGNEX=0 - while read M; do - M="`basename ${M}`" - M="${M::-4}" - PLATFORM=`readModelKey "${M}" "platform"` - DT="`readModelKey "${M}" "dt"`" - BETA="`readModelKey "${M}" "beta"`" - [ "${BETA}" = "true" -a ${FLGBETA} -eq 0 ] && continue - # Check id model is compatible with CPU - COMPATIBLE=1 - if [ ${RESTRICT} -eq 1 ]; then - for F in `readModelArray "${M}" "flags"`; do - if ! grep -q "^flags.*${F}.*" /proc/cpuinfo; then - COMPATIBLE=0 - FLGNEX=1 - break - fi - done + if [ -z "${1}" ]; then + RESTRICT=1 + FLGBETA=0 + dialog --backtitle "`backtitle`" --title "Model" --aspect 18 \ + --infobox "Reading models" 0 0 + while true; do + echo "" > "${TMP_PATH}/menu" + FLGNEX=0 + while read M; do + M="`basename ${M}`" + M="${M::-4}" + PLATFORM=`readModelKey "${M}" "platform"` + DT="`readModelKey "${M}" "dt"`" + BETA="`readModelKey "${M}" "beta"`" + [ "${BETA}" = "true" -a ${FLGBETA} -eq 0 ] && continue + # Check id model is compatible with CPU + COMPATIBLE=1 + if [ ${RESTRICT} -eq 1 ]; then + for F in `readModelArray "${M}" "flags"`; do + if ! grep -q "^flags.*${F}.*" /proc/cpuinfo; then + COMPATIBLE=0 + FLGNEX=1 + break + fi + done + fi + [ "${DT}" = "true" ] && DT="-DT" || DT="" + [ ${COMPATIBLE} -eq 1 ] && echo "${M} \"\Zb${PLATFORM}${DT}\Zn\" " >> "${TMP_PATH}/menu" + done < <(find "${MODEL_CONFIG_PATH}" -maxdepth 1 -name \*.yml | sort) + [ ${FLGNEX} -eq 1 ] && echo "f \"\Z1Disable flags restriction\Zn\"" >> "${TMP_PATH}/menu" + [ ${FLGBETA} -eq 0 ] && echo "b \"\Z1Show beta models\Zn\"" >> "${TMP_PATH}/menu" + dialog --backtitle "`backtitle`" --colors --menu "Choose the model" 0 0 0 \ + --file "${TMP_PATH}/menu" 2>${TMP_PATH}/resp + [ $? -ne 0 ] && return + resp=$(<${TMP_PATH}/resp) + [ -z "${resp}" ] && return + if [ "${resp}" = "f" ]; then + RESTRICT=0 + continue fi - [ "${DT}" = "true" ] && DT="-DT" || DT="" - [ ${COMPATIBLE} -eq 1 ] && echo "${M} \"\Zb${PLATFORM}${DT}\Zn\" " >> "${TMP_PATH}/menu" - done < <(find "${MODEL_CONFIG_PATH}" -maxdepth 1 -name \*.yml | sort) - [ ${FLGNEX} -eq 1 ] && echo "f \"\Z1Disable flags restriction\Zn\"" >> "${TMP_PATH}/menu" - [ ${FLGBETA} -eq 0 ] && echo "b \"\Z1Show beta models\Zn\"" >> "${TMP_PATH}/menu" - dialog --backtitle "`backtitle`" --colors --menu "Choose the model" 0 0 0 \ - --file "${TMP_PATH}/menu" 2>${TMP_PATH}/resp - [ $? -ne 0 ] && return - resp=$(<${TMP_PATH}/resp) - [ -z "${resp}" ] && return - if [ "${resp}" = "f" ]; then - RESTRICT=0 - continue - fi - if [ "${resp}" = "b" ]; then - FLGBETA=1 - continue - fi - # If user change model, clean buildnumber and S/N - if [ "${MODEL}" != "${resp}" ]; then - MODEL=${resp} - writeConfigKey "model" "${MODEL}" "${USER_CONFIG_FILE}" - BUILD="" - writeConfigKey "build" "${BUILD}" "${USER_CONFIG_FILE}" - SN="" - writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}" - # Delete old files - rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" - DIRTY=1 - fi - break - done + if [ "${resp}" = "b" ]; then + 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} + writeConfigKey "model" "${MODEL}" "${USER_CONFIG_FILE}" + BUILD="" + writeConfigKey "build" "${BUILD}" "${USER_CONFIG_FILE}" + SN="" + writeConfigKey "sn" "${SN}" "${USER_CONFIG_FILE}" + # Delete old files + rm -f "${ORI_ZIMAGE_FILE}" "${ORI_RDGZ_FILE}" "${MOD_ZIMAGE_FILE}" "${MOD_RDGZ_FILE}" + DIRTY=1 + fi } ############################################################################### # Shows available buildnumbers from a model to user choose one function buildMenu() { ITEMS="`readConfigEntriesArray "builds" "${MODEL_CONFIG_PATH}/${MODEL}.yml" | sort -r`" - 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 + 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 ;; @@ -1105,10 +1159,14 @@ while true; do echo "a \"Addons\"" >> "${TMP_PATH}/menu" echo "x \"Cmdline menu\"" >> "${TMP_PATH}/menu" echo "i \"Synoinfo menu\"" >> "${TMP_PATH}/menu" - echo "d \"Build the loader\"" >> "${TMP_PATH}/menu" fi fi echo "v \"Advanced menu\"" >> "${TMP_PATH}/menu" + if [ -n "${MODEL}" ]; then + if [ -n "${BUILD}" ]; then + echo "d \"Build the loader\"" >> "${TMP_PATH}/menu" + fi + fi if loaderIsConfigured; then echo "b \"Boot the loader\" " >> "${TMP_PATH}/menu" fi @@ -1117,7 +1175,7 @@ while true; do echo "c \"Clean disk cache\"" >> "${TMP_PATH}/menu" fi echo "p \"Update menu\"" >> "${TMP_PATH}/menu" - echo "e \"Exit\"" >> "${TMP_PATH}/menu" + echo "e \"Exit\"" >> "${TMP_PATH}/menu" dialog --default-item ${NEXT} --backtitle "`backtitle`" --colors \ --menu "Choose the option" 0 0 0 --file "${TMP_PATH}/menu" \ @@ -1131,7 +1189,7 @@ while true; do x) cmdlineMenu; NEXT="i" ;; i) synoinfoMenu; NEXT="d" ;; d) make; NEXT="v" ;; - v) advancedMenu; NEXT="d" ;; + v) advancedMenu; NEXT="b" ;; b) boot ;; k) keymapMenu ;; c) dialog --backtitle "`backtitle`" --title "Cleaning" --aspect 18 \ diff --git a/files/board/arpl/overlayfs/opt/arpl/model-configs/DS923+.yml b/files/board/arpl/overlayfs/opt/arpl/model-configs/DS923+.yml index 0ff5f784..1c14bd86 100644 --- a/files/board/arpl/overlayfs/opt/arpl/model-configs/DS923+.yml +++ b/files/board/arpl/overlayfs/opt/arpl/model-configs/DS923+.yml @@ -23,7 +23,7 @@ serial: - "2040" - "20C0" - "2150" - middle: "SBR" + middle: "TQR" suffix: "alpha" disks: 4 builds: diff --git a/files/board/arpl/overlayfs/opt/arpl/ramdisk-patch.sh b/files/board/arpl/overlayfs/opt/arpl/ramdisk-patch.sh index 60878b68..b0597e76 100755 --- a/files/board/arpl/overlayfs/opt/arpl/ramdisk-patch.sh +++ b/files/board/arpl/overlayfs/opt/arpl/ramdisk-patch.sh @@ -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 "." @@ -80,9 +83,11 @@ sed -e "/@@@CONFIG-MANIPULATORS-TOOLS@@@/ {" -e "r ${TMP_PATH}/rp.txt" -e 'd' -e rm "${TMP_PATH}/rp.txt" touch "${TMP_PATH}/rp.txt" 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/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" diff --git a/files/board/arpl/overlayfs/root/.bashrc b/files/board/arpl/overlayfs/root/.bashrc index 8d86203d..1e160928 100644 --- a/files/board/arpl/overlayfs/root/.bashrc +++ b/files/board/arpl/overlayfs/root/.bashrc @@ -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 diff --git a/files/board/arpl/p1/ARPL-VERSION b/files/board/arpl/p1/ARPL-VERSION new file mode 100644 index 00000000..0deec97f --- /dev/null +++ b/files/board/arpl/p1/ARPL-VERSION @@ -0,0 +1 @@ +1.0-beta8 diff --git a/img-gen.sh b/img-gen.sh index ed13e442..d79b569d 100755 --- a/img-gen.sh +++ b/img-gen.sh @@ -71,6 +71,7 @@ fi echo "Copying files" VERSION=`cat VERSION` sed 's/^ARPL_VERSION=.*/ARPL_VERSION="'${VERSION}'"/' -i files/board/arpl/overlayfs/opt/arpl/include/consts.sh +echo "${VERSION}" > files/board/arpl/p1/ARPL-VERSION cp -Ru files/* .buildroot/ cd .buildroot diff --git a/update-list.yml b/update-list.yml index 01b2bc5d..141178d5 100644 --- a/update-list.yml +++ b/update-list.yml @@ -2,4 +2,5 @@ replace: ".buildroot/output/images/bzImage": "/mnt/p3/bzImage-arpl" ".buildroot/output/images/rootfs.cpio.xz": "/mnt/p3/initrd-arpl" "files/board/arpl/p1/grub/grub.cfg": "/mnt/p1/grub/grub.cfg" + "files/board/arpl/p1/ARPL-VERSION" : "/mnt/p1/ARPL-VERSION" remove: