How can I automount a network share on macOS Catalina?
This is the article that i used https://useyourloaf.com/blog/using-the-mac-os-x-automounter/ and my code:
networkPath
persistent="true"
username
password
function debugEcho () {
if (true) then
echo -e $1
fi
}
shareName=${networkPath##*/}
debugEcho "$shareName"
userPersistent=$username
userPersistent=$(echo "$username" | tr "\\" ";")
if [[ $username == *"@"* ]]; then
OIFS=$IFS
IFS=@
set -- $username
user=$1
domain=$2
debugEcho "$user $domain"
userPersistent="$domain;$user"
IFS=$OIFS
debugEcho "$userPersistent"
fi
username=${username//@/"%40"}
debugEcho $username
shareName="TEST7"
if [[ "$persistent" == "true" ]]; then
mkdir -p /System/Volumes/Data/mnt
LINE="/System/Volumes/Data/mnt/Resources auto_resources"
FILE='/etc/auto_master'
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
touch /etc/auto_resources
LINE="$shareName -fstype=smbfs ://$userPersistent:$password@$networkPath"
FILE='/etc/auto_resources'
grep -qF -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
automount -cv
open "/System/Volumes/Data/mnt/Resources/"
path1="/System/Volumes/Data/mnt/Resources/"
path2="~/Desktop/"
debugEcho "$path1"
ln -s $path1 $path2
else
open "smb://$username:$password@$networkPath"
fi