Skip to content

Instantly share code, notes, and snippets.

@mindfullsilence
Last active June 13, 2020 22:16
Show Gist options
  • Select an option

  • Save mindfullsilence/933b9e8d7035cc7b6c99b753ece73bb1 to your computer and use it in GitHub Desktop.

Select an option

Save mindfullsilence/933b9e8d7035cc7b6c99b753ece73bb1 to your computer and use it in GitHub Desktop.

Revisions

  1. mindfullsilence revised this gist Jun 13, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions quickmount.sh
    Original file line number Diff line number Diff line change
    @@ -53,4 +53,9 @@ function disconnect() {
    MOUNTED=()

    echo "Disconnected all mounted drives."
    }

    # list all currently mounted folders
    function mounted() {
    printf '%s\n' "${MOUNTED[@]}" | sort -r
    }
  2. mindfullsilence renamed this gist Jun 13, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. mindfullsilence revised this gist Jun 13, 2020. No changes.
  4. mindfullsilence revised this gist Jun 13, 2020. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    # Installation

    1) Copy the contents of the quickmount.sh file to your ~/.bash_profile
    2) Edit lines 4, 5, and 6 with the appropriate information for connecting to your synology NAS
    3) Edit/duplicate the `projects` function for any folders you want to mount on your mac.
    4) Save your ~/.bash_profile, then in terminal run `source ~/.bash_profile`

    # Usage

    To mount a directory from terminal, just call your function:

    ```bash
    mindfullsilences-MBP:~ mindfullsilence$ projects
    mindfullsilences-MBP:Projects mindfullsilence$
    ```

    To disconnect all mounted folders, call the `disconnect` command:

    ```bash
    mindfullsilences-MBP:Projects mindfullsilence$ disconnect
    Disconnected all mounted drives.
    mindfullsilences-MBP:~ mindfullsilence$
    ```
  5. mindfullsilence created this gist Jun 13, 2020.
    56 changes: 56 additions & 0 deletions quickmount.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    MOUNTED=()

    function synology() {
    USER="admin" #synology login username
    PASSWORD="myP%40ssW%7B%7Drd" # should be the uri encoded password. Eg: "myP@ssW{}rd" becomes "myP%40ssW%7B%7Drd"
    SERVER="SynologyDS718" # the name you gave your server during setup. Can also be an IP address

    MOUNTPOINT=$1
    SERVERDIR=$2
    SERVERURI="$SERVER/$2"

    # ensures directory exists for mounting
    if [ ! -d $MOUNTPOINT ]; then
    mkdir $MOUNTPOINT
    fi

    # mounts directory if not already mounted
    # TODO: this has an inheret flaw in that if the server folder is empty,
    # this check will fail, and attempt to mount an already mounted drive.
    # Unlikely to ever be the case for me so ¯\_(ツ)_/¯
    if [ ! "$(ls -A $MOUNTPOINT)" ]; then
    mount_smbfs //$USER:$PASSWORD@$SERVERURI $MOUNTPOINT
    fi

    MOUNTED+=($1)
    }

    # Recreate this function for each mountpoint
    # and nas location you want to quickly mount
    function projects() {
    # Where you want the nas folder to be accessible on your mac
    MOUNTPOINT=/Users/mindfullsilence/Documents/Projects

    # Where the folder exists on the NAS server (dont include the beginning "/")
    SERVERDIR=Projects/web

    synology $MOUNTPOINT $SERVERDIR

    cd $MOUNTPOINT
    }

    # Unmounts all mounted locations
    function disconnect() {
    # cd to home so umount doesnt ever fail
    cd ~

    #unmount all points
    for i in "${MOUNTED[@]}"; do
    umount $i
    done

    # clear the array of mountpoints
    MOUNTED=()

    echo "Disconnected all mounted drives."
    }