-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·134 lines (118 loc) · 2.88 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -eET
# Options
##
__usage()
{
cat << EOF
Usage: $0 [BRANCH] [INSTALL METHOD]
INSTALL METHOD:
global Install globally.
user Install to user. (default)
local Install to current directory.
OPTIONS:
--help Show this message.
EOF
exit 0
}
_sudo=""
if test "$*"; then
options="$*"
if echo "$options" | grep "\-\-help" > /dev/null; then
__usage
fi
if echo "$options" | grep "global" > /dev/null; then
install_method=global
options="$(echo "$options" | sed 's/global//')"
install_path="/usr/local/bin"
if (( UID != 0 )); then
_sudo="sudo "
fi
elif echo "$options" | grep "local" > /dev/null; then
install_method=local
install_path="."
options="$(echo "$options" | sed 's/local//')"
elif echo "$options" | grep "user" > /dev/null; then
install_method=user
install_path="$HOME/.bin"
options="$(echo "$options" | sed 's/user//')"
fi
fi
# setup
##
options=$( echo $options )
test "$options" && version=$options
test "$version" || version="latest"
source="https://raw.githubusercontent.com/odb/shunt/master/shunt.sh"
target="shunt.sh"
execln="shunt"
# display banner
##
echo "Installing shunt"
echo "------------------"
echo " "
# check superuser if method not specified
##
if ! test "$install_method"; then
install_method="user"
install_path="$HOME/.bin"
if (( UID == 0 )); then
install_method="global"
install_path="/usr/local/bin"
fi
fi
# ensure install directory
##
test -d $install_path || $_sudo mkdir -p $install_path
# fetch latest
##
cd $install_path
if test -f $target; then
echo "> Backing up previous version:"
$_sudo mv -v $target $target.bak
echo " "
fi
echo "> Downloading $source:"
$_sudo curl -O $source
$_sudo chmod 755 $install_path/$target
# create executable symlink
##
if [ "$install_method" != "local" ]; then
test -L $execln || $_sudo ln -s $target $execln
echo "> Install path: $install_path/$execln"
else
echo "> Install path: $install_path/$target"
fi
# update path
##
export_string="\nexport PATH=$install_path:\$PATH # Add shunt to PATH"
report=false
if [ "$install_method" = "user" ]; then
if test -f $HOME/.zshrc; then
if ! grep "$install_path" $HOME/.zshrc 2>&1 > /dev/null; then
echo -e "$export_string" >> $HOME/.zshrc
fi
elif test -f $HOME/.profile; then
if ! grep "$install_path" $HOME/.profile 2>&1 > /dev/null; then
echo -e "$export_string" >> $HOME/.profile
report=true
fi
elif test -f $HOME/.bashrc; then
if ! grep "$install_path" $HOME/.bashrc 2>&1 > /dev/null; then
echo -e "$export_string" >> $HOME/.bashrc
report=true
fi
else
echo " "
echo "WARNING: Please add $install_path to your PATH."
fi
else
report=false
fi
if $report; then
echo " "
echo "NOTE: Please log out and log back in to ensure that 'shunt' is available to your shell."
fi
echo " "
echo "DONE"
# vim: ft=sh: