-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinstall.sh
103 lines (84 loc) · 2.92 KB
/
install.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/bash
wslalias_version="v2.4"
wslalias_dir="$HOME/.wsl-alias"
user=$(whoami)
echo
echo "Welcome to wsl-alias $wslalias_version installer"
echo
mkdir -p "$wslalias_dir"
cd "$wslalias_dir"
git clone -c advice.detachedHead=false -b "$wslalias_version" https://github.com/leongrdic/wsl-alias.git update
if [ -f "$wslalias_dir/env.sh" ]; then
rm -f update/env.sh
fi
echo
echo "Moving files and fixing permissions"
cp -r update/* .
rm -rf update
chmod +x wrapper.sh
chmod +x bin/wsl-alias
if [ $(stat -c "%a" "/mnt") != "777" ]; then
echo "Invalid permissions detected on the /mnt directory"
echo "You might be asked for your password to fix the permissions so that you can create new mountpoints for drives"
sudo chmod 777 /mnt
fi
# creating the aliases directory through windows to avoid WSL issue #3487
cmd.exe /c mkdir "%userprofile%\wsl-alias" 2>/dev/null
echo
echo "Do you want to grant your user to use the mount/umount commands without typing a password?"
echo "If you choose yes, you might be asked for your password to add a new sudoers entry"
echo "You can skip this step if you've had wsl-alias v2+ previously installed for this user"
echo -n "Answer (y/n): "
read setup_sudo
if [ "$setup_sudo" = "y" ]; then
setup_sudoers="$user ALL=(root) NOPASSWD: /bin/mount, /bin/umount"
if [ $(sudo grep -c "^$setup_sudoers" /etc/sudoers) == 1 ]; then
echo 'Entry already found in /etc/sudoers, not modifying'
else
sudo su -c "echo '$setup_sudoers' >> /etc/sudoers"
echo "Modified the /etc/sudoers file"
fi
fi
win_home=$(cmd.exe /c echo %userprofile% 2>/dev/null | sed -e 's/\r//g')
win_home=$(wslpath "$win_home")
wslalias_dir_win="$win_home/wsl-alias"
if [ -z "$(ls -A $wslalias_dir_win)" ]; then
# first time install
echo
echo "Choose a default alias which you'll use to pass commands from Windows to wsl"
echo "Note: this alias can't be 'wsl' because that's an internal Windows command"
echo -n "Command [b]: "
read setup_alias
if [ -z "$setup_alias" ] || [ "$setup_alias" == "wsl" ]; then
setup_alias="b"
fi
cmd_path="$wslalias_dir_win/$setup_alias.bat"
cp template.bat "$cmd_path"
perl -pi -e 's/ \{alias_command\}//g' "$cmd_path"
echo
echo
echo "The installation has completed!"
echo
echo "Add the following directory to your PATH enviroment variable in Windows:"
echo " %userprofile%\\wsl-alias"
echo
echo "After that you'll be able to use it to call wsl commands from Windows"
echo "To add a new alias from Windows, use:"
echo " $setup_alias wsl-alias"
echo
else
# update
echo
echo
echo "The update has completed!"
echo
echo "Make sure the following directory is still present"
echo "in your PATH enviroment variable in Windows:"
echo " %userprofile%\\wsl-alias"
echo
echo "Note: you may have to recreate your aliases after the update."
echo "Please refer to the GitHub releases page for more info."
echo " https://github.com/leongrdic/wsl-alias/releases"
echo
setup_alias="[default alias]"
fi