Created
February 22, 2023 12:28
-
-
Save joeperpetua/f05c152894d8c9822277110ef2e055c1 to your computer and use it in GitHub Desktop.
Script to mount/unmount Synology encrypted shared folders via CLI using synoshare built-in tool.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/sh | |
| HELP='false' | |
| while getopts ":hm:s:" flag | |
| do | |
| case "${flag}" in | |
| h) HELP='true';; | |
| m) METHOD=${OPTARG};; | |
| s) SHARED_FOLDER=${OPTARG};; | |
| \?) echo "Invalid option: -$OPTARG" >&2; exit 1;; | |
| :) echo "Option -$OPTARG requires an argument."; exit 1;; | |
| esac | |
| done | |
| if ${HELP} || [ "$#" == 0 ]; then | |
| echo -e "\nThis script helps you to mount and unmount Synology NAS encrypted shared folders in a secure way using the built-in synoshare tool in DSM.\n"; | |
| echo -e "\nUsage:"; | |
| echo -e " sh ./synomount.sh [-h] -m METHOD -s SHARED_FOLDER" | |
| echo -e "\nOptions:"; | |
| echo -e " -h Shows this message"; | |
| echo -e " -m METHOD Method to execute { unmount | mount }"; | |
| echo -e " -s SHARED_FOLDER Shared folder name to mount/unmount"; | |
| echo -e "\nExample:"; | |
| echo " sh ./synomount.sh -m mount -s test_folder"; | |
| echo " sh ./synomount.sh -m unmount -s test_folder"; | |
| exit 1; | |
| fi | |
| : ${METHOD:?Missing method, please specify the -m argument.}; | |
| : ${SHARED_FOLDER:?Missing shared folder, please specify the -s argument.}; | |
| if [ ${METHOD} = "unmount" ]; then | |
| echo "Unmounting ${SHARED_FOLDER}..."; | |
| synoshare --enc_unmount $SHARED_FOLDER; | |
| echo "Process done."; | |
| elif [ ${METHOD} = "mount" ]; then | |
| echo -n "Enter encryption key:"; | |
| read -s ENC_KEY; | |
| echo -e "\nMounting ${SHARED_FOLDER}..."; | |
| /usr/syno/sbin/synoshare --enc_mount $SHARED_FOLDER $ENC_KEY | |
| echo "Process done."; | |
| else | |
| echo -e "No valid method was provided.\nAccepted methods are 'mount' or 'unmount'."; | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If your objective is to run this automatically, then you can simply use the native DSM command to mount the shared folder and add it to a cron task or scheduled task in DSM:
synoshare --enc_mount example_shared_folder example_passwordThe downside is that this will leave the encryption key in plain text inthe
/var/log/bash_history.logfile, but as you want to leave the encryption key in a file anyways, it should not be too different. Not secure but that is on you.This gist was thought to not leave any trace of the encryption key in the file system, so what you are asking can certainly be done, but would be opposite of the whole idea behind this script.