Skip to content

Instantly share code, notes, and snippets.

@7aman
Created December 22, 2018 13:54
Show Gist options
  • Save 7aman/1565f4f35453791d13de5f22bc50a2cf to your computer and use it in GitHub Desktop.
Save 7aman/1565f4f35453791d13de5f22bc50a2cf to your computer and use it in GitHub Desktop.
Mount a shared folder from a windows host.
#!/bin/bash
command -v mount.cifs >/dev/null 2>&1 || {
echo "I require mount.cifs but it's not installed. You can install via apt:" >&2;
echo " sudo apt-get install cifs-utils"
echo ""
echo "Press any key to abort."
read
exit 1;
}
myPath=$HOME/tmp/$(uuidgen)
mkdir -p $myPath
echo 'Defaults:'
echo ' IP : 192.168.1.X (You must enter X)'
echo ' windows username : fakeuser'
echo ' windows password : fakepassword'
echo ''
read -p 'Use Default Value? [Yes]/no:' defaults
if [ "$defaults" = "" ]
then
read -p 'IP : 192.168.1.' winIP
winIP="192.168.1."$winIP
read -p 'windows shared folder : ' winDir
winUser=fakeuser
winPass=fakepassword
else
read -p 'IP : ' winIP
read -p 'windows shared folder : ' winDir
read -p 'username : ' winUser
if [ "$winUser" = "" ]
then
winUser=fakeuser
fi
read -sp 'password : ' winPass
if [ "$winPass" = "" ]
then
winPass=fakepassword
fi
fi
echo " "
sudo mount -t cifs "//"$winIP"/"$winDir $myPath -o dir_mode=0777,file_mode=0777,username=$winUser,password=$winPass
xdg-open $myPath
echo ""
read -p "Done with sharing? Ready to unmount folder?"
sudo umount "//"$winIP"/"$winDir
rmdir $myPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment