Skip to content

Commit

Permalink
Merge pull request #35 from 007revad/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
007revad authored May 19, 2024
2 parents a2b114e + ccf1634 commit be7be2f
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 29 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v2.1.11
- Added ability to schedule the script and specify the expansion unit to enable.
--unit=EUNIT where EUNIT is dx517, dx513, dx213, dx510, rx418, rx415 or rx410

v2.0.10
- Added Check and Restore as menu choices (so you don't need to run the script with an option to check or restore).
- Now shows which expansion units are currently connected.
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ This script will work for the following Synology NAS models:
## How to run the script

### Scheduling the script in Synology's Task Scheduler

See <a href=how_to_schedule.md/>How to schedule a script in Synology Task Scheduler</a>

### Run the script via SSH

[How to enable SSH and login to DSM via SSH](https://kb.synology.com/en-global/DSM/tutorial/How_to_login_to_DSM_with_root_permission_via_SSH_Telnet)
Expand All @@ -68,22 +72,24 @@ sudo -s /volume1/scripts/syno_enable_eunit.sh
> **Note** <br>
> Replace /volume1/scripts/ with the path to where the script is located.
**Options:**
### Options:
```YAML
-c, --check Check expansion units status
-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
-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
auto-updating. AGE must be a number: 0 or greater
AGE is how many days old a release must be before
auto-updating. AGE must be a number: 0 or greater
-h, --help Show this help message
-v, --version Show the script version

```

## What about DSM updates?

After any DSM update you will need to run this script again.
After any DSM update you will need to run this script again, if you don't have it scheduled to run at boot.

<br>

Expand Down
27 changes: 27 additions & 0 deletions how_to_schedule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# How to schedule a script in Synology Task Scheduler

To schedule a script to run on your Synology at boot-up or shutdown follow these steps:

**Note:** You can setup a schedule task and leave it disabled, so it only runs when you select the task in the Task Scheduler and click on the Run button.

1. Go to **Control Panel** > **Task Scheduler** > click **Create** > and select **Triggered Task**.
2. Select **User-defined script**.
3. Enter a task name.
4. Select **root** as the user (The script needs to run as root).
5. Select **Boot-up** as the event that triggers the task.
6. Leave **Enable** ticked.
7. Click **Task Settings**.
8. Optionally you can tick **Send run details by email** and **Send run details only when the script terminates abnormally** then enter your email address.
9. In the box under **User-defined script** type the path to the script.
- e.g. If you saved the script to a shared folder on volume1 called "scripts" you'd type:
- `/volume1/scripts/syno_enable_eunit.sh -e --unit=EUNIT`
- Replace EUNIT with your expansion unit model: dx517, dx513, dx213, dx510, rx418, rx415 or rx410
11. Click **OK** to save the settings.

Here's some screenshots showing what needs to be set:

<p align="leftr"><img src="images/schedule1.png"></p>

<p align="leftr"><img src="images/schedule2.png"></p>

<p align="leftr"><img src="images/schedule3.png"></p>
Binary file added images/schedule1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/schedule2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/schedule3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 53 additions & 24 deletions syno_enable_eunit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# sudo -i /volume1/scripts/syno_enable_eunit.sh
#-----------------------------------------------------------------------------------

scriptver="v2.0.10"
scriptver="v2.1.11"
script=Synology_enable_eunit
repo="007revad/Synology_enable_eunit"
scriptname=syno_enable_eunit
Expand All @@ -21,15 +21,15 @@ scriptname=syno_enable_eunit
if [ ! "$(basename "$BASH")" = bash ]; then
echo "This is a bash script. Do not run it with $(basename "$BASH")"
printf \\a
exit 1
exit 1 # Not running in bash
fi

# Check script is running on a Synology NAS
if ! /usr/bin/uname -a | grep -i synology >/dev/null; 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."
exit 1
exit 1 # Not Synology NAS
fi


Expand All @@ -46,6 +46,10 @@ Usage: $(basename "$0") [options]
Options:
-c, --check Check expansion units status
-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
-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
Expand Down Expand Up @@ -76,7 +80,7 @@ autoupdate=""

# Check for flags with getopt
if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \
check,restore,help,version,email,autoupdate:,log,debug -- "${args[@]}")"; then
check,restore,unit:,help,version,email,autoupdate:,log,debug -- "${args[@]}")"; then
eval set -- "$options"
while true; do
case "${1,,}" in
Expand All @@ -100,6 +104,15 @@ if options="$(getopt -o abcdefghijklmnopqrstuvwxyz0123456789 -l \
restore=yes
break
;;
--unit) # Specify eunit to enable for task scheduler
if [[ ${2,,} =~ ^(d|r)x[0-9]+$ ]]; then
unit="${2^^}"
else
echo -e "Invalid argument '$2'\n"
exit 2 # Invalid argument
fi
break
;;
-e|--email) # Disable colour text in task scheduler emails
color=no
;;
Expand Down Expand Up @@ -156,7 +169,7 @@ fi
if [[ $( whoami ) != "root" ]]; then
ding
echo -e "${Error}ERROR${Off} This script must be run as sudo or root!"
exit 1
exit 1 # Not running as sudo or root
fi

