Skip to content

Instantly share code, notes, and snippets.

@sam2332
Created February 22, 2022 15:47
Show Gist options
  • Save sam2332/c4e0cea182000e42bcdb560634823495 to your computer and use it in GitHub Desktop.
Save sam2332/c4e0cea182000e42bcdb560634823495 to your computer and use it in GitHub Desktop.
bashrc addon for connecting to windows shares from a linux host if connected to vpn.sh
share_mount_dir='/home/srudloff/shares'
vpn_connected=`ifconfig | grep "tun0"|wc -c`
if (( vpn_connected > 0 )); then
if [[ $(keyring get VPN_SYSTEM DOMAIN | wc -c) -eq 0 ]];then
keyring set VPN_SYSTEM DOMAIN
fi
SMB_DOMAIN=`keyring get VPN_SYSTEM DOMAIN`
if [[ $(keyring get VPN_$SMB_DOMAIN USER | wc -c) -eq 0 ]];then
keyring set VPN_$SMB_DOMAIN USER
fi
SMB_USER=`keyring get VPN_$SMB_DOMAIN USER`
if [[ $(keyring get VPN_$SMB_DOMAIN $SMB_USER | wc -c) -eq 0 ]];then
keyring set VPN_$SMB_DOMAIN $SMB_USER
fi
if ! mountpoint -q "$share_mount_dir/shared/" || ! mountpoint -q "$share_mount_dir/home"; then
SMB_PASS=`keyring get VPN_$SMB_DOMAIN $SMB_USER`
fi
if ! mountpoint -q "$share_mount_dir/home"; then
echo "Mounting Work Home Drive"
sudo mount.cifs "//SMB_PATH/home" $share_mount_dir/home -o dom=$SMB_DOMAIN,pass=$SMB_PASS,user=$SMB_USER,vers=3.02,rw,dir_mode=0755,file_mode=0755,uid=1000,gid=1000
fi
if ! mountpoint -q "$share_mount_dir/shared/";then
echo "Mounting Work Department Shared Drive"
sudo mount.cifs "//SMBPATH/Shared" $share_mount_dir/shared/ -o dom=$SMB_DOMAIN,pass=$SMB_PASS,user=$SMB_USER,vers=3.02,rw,dir_mode=0755,file_mode=0755,uid=1000,gid=1000
fi
fi
@sam2332
Copy link
Author

sam2332 commented Feb 22, 2022

If you have any improvements please let me know
i was thinking of converting it to python so i could have a map of shares

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment