-
Notifications
You must be signed in to change notification settings - Fork 2
/
install
216 lines (192 loc) · 6.24 KB
/
install
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#! /bin/zsh
# Get to the root of av-shell install
cd $(dirname "$0")
# Import color
source config/color
av_shell_prompt="${txtblu}[AV-SHELL]${txtrst}"
# Check for a help flag
if [[ $1 == "--help" ]]; then
echo -e "${av_shell_prompt} Install the av-shell plugin"
echo
echo "Usage: $0 [--yes]"
echo " $0 --help"
exit 0
fi
# Error Check
function error_check {
if [[ $1 == 0 ]]; then
echo -e "$2 - ${txtgrn}success${txtrst}"
else
echo -e "$2 - ${txtred}failed${txtrst}"
exit $1
fi
}
# Check dependencies
echo "Checking for dependencies...\n"
dependencies="brew go jq gum k9s dive gorun"
to_install=""
for dep in $=dependencies; do
tool_path=$(which $dep | grep -v 'not found')
installed=$?
result=$(if [[ $installed -eq 0 ]]; then echo "[${txtgrn} OK ${txtrst}]"; else echo "[${txtylw} NO ${txtrst}]"; fi)
printf "${txtb}%-15s %-6s\n" "$dep" "$result"
if [[ "$dep" != "go" && "$dep" != "brew" && "$dep" != "gorun" ]]; then
if [[ $installed -eq 1 ]]; then
to_install="$to_install $dep"
fi
fi
done
to_install=${to_install#"${to_install%%[![:space:]]*}"}
echo
# Figure out if we should install brew automatically
if [[ -z "$(which brew | grep -v 'not found')" ]]; then
just_install=false
if [[ "$1" == "--yes" ]]; then
just_install=true
else
echo
echo -n "Would you like to install brew? (y/n): "
read install
if [[ "$install" == "y" ]]; then
just_install=true
fi
fi
if [[ $just_install == false ]]; then
echo
echo "Brew must be installed to ensure dependencies are fulfilled,"
echo "run the following command and retry"
echo " |"
echo ' | bash -c \"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\"'
echo " |"
echo
exit 1
fi
NONINTERACTIVE=1 bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
error_check $? "brew install"
else
echo "brew is already installed - ${txtgrn}success${txtrst}"
fi
# Ensure brew is on path
if [[ "$(uname)" == "Linux" ]]; then
eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
output=$(cat ~/.zshrc | grep "linuxbrew")
if [[ $output != *"shellenv"* ]]; then
echo 'eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)' >> ~/.zshrc
fi
error_check $? "ensuring brew is on PATH"
fi
# With brew installed then we can just install stuff
if [[ ! -z "$(which brew | grep -v 'not found')" && -n "$to_install" ]]; then
just_install=false
if [[ "$1" == "--yes" ]]; then
just_install=true
else
echo
echo -n "Would you like to install missing dependencies with brew? (y/n): "
read install
if [[ "$install" == "y" ]]; then
just_install=true
fi
fi
if [[ $just_install == false ]]; then
echo
echo "You can install dependencies with the following command:"
echo " |"
echo " | brew install ${to_install[@]}"
echo " |"
echo
exit 1
fi
eval "brew install ${to_install[@]} &> /dev/null"
error_check $? "brew dependencies install"
else
echo "brew dependencies are already installed - ${txtgrn}success${txtrst}"
fi
# Add go/bin path to PATH
output=$(cat ~/.zshrc | grep "~/.local/bin")
if [[ $output != *"PATH"* ]]; then
echo "export PATH=\$PATH:~/.local/bin" >> ~/.zshrc
fi
error_check $? "ensuring ~/.local/bin is on PATH"
# Add go/bin path to PATH
export PATH=$PATH:~/go/bin
output=$(cat ~/.zshrc | grep "~/go/bin")
if [[ $output != *"PATH"* ]]; then
echo "export PATH=\$PATH:~/go/bin" >> ~/.zshrc
fi
error_check $? "ensuring ~/go/bin is on PATH"
# With golang installed we can add gorun
if [[ -z "$(which gorun | grep -v 'not found')" ]]; then
just_install=false
if [[ "$1" == "--yes" ]]; then
just_install=true
else
echo
echo -n "Would you like to install missing gorun dependency? (y/n): "
read install
if [[ "$install" == "y" ]]; then
just_install=true
fi
fi
if [[ $just_install == false ]]; then
echo
echo "You can install gorun with the following command:"
echo " |"
echo " | go install github.com/erning/gorun@latest"
echo " |"
echo
exit 1
fi
go install github.com/erning/gorun@latest &> /dev/null
error_check $? "gorun install"
else
echo "gorun is already installed - ${txtgrn}success${txtrst}"
fi
# Symlink av command
INSTALL_DIR="$HOME/.local/bin"
rm -f ${INSTALL_DIR}/av > /dev/null 2>&1
ln -s `pwd`/av ${INSTALL_DIR}/av > /dev/null 2>&1
error_check $? "Creating symlink in ${txtpur}${INSTALL_DIR}${txtrst}"
# Detect oh-my-zsh and install av-shell plugin
if [[ ! -z "$(zsh -i -c 'which omz' | grep -v 'not found')" || -z "$(cat ~/.zshrc | grep plugins | grep ' av)\|(av \| av ')" ]]; then
just_install=false
if [[ "$1" == "--yes" ]]; then
just_install=true
else
echo
echo -n "Would you like to install av-shell plugin for oh-my-zsh? (y/n): "
read install
if [[ "$install" == "y" ]]; then
just_install=true
fi
fi
if [[ $just_install == false ]]; then
echo
echo "Later, you can install av-shell plugin for oh-my-zsh with the following commands:"
echo " |"
echo " | ln -sf ~/.av/zsh-plugin/av.plugin.zsh ~/.oh-my-zsh/custom/plugins/av"
echo " | omz plugin enable av"
echo " |"
echo
exit 0
fi
mkdir -p ~/.oh-my-zsh/custom/plugins
if [[ -d ~/.oh-my-zsh/custom/plugins/av ]]; then
rm -rf ~/.oh-my-zsh/custom/plugins/av
fi
ln -sf ~/.av/zsh-plugin ~/.oh-my-zsh/custom/plugins/av &>/dev/null 2>&1
error_check $? "av-shell plugin for oh-my-zsh install"
output=$(zsh -i -c 'omz plugin enable av')
if [[ $output == *"av is already enabled"* ]]; then
echo ""
fi
error_check $? "adding av to oh-my-zsh plugins list"
else
echo "av oh-my-zsh plugin already installed - ${txtgrn}success${txtrst}"
fi
echo
echo "Next steps:"
echo ""
echo "1. 'source ~/.zshrc' to reload your shell"
echo "2. In your favorite project directory run 'av init' to setup the project"
echo