forked from adtac/climate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·237 lines (193 loc) · 6.47 KB
/
install
File metadata and controls
executable file
·237 lines (193 loc) · 6.47 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
PLAIN='\033[0m'
RED_BOLD='\033[1;31m'
GREEN_BOLD='\033[1;32m'
BLUE_BOLD='\033[1;34m'
YELLOW_BOLD='\033[1;33m'
PLAIN_BOLD='\033[1;37m'
# ----------------------------------------------------------------------------
# Utilities
trap ctrl_c INT
ctrl_c() {
tput cnorm
exit
}
spinner() {
local spin="\\|/-"
local i=0
tput civis
while kill -0 "$1" 2>/dev/null; do
i=$(( (i+1) %4 ))
printf "\b%s" "${spin:$i:1}"
sleep 0.07
done
tput cnorm
}
yesno() {
while true; do
printf "${BLUE}"
printf " • $1 "
if [[ $2 == "no" ]]; then
printf "${PLAIN}[yes | ${GREEN_BOLD}no${PLAIN}] "
read ans
if [[ -z "$ans" ]]; then
ans="no"
fi
else
printf "${PLAIN}[${GREEN_BOLD}yes${PLAIN} | no] "
read ans
if [[ -z "$ans" ]]; then
ans="yes"
fi
fi
if [[ $ans == "yes" ]] || [[ $ans == "y" ]]; then
return 0
elif [[ $ans == "no" ]] || [[ $ans == "n" ]]; then
return 1
else
printf " ${RED}Invalid answer. Please answer with 'yes' or 'no'."
fi
done
}
ask() {
printf "${PLAIN} • ${BLUE}$2 "
printf "${PLAIN}[${GREEN_BOLD}$3${PLAIN}] "
read ans
if [[ -z "$ans" ]]; then
ans="$3"
fi
eval "$1='"$ans"'"
}
command_exists () {
type "$1" &> /dev/null
}
system_verify() {
if ! command_exists $1; then
printf "${PLAIN} • ${RED}$1 missing.${PLAIN} "
if command_exists apt-get || command_exists yum || command_exists dnf; then
printf "Installing... "
if command_exists dnf && [[ "$3" != "-" ]]; then
sudo dnf install -y "$3" > /dev/null 2>&1 &
spinner $!
printf "\b${GREEN}Installed!"
elif command_exists yum && [[ "$3" != "-" ]]; then
sudo yum install -y "$3" > /dev/null 2>&1 &
spinner $!
printf "\b${GREEN}Installed!"
elif command_exists apt-get && [[ "$2" != "-" ]]; then
sudo apt-get install -y "$2" > /dev/null 2>&1 &
spinner $!
printf "\b${GREEN}Installed!"
else
printf "${RED}Package doesn't exist for your arch. Please install it manually."
fi
else
printf "Please install it manually."
fi
else
printf "${PLAIN} • ${GREEN}$1 exists!${PLAIN}"
fi
printf "\n"
}
npm_verify() {
if ! command_exists $1; then
printf "${PLAIN} • ${RED}$1 missing.${PLAIN} "
if [[ -n "$(which npm)" ]]; then
printf "Installing... "
sudo npm install -g "$2" > /dev/null 2>&1 &
spinner $!
printf "\b${GREEN}Installed!"
else
printf "Please install it manually using npm."
fi
else
printf "${PLAIN} • ${GREEN}$1 exists!${PLAIN}"
fi
printf "\n"
}
pip_verify() {
if ! command_exists $1; then
printf "${PLAIN} • ${RED}$1 missing.${PLAIN} "
if [[ -n "$(which npm)" ]]; then
printf "Installing... "
sudo pip install "$2" > /dev/null 2>&1 &
spinner $!
printf "\b${GREEN}Installed!"
else
printf "Please install it manually using pip."
fi
else
printf "${PLAIN} • ${GREEN}$1 exists!${PLAIN}"
fi
printf "\n"
}
main() {
INSTALL_DIR=/usr/local/bin
if [[ ! -z "$1" ]]; then
INSTALL_DIR="$1"
fi
if [[ ! -w "$INSTALL_DIR" ]]; then
printf "${RED_BOLD}Error: must be root to install.${PLAIN}\n"
exit
fi
printf "${RED_BOLD}"
printf "┌───────────────────┐\n"
printf "│ "
printf "${PLAIN_BOLD}"
printf "climate installer "
printf "${RED_BOLD}"
printf "│\n"
printf "└───────────────────┘\n"
if [[ ! -f "climate" ]]; then
printf "Downloading... "
system_verify "git" "git-all" "git-all"
git clone https://github.com/adtac/climate.git --depth=1 > /dev/null 2>&1 &
spinner $!
cd climate
fi
CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
printf "\n${PLAIN}Alright, let's get started with a few questions. Just press enter if you want to use the ${GREEN_BOLD}default value.\n\n"
SHOW_COMMAND=false
if yesno "Show commands before execution?" "no" ; then
SHOW_COMMAND=true
fi
ask EDITOR "What's your favourite editor?" "vi"
CLIMATE_EXEC="climate"
CLIMATE_SRC=$INSTALL_DIR/$CLIMATE_EXEC
printf "#!/usr/bin/env bash\n\n" > $CLIMATE_SRC
printf "SHOW_COMMAND=${SHOW_COMMAND}\n" >> $CLIMATE_SRC
printf "EDITOR=${EDITOR}\n" >> $CLIMATE_SRC
printf "\n" >> $CLIMATE_SRC
tail -n +3 "$CUR_DIR/climate" >> $CLIMATE_SRC
chmod +x $CLIMATE_SRC
printf "\nGreat. Now, let's check if you have the all requirements:\n\n"
# command Debian based RPM based
system_verify "upower" "upower" "upower"
system_verify "curl" "curl" "curl"
system_verify "rar" "rar" "-"
system_verify "unzip" "unzip" "unzip"
system_verify "7z" "p7zip-full" "p7zip"
system_verify "xdg-screensaver" "xdg-utils" "xdg-open"
system_verify "dig" "dnsutils" "bind-utils"
system_verify "git" "git-all" "git-all"
system_verify "python" "python" "python"
system_verify "pip" "python-pip" "python-pip"
system_verify "npm" "npm" "npm"
system_verify "fdupes" "fdupes" "fdupes"
system_verify "glances" "glances" "glances"
system_verify "sensors" "lm-sensors" "lm_sensors"
system_verify "sshfs" "sshfs" "fuse-sshfs"
npm_verify "http-server" "http-server"
npm_verify "is-up" "is-up-cli"
npm_verify "is-online" "is-online-cli"
pip_verify "speedtest" "speedtest-cli"
printf "\nNeat! You're all set. Run 'climate' to see the whole list "
printf "of commands supported. Enjoy!${PLAIN}\n"
}
main $@