#!/bin/bash # # Purpose : SMB shares: which are mounted, and mounting one the way Finder # does. Sourced by configure.d/60-storage.sh and system/storage-mount. # smb://user@host/share and //user@host/share (as mount shows it) the same # way: no user, lower case, host without .local or Bonjour's ._smb._tcp.local, # %20 as a space share_key() { local s="${1#smb:}" host share s="${s#//}" s="${s#*@}" host="${s%%/*}" share="${s#*/}" host="${host%._smb._tcp.local}" host="${host%.local}" host="${host%.}" echo "$host/${share//%20/ }" | tr '[:upper:]' '[:lower:]' } # The SMB shares mounted now: "//user@host/share|mount point" per line smb_mounts() { mount -t smbfs | sed -nE 's#^(//[^ ]+) on (.+) \(smbfs.*#\1|\2#p' } # The mount point of a share, if it's mounted mounted_at() { local key line key="$(share_key "$1")" while IFS= read -r line; do if [ "$(share_key "${line%%|*}")" = "$key" ]; then echo "${line#*|}" return 0 fi done < <(smb_mounts) return 1 } host_of() { local s="${1#*://}" s="${s#*@}" echo "${s%%/*}" } mount_share() { osascript -e 'on run argv' -e 'mount volume (item 1 of argv)' -e 'end run' "$1" > /dev/null 2>&1 }