-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·218 lines (184 loc) · 6.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
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
217
#!/bin/bash
# Created by: WestleyK
# Email: westleyk@nym.hush.com
# version-1.0.4
# Date: Feb 2, 2018
# https://github.com/WestleyK/easy-clone
#
# The Clear BSD License
#
# Copyright (c) 2018 WestleyK
# All rights reserved.
#
# This software is licensed under a Clear BSD License.
#
set -e
HOME_FILE="home-dir.txt"
DEP="dependencies"
SCRIPT_NAME="hubget"
INSTALL_TO="/usr/local/bin"
STRCOMP_URL="https://github.com/WestleyR/str/raw/master/pre-compiled/x86_64/strcomp"
ECGO_URL="https://github.com/WestleyK/ecgo/raw/master/pre-compiled/ubuntu-x86_64/ecgo"
USERNAME=""
help_usage() {
ecgo -a "USAGE:
./install.sh [--user=username] [--prefix=/where/to/install]
[uninstall/remove, update]
DERSCTIPTION:
simple install script for: ${SCRIPT_NAME}.
INFO:
defalt installation : ${INSTALL_TO}/${SCRIPT_NAME}
source code: https://github.com/WestleyK/easy-clone"
exit 0
}
if [ ! -e "$DEP" ]; then
mkdir "$DEP"
fi
if ! [ -x "$(command -v ecgo)" ]; then
echo "ERROR: Need 'echo'"
echo
echo "This will automaticly download the precompiled code from github."
echo
echo "For install instrunctions, visit:"
echo "https://github.com/WestleyK/ecgo"
echo
wget -O "$DEP/ecgo" "$ECGO_URL"
chmod +x "$DEP/ecgo"
cp "$DEP/ecgo" "/usr/bin"
ecgo --info "'ecgo' Installed!" -l
fi
if ! [ -x "$(command -v strcomp)" ]; then
ecgo -error "Need 'strcomp'" -l
ecgo "This will automaticly download the precompiled code from github." -l
ecgo "For install instrunctions, visit:" -l "https://github.com/WestleyR/strcomp" -l
wget -O "$DEP/strcomp" "$STRCOMP_URL"
chmod +x "$DEP/strcomp"
cp "$DEP/strcomp" "/usr/bin"
ecgo --info "'strcomp' Installed!" -l
fi
uninstall_script() {
ecgo --warning "Uninstalling: ${SCRIPT_NAME}"
if [ ! -f "${INSTALL_TO}/${SCRIPT_NAME}" ]; then
ecgo -l --warning "Uninstall: ${SCRIPT_NAME}: Not in default install location."
SCRIPT_LOCATION=` which ${SCRIPT_NAME} `
ecgo --info "Uninstall: ${SCRIPT_NAME}: In: ${SCRIPT_LOCATION}"
if [ ! -w "$SCRIPT_LOCATION" ]; then
ecgo -l --fatal "Directory NOT writable: ${SCRIPT_LOCATION}."
ecgo --fatal "Uninstall failed." -l
ecgo "Try with \`sudo'"
exit 255
fi
rm -f "${SCRIPT_LOCATION}${SCRIPT_NAME}"
else
ecgo --info "Uninstall: ${SCRIPT_NAME}: In: ${INSTALL_TO}"
ecgo --warning "Uninstalling: ${SCRIPT_NAME}: From: ${INSTALL_TO}"
if [ ! -w "$INSTALL_TO" ]; then
ecgo -l --fatal "Directory NOT writable: ${INSTALL_TO}."
ecgo --fatal "Uninstall failed." -l
ecgo "Try with \`sudo'"
exit 255
fi
rm -f "${INSTALL_TO}${SCRIPT_NAME}"
fi
# ecgo --info "Removing auto-complete.sh from ~/.bashrc..."
IS_SOURCE=false
if [[ ! -z $( cat "${HOME}/.bashrc" | grep 'easy-clone/auto-complete.sh') ]]; then
ecgo -l -bold -negative --warning -yellow -negative "You should remove the following line from: " -bold "${HOME}/.bashrc:"
ecgo "$(cat ${HOME}/.bashrc | grep "source /home/westleyk/*easy-clone/auto-complete.sh" )" -l
IS_SOURCE=true
## sed -i '' "/source\ \/home\/westleyk\/*easy-clone\/auto-complete.sh/d" $file
# sed -ie '/source\ \/home\/westleyk\/*easy-clone\/auto-complete.sh/d' ~/foo
# cat ${HOME}/.bashrc | grep -v "source /home/westleyk/*easy-clone/auto-complete.sh" >> ${HOME}/foo
# ecgo "Removed source."
# else
# ecgo --info "No source to remove."
fi
ecgo -l --info "Uninstall: SUCCESSFULL!"
if [ "$IS_SOURCE" = true ]; then
ecgo -green "DONE. " -r -teal -bold "And remenber to remove the source line from your .bashrc" -l
else
ecgo -green "DONE." -l
fi
exit 0
}
check_args() {
OPTION="$1"
if [[ $(ecgo -a "$OPTION" | strcomp -s="--user=") = 0 ]]; then
USERNAME=` ecgo -a "$OPTION" | strcomp --cut-start=7 `
ecgo -d "USERNAME: ${USERNAME}"
elif [[ $(ecgo -a "$OPTION" | strcomp -s="--username=") = 0 ]]; then
USERNAME=` ecgo -a "$OPTION" | strcomp --cut-start=11 `
ecgo -d "USERNAME: ${USERNAME}"
elif [[ $(ecgo -a "$OPTION" | strcomp -s="--prefix=") = 0 ]]; then
INSTALL_TO=` ecgo -a "$OPTION" | strcomp --cut-start=9 `
ecgo -d "INSTALLTO: ${INSTALL_TO}"
elif [[ "$OPTION" = "-h" ]] || [[ "$OPTION" = "--help" ]]; then
help_usage
elif [[ "$OPTION" = "uninstall" ]] || [[ "$OPTION" = "remove" ]]; then
uninstall_script
else
ecgo --fatal "Install: ${OPTION}: Option not found."
exit 1
fi
}
for OPTION in "$@"; do
check_args "$OPTION"
done
ecgo --info "Installing to: ${INSTALL_TO}"
ecgo -d "Home: $HOME"
ecgo --debug "CWD: $(pwd)"
if [ ! -z $USERNAME ]; then
ecgo --info "Username set: $USERNAME"
NEW_HOME=`ecgo -a "/home/${USERNAME}"`
ecgo --debug "New home: ${NEW_HOME}"
if [ ! -f "${NEW_HOME}/.bashrc" ]; then
ecgo -l --fatal "Install: ${NEW_HOME}/.bashrc: File not found."
ecgo "Wrong username maybe?" -l
exit 255
fi
if [[ "$(pwd)" != "${NEW_HOME}/easy-clone" ]]; then
ecgo -l --warning "Install: easy-clone: Not in home directory: ${NEW_HOME}."
ecgo --warning "easy-clone should be in your home directory."
ecgo "Recomend to reinstall: ${SCRIPT_NAME} in your home direstory" -l
fi
if [[ -z $( cat "${NEW_HOME}/.bashrc" | grep 'easy-clone/auto-complete.sh') ]]; then
ecgo --info "Adding: source $(pwd)/auto-complete.sh to: ${NEW_HOME}/.bashrc"
ecgo -a "source $(pwd)/auto-complete.sh" >> "${NEW_HOME}/.bashrc"
fi
else
if [[ "$(pwd)" != "${HOME}/easy-clone" ]]; then
ecgo -l --fatal "Install failed."
ecgo "Try running with '--username=your_username'" -l
exit 100
fi
fi
if [[ -z $(cat "${HOME}/.bashrc" | grep 'easy-clone/auto-complete.sh') ]]; then
ecgo --info "Adding: source ${HOME}/easy-clone/auto-complete.sh to: ${HOME}/.bashrc"
ecgo -a "source ${HOME}/easy-clone/auto-complete.sh" >> "${HOME}/.bashrc"
fi
if [ -e "${INSTALL_TO}/${SCRIPT_NAME}" ]; then
ecgo --warning "Overriding existing ${SCRIPT_NAME} version..."
fi
ecgo --info "UID: ${UID}"
if [ $UID -ne 0 ]; then
ecgo --warning "UID is not 0, try running it with \`sudo'"
fi
ecgo --info "Installing: ${SCRIPT_NAME} to: ${INSTALL_TO}..."
if [ ! -d "$INSTALL_TO" ]; then
ecgo -l --fatal "Install: ${INSTALL_TO}: No such directory."
exit 255
fi
if [ ! -w "$INSTALL_TO" ]; then
ecgo -l --fatal "Directory NOT writable: ${INSTALL_TO}."
ecgo --fatal "Install failed." -l
exit 255
fi
ecgo --info "Directory writable: ${INSTALL_TO}."
cp -f "$SCRIPT_NAME" "$INSTALL_TO"
ecgo -i -green "DONE!"
ecgo -l -blue -bold "$SCRIPT_NAME" -r -yellow " Installed to: " -r -teal "${INSTALL_TO}"
ecgo -l -blue "To finish the install, do:"
ecgo -yellow -bold "$ " -r -yellow "source ~/.bashrc" -l
#
# End Install Script
#