-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwsl_automount.sh
55 lines (49 loc) · 1.15 KB
/
wsl_automount.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
if [ $# -eq 2 ]; then
if [ $UID -ne 0 ]; then
echo "This command must be run as root"
echo "Attempting to elevate $0"
sudo $0 $@
exit
fi
drive=`echo "${2:0:1}" | tr '[:upper:]' '[:lower:]'`
if [[ "$1" == "mount" ]]; then
if [ ! -d /mnt/$drive ]; then
echo "Creating dir"
mkdir /mnt/$drive
fi
echo "Mounting drive"
mount -t drvfs $drive: /mnt/$drive
else
if [[ "$1" == "unmount" ]]; then
echo "Umounting drive"
umount -l /mnt/$drive
rmdir /mnt/$drive
else
echo "Command was invalid, check usage"
fi
fi
else
if [[ "$1" == "install" ]]; then
file=`readlink -f $0 | sed 's/ /\\ /g'`
user=`whoami`
echo "Attempting to install wsl_automount.sh"
sudo sh -c "echo '$user ALL = (root) NOPASSWD:${file}' > /etc/sudoers.d/wsl_automount"
else
if [[ $# -eq 1 ]]; then
drive=`echo "${1:0:1}" | tr '[:upper:]' '[:lower:]'`
if [ -d /mnt/$drive ]; then
$0 unmount $1
else
$0 mount $1
fi
else
echo "usage: wsl_automount.sh comand path"
echo ""
echo "Commands"
echo "-----------------------------------"
echo "mount: mount the path"
echo "unmount: unmount the path"
fi
fi
fi