-
Notifications
You must be signed in to change notification settings - Fork 56
/
install.sh
42 lines (37 loc) · 1.12 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
#!/usr/bin/env bash
echo "Downloading win-sudo..."
# Set error handler
trap "echo 'Failed to install, sorry :('; exit 1" ERR
# Clean default install dir
if [ -d "$HOME/bin/win-sudo" ] ; then
echo "Cleaning $HOME/bin/win-sudo..."
rm -rfv "$HOME/bin/win-sudo"
fi
# Download latest sources to a fresh directory
mkdir -pv "$HOME/bin/win-sudo"
cd "$_"
git init -q
git config core.sparsecheckout true
mkdir -p .git/info
echo s/ >>.git/info/sparse-checkout
git remote add -mf base https://github.com/purplesyringa/win-sudo.git
git pull -q base master
# Start processing bash initialization files
# We're leaving out /.profile to avoid permission issues (at least in Git Bash)
touch "$HOME/.bashrc"
for f in "$HOME/.bashrc" "$HOME/.bash_profile"
do
echo "Processing $f"
if [ -f "$f" ] ; then
if grep -q "source \"$HOME/bin/win-sudo/s/path.sh\"" "$f" ; then
echo "Sudo initialization already in file " $f
break
else
echo "Appending sudo initialization to " $f
echo "[ -f \"$HOME/bin/win-sudo/s/path.sh\" ] && source \"$HOME/bin/win-sudo/s/path.sh\"" >>"$f"
break
fi
fi
done
echo "Win-sudo successfully installed!"
exec bash