# Get DSM major and minor versions
Expand Down Expand Up @@ -258,7 +271,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 cat /proc/mdstat | grep "$md" | grep nvme >/dev/null; then
if grep "$md" /proc/mdstat | grep nvme >/dev/null; then
echo -e "${Yellow}WARNING${Off} Don't store this script on an NVMe volume!"
fi

Expand Down Expand Up @@ -748,7 +761,7 @@ edit_synoinfo(){
setting=$(synogetkeyvalue "$synoinfo" support_ew_20_eunit)
if [[ $setting != *"$1"* ]]; then
#backupdb "$synoinfo" long || exit 1 # debug
backupdb "$synoinfo" || exit 1
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"
Expand Down Expand Up @@ -917,7 +930,7 @@ install_binfile(){
if ! curl -kL -m 30 --connect-timeout 5 "$2" -o "/tmp/$1"; then
echo -e "${Error}ERROR${Off} Failed to download ${1}!"
#return
exit 1
exit 1 # Failed to download binfile
fi
binfile="/tmp/${1}"

Expand All @@ -928,11 +941,11 @@ install_binfile(){
if [[ $md5 != "$6" ]]; then
echo "Expected md5: $6"
echo -e "${Error}ERROR${Off} Downloaded $1 md5 hash does not match!"
exit 1
exit 1 # Downloaded $1 md5 hash does not match
fi
else
echo -e "${Error}ERROR${Off} Cannot add expansion unit without ${1}!"
exit 1
exit 1 # User answered no
fi
fi

Expand All @@ -959,7 +972,7 @@ edit_modeldtb(){
if [[ -x /usr/sbin/dtc ]]; then

# Backup model.dtb
backupdb "$dtb_file" || exit 1
backupdb "$dtb_file" || exit 1 # Failed to backup model.dtb

# Output model.dtb to model.dts
dtc -q -I dtb -O dts -o "$dts_file" "$dtb_file" # -q Suppress warnings
Expand Down Expand Up @@ -998,53 +1011,50 @@ edit_modeldtb(){
# Show currently enabled eunit(s)
show_enabled

eunits=("Check" "DX517" "DX513" "DX213" "DX510" "RX418" "RX415" "RX410" "Restore" "Quit")
PS3="Select your Expansion Unit: "
select choice in "${eunits[@]}"; do
echo -e "You selected $choice \n"
enable_eunit(){
case "$choice" in
DX517)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
DX513)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
DX213)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
DX510)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
RX418)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
RX415)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
RX410)
edit_synoinfo "$choice"
eboxs=("$choice") && edit_modeldtb
break
return
;;
Check)
check_enabled
exit
;;
Restore)
restore_orig
break
return
;;
Quit) exit ;;
"") echo "Invalid Choice!" ;;
Expand All @@ -1053,7 +1063,26 @@ select choice in "${eunits[@]}"; do
exit
;;
esac
done
}

eunits=("Check" "DX517" "DX513" "DX213" "DX510" "RX418" "RX415" "RX410" "Restore" "Quit")
if [[ -n $unit ]]; then
# Expansion Unit supplied as argument
if [[ ${eunits[*]} =~ "${unit^^}" ]]; then
choice="${unit^^}"
echo -e "$choice selected\n"
enable_eunit
else
echo -e "Unsupported expansion unit argument: $unit\n"
exit 2 # Unsupported expansion unit argument
fi
else
PS3="Select your Expansion Unit: "
select choice in "${eunits[@]}"; do
echo -e "You selected $choice \n"
enable_eunit
done
fi
#echo ""


Expand Down

0 comments on commit be7be2f

Please sign in to comment.