diff --git a/CHANGES.txt b/CHANGES.txt index f5a19f3..3ee89f3 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,12 @@ +v3.0.14 +- Added support for InfiniBand expansion units for RS2421+, RS2421RP+ and RS2821RP+ NAS. + - Supports RX1217RP, RX1217, RX1214RP, RX1214, RX1211RP, RX1211, DX1215II, DX1215 or DX1211 expansion units. +- Removed editing synoinfo.conf as it only "support_ew_20_eunit" only relates to extended warranty. + +v2.1.13 +- Added checks to prevent running on unsupported Synology NAS model. + - Needs syno_slot_mapping command and /etc/model.dtb file. + v2.1.12 - Bug fix for false "Failed to delete tmp files" log entries when script updates itself. - Bug first appeared in v1.0.6 diff --git a/syno_enable_eunit.sh b/syno_enable_eunit.sh index 686be13..770c1b2 100644 --- a/syno_enable_eunit.sh +++ b/syno_enable_eunit.sh @@ -12,7 +12,7 @@ # sudo -i /volume1/scripts/syno_enable_eunit.sh #----------------------------------------------------------------------------------- -scriptver="v2.1.12" +scriptver="v3.0.14" script=Synology_enable_eunit repo="007revad/Synology_enable_eunit" scriptname=syno_enable_eunit @@ -25,7 +25,7 @@ if [ ! "$(basename "$BASH")" = bash ]; then fi # Check script is running on a Synology NAS -if ! /usr/bin/uname -a | grep -i synology >/dev/null; then +if ! /usr/bin/uname -a | grep -q -i synology; then echo "This script is NOT running on a Synology NAS!" echo "Copy the script to a folder on the Synology" echo "and run it from there." @@ -48,8 +48,9 @@ Options: -r, --restore Restore from backups to undo changes --unit=EUNIT Automatically enable specified expansion unit Only needed when script is scheduled - EUNIT is dx517, dx513, dx213, dx510, rx418, - rx415 or rx410 + EUNIT is dx517, dx513, dx213, dx510, rx418, rx415, + rx410, rx1217rp, rx1217, rx1214r, rx1214, rxX1211rp, + rx1211, dx1215ii, dx1215 or dx1211 -e, --email Disable colored text in output scheduler emails --autoupdate=AGE Auto update script (useful when script is scheduled) AGE is how many days old a release must be before @@ -72,10 +73,9 @@ EOF } -# Save options used +# Save options used for getopts args=("$@") - autoupdate="" # Check for flags with getopt @@ -105,8 +105,14 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \ break ;; --unit) # Specify eunit to enable for task scheduler - if [[ ${2,,} =~ ^(d|r)x[0-9]+$ ]]; then - unit="${2^^}" + if [[ ${2,,} =~ ^(d|r)x[0-9]+(rp|ii)?$ ]]; then + if [[ ${2:(-2)} == "rp" ]]; then + # Convert to upper case except rp at end + unit="$(b=${2:0:-2} && echo -n "${b^^}")rp" + else + # Convert to upper case + unit="${2^^}" + fi else echo -e "Invalid argument '$2'\n" exit 2 # Invalid argument @@ -271,7 +277,7 @@ echo -e "Running from: ${scriptpath}/$scriptfile\n" scriptvol=$(echo "$scriptpath" | cut -d"/" -f2) vg=$(lvdisplay | grep /volume_"${scriptvol#volume}" | cut -d"/" -f3) md=$(pvdisplay | grep -B 1 -E '[ ]'"$vg" | grep /dev/ | cut -d"/" -f3) -if grep "$md" /proc/mdstat | grep nvme >/dev/null; then +if grep "$md" /proc/mdstat | grep -q nvme; then echo -e "${Yellow}WARNING${Off} Don't store this script on an NVMe volume!" fi @@ -430,7 +436,10 @@ if which syno_slot_mapping >/dev/null; then else echo -e "${Cyan}None${Off}" fi - echo "" + #echo "" +else + echo -e "${Error}ERROR${Off} Unsupported Synology NAS model. No syno_slot_mapping command!" + exit 1 # No syno_slot_mapping file fi @@ -451,6 +460,9 @@ if [[ -f /etc.defaults/model.dtb ]]; then # Is device tree model dtb2_file="/etc/model${hwrev}.dtb" #dts_file="/etc.defaults/model${hwrev}.dts" dts_file="/tmp/model${hwrev}.dts" +else + echo -e "${Error}ERROR${Off} Unsupported Synology NAS model. No model.dtb file!" + exit 1 # No model.dtb file fi synoinfo="/etc.defaults/synoinfo.conf" @@ -510,9 +522,7 @@ restore_orig(){ if [[ -f ${synoinfo}.bak ]]; then setting="$(/usr/syno/bin/synogetkeyvalue "${synoinfo}.bak" support_ew_20_eunit)" setting2="$(/usr/syno/bin/synogetkeyvalue "${synoinfo}" support_ew_20_eunit)" - if [[ $setting == "$setting2" ]]; then - echo -e "${Cyan}OK${Off} ${synoinfo}" - else + if [[ $setting != "$setting2" ]]; then if /usr/syno/bin/synosetkeyvalue "$synoinfo" support_ew_20_eunit "$setting"; then /usr/syno/bin/synosetkeyvalue "$synoinfo2" support_ew_20_eunit "$setting" echo -e "Restored ${synoinfo}" @@ -599,126 +609,45 @@ fi #---------------------------------------------------------- # Check currently enabled expansion units -check_key_value(){ - # $1 is path/file - # $2 is key - setting="$(/usr/syno/bin/synogetkeyvalue "$1" "$2")" - if [[ -f $1 ]]; then - if [[ -n $2 ]]; then - echo -e "${Yellow}$2${Off} = $setting" >&2 - else - echo -e "Key name not specified!" >&2 - fi - else - echo -e "File not found: $1" >&2 - fi -} +supported_eunits=("DX517" "DX513" "DX213" "DX510" "RX418" "RX415" "RX410" \ +"RX1217rp" "RX1217" "RX1214rp" "RX1214" "RX1211rp" "RX1211" \ +"DX1215II" "DX1215" "DX1211") -check_section_key_value(){ - # $1 is path/file - # $2 is section - # $3 is key - # $4 is description - setting="$(/usr/syno/bin/get_section_key_value "$1" "$2" "$3")" - if [[ -f $1 ]]; then - if [[ -n $2 ]]; then - if [[ -n $3 ]]; then - if [[ $setting == "yes" ]]; then - echo -e "${Cyan}$4${Off} is enabled for ${Yellow}$3${Off}" >&2 - else - echo -e "${Cyan}$4${Off} is ${Cyan}not${Off} enabled for ${Yellow}$3${Off}" >&2 - fi - else - echo -e "Key name not specified!" >&2 - fi +check_modeldtb(){ + # $1 is DX517 or RX418 etc + if [[ -f "${dtb2_file}" ]]; then + if grep -q --text "$1" "${dtb2_file}"; then + echo -e "${Cyan}$1${Off} is enabled in ${Yellow}${dtb2_file}${Off}" >& 2 else - echo -e "Section name not specified!" >&2 + echo -e "${Cyan}$1${Off} is ${Cyan}not${Off} enabled in ${Yellow}${dtb2_file}${Off}" >& 2 fi - else - echo -e "File not found: $1" >&2 fi -} - -check_modeldtb(){ - # $1 is DX517 or RX418 etc if [[ -f "${dtb_file}" ]]; then - if grep --text "$1" "${dtb_file}" >/dev/null; then + if grep -q --text "$1" "${dtb_file}"; then echo -e "${Cyan}$1${Off} is enabled in ${Yellow}${dtb_file}${Off}" >& 2 else echo -e "${Cyan}$1${Off} is ${Cyan}not${Off} enabled in ${Yellow}${dtb_file}${Off}" >& 2 fi fi - if [[ -f "${dtb2_file}" ]]; then - if grep --text "$1" "${dtb2_file}" >/dev/null; then - echo -e "${Cyan}$1${Off} is enabled in ${Yellow}${dtb2_file}${Off}" >& 2 - else - echo -e "${Cyan}$1${Off} is ${Cyan}not${Off} enabled in ${Yellow}${dtb2_file}${Off}" >& 2 - fi - fi } check_enabled(){ - # /etc.defaults/synoinfo.conf - setting=$(/usr/syno/bin/synogetkeyvalue "$synoinfo" support_ew_20_eunit) - IFS=',' read -r -a eunits_array <<< "$setting" - for e in "${eunits_array[@]}"; do - echo -e "${Cyan}${e#Synology-}${Off} is enabled in ${Yellow}${synoinfo}${Off}" - done echo "" - - # /etc/synoinfo.conf - setting2=$(/usr/syno/bin/synogetkeyvalue "$synoinfo2" support_ew_20_eunit) - IFS=',' read -r -a eunits_array2 <<< "$setting2" - for e in "${eunits_array2[@]}"; do -# if [[ ${eunits_array[*]} =~ "$e" ]]; then - if [[ ${eunits_array[*]} =~ $e ]]; then - echo -e "${Cyan}${e#Synology-}${Off} is enabled in ${Yellow}${synoinfo2}${Off}" + for e in "${supported_eunits[@]}"; do + if grep -q --text "$e" "${dtb_file}"; then + check_modeldtb "${e#Synology-}" fi done echo "" - - for e in "${eunits_array[@]}"; do - check_modeldtb "${e#Synology-}" - done - echo "" } if [[ $check == "yes" ]]; then - echo "" + #echo "" check_enabled exit fi -show_enabled(){ - # /etc.defaults/synoinfo.conf - setting=$(/usr/syno/bin/synogetkeyvalue "$synoinfo" support_ew_20_eunit) - IFS=',' read -r -a eunits_array <<< "$setting" - # /etc/synoinfo.conf - setting2=$(/usr/syno/bin/synogetkeyvalue "$synoinfo2" support_ew_20_eunit) - IFS=',' read -r -a eunits_array2 <<< "$setting2" - for e in "${eunits_array[@]}"; do - count="1" -# if [[ ${eunits_array2[*]} =~ "$e" ]]; then - if [[ ${eunits_array2[*]} =~ $e ]]; then - count=$((count +1)) - fi - if grep --text "${e#Synology-}" "${dtb_file}" >/dev/null; then - count=$((count +1)) - fi - if grep --text "${e#Synology-}" "${dtb2_file}" >/dev/null; then - count=$((count +1)) - fi - if [[ $count == "4" ]]; then - echo -e "${Cyan}${e#Synology-}${Off} is enabled" - else - echo -e "${Cyan}${e#Synology-}${Off} ${Yellow}partially${Off} enabled" - fi - done - echo "" -} - - #------------------------------------------------------------------------------ # Enable unsupported Synology expansion units @@ -753,28 +682,6 @@ backupdb(){ return 0 } -edit_synoinfo(){ - # $1 is the eunit model - if [[ -n $1 ]]; then - # Check if already enabled in synoinfo.conf - # support_ew_20_eunit="Synology-DX517,Synology-RX418" - setting=$(synogetkeyvalue "$synoinfo" support_ew_20_eunit) - if [[ $setting != *"$1"* ]]; then - #backupdb "$synoinfo" long || exit 1 # debug - backupdb "$synoinfo" || exit 1 # Failed to backup file - newsetting="${setting},Synology-${1}" - if synosetkeyvalue "$synoinfo" support_ew_20_eunit "$newsetting"; then - synosetkeyvalue "$synoinfo2" support_ew_20_eunit "$newsetting" - echo -e "Enabled ${Cyan}$1${Off} in ${Yellow}synoinfo.conf${Off}" >&2 - else - echo -e "${Error}ERROR 9${Off} Failed to enable $1 in synoinfo.conf!" >&2 - fi - else - echo -e "${Cyan}$1${Off} already enabled in ${Yellow}synoinfo.conf${Off}" >&2 - fi - fi -} - dts_ebox(){ # $1 is the ebox model # $2 is the dts file @@ -901,6 +808,112 @@ elif [[ $1 == RX418 ]] || [[ $1 == RX415 ]] || [[ $1 == RX410 ]]; then }; EORX4bay +elif [[ ${_12bays[*]} =~ $1 ]]; then + cat >> "$2" <; + pmp_link = <0x00>; + }; + }; + + pmp_slot@2 { + + libata { + EMID = <0x00>; + pmp_link = <0x01>; + }; + }; + + pmp_slot@3 { + + libata { + EMID = <0x00>; + pmp_link = <0x02>; + }; + }; + + pmp_slot@4 { + + libata { + EMID = <0x01>; + pmp_link = <0x00>; + }; + }; + + pmp_slot@5 { + + libata { + EMID = <0x01>; + pmp_link = <0x01>; + }; + }; + + pmp_slot@6 { + + libata { + EMID = <0x01>; + pmp_link = <0x02>; + }; + }; + + pmp_slot@7 { + + libata { + EMID = <0x02>; + pmp_link = <0x00>; + }; + }; + + pmp_slot@8 { + + libata { + EMID = <0x02>; + pmp_link = <0x01>; + }; + }; + + pmp_slot@9 { + + libata { + EMID = <0x02>; + pmp_link = <0x02>; + }; + }; + + pmp_slot@10 { + + libata { + EMID = <0x03>; + pmp_link = <0x00>; + }; + }; + + pmp_slot@11 { + + libata { + EMID = <0x03>; + pmp_link = <0x01>; + }; + }; + + pmp_slot@12 { + + libata { + EMID = <0x03>; + pmp_link = <0x02>; + }; + }; + }; +}; +EORX12bay + fi } @@ -981,7 +994,7 @@ edit_modeldtb(){ # Edit model.dts for c in "${eboxs[@]}"; do # Edit model.dts if needed - if ! grep "$c" "$dtb_file" >/dev/null; then + if ! grep -q "$c" "$dtb_file"; then dts_ebox "$c" "$dts_file" echo -e "Added ${Cyan}$c${Off} to ${Yellow}model${hwrev}.dtb${Off}" >&2 reboot=yes @@ -1009,42 +1022,27 @@ edit_modeldtb(){ # Select expansion unit to enable # Show currently enabled eunit(s) -show_enabled +check_enabled enable_eunit(){ case "$choice" in - DX517) - edit_synoinfo "$choice" - eboxs=("$choice") && edit_modeldtb - return - ;; - DX513) - edit_synoinfo "$choice" + DX517|DX513|DX510) eboxs=("$choice") && edit_modeldtb return ;; DX213) - edit_synoinfo "$choice" eboxs=("$choice") && edit_modeldtb return ;; - DX510) - edit_synoinfo "$choice" + RX418|RX415|RX410) eboxs=("$choice") && edit_modeldtb return ;; - RX418) - edit_synoinfo "$choice" + RX1217rp|RX1217|RX1214rp|RX1214|RX1211rp|RX1211) eboxs=("$choice") && edit_modeldtb return ;; - RX415) - edit_synoinfo "$choice" - eboxs=("$choice") && edit_modeldtb - return - ;; - RX410) - edit_synoinfo "$choice" + DX1215II|DX1215|DX1211) eboxs=("$choice") && edit_modeldtb return ;; @@ -1065,11 +1063,18 @@ enable_eunit(){ esac } -eunits=("Check" "DX517" "DX513" "DX213" "DX510" "RX418" "RX415" "RX410" "Restore" "Quit") +_12bays=("RX1217rp" "RX1217" "RX1214rp" "RX1214" "RX1211rp" "RX1211" \ +"DX1215II" "DX1215" "DX1211") + +eunits=("DX517" "DX513" "DX213" "DX510" "RX418" "RX415" "RX410" \ +"RX1217rp" "RX1217" "RX1214rp" "RX1214" "RX1211rp" "RX1211" \ +"DX1215II" "DX1215" "DX1211" \ +"Restore" "Quit") + if [[ -n $unit ]]; then # Expansion Unit supplied as argument - if [[ ${eunits[*]} =~ "${unit^^}" ]]; then - choice="${unit^^}" + if [[ ${eunits[*]} =~ ${unit} ]]; then + choice="${unit}" echo -e "$choice selected\n" enable_eunit else @@ -1081,6 +1086,7 @@ else select choice in "${eunits[@]}"; do echo -e "You selected $choice \n" enable_eunit + break done fi #echo ""