-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·480 lines (400 loc) · 15.3 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
#!/bin/bash
# installer for guru-client. ujo.guru casa@ujo.guru 2017-2024
modules_to_install=(ai android audio backup cal conda convert corsair display dokuwiki fingrid game mqtt note place print program project radio say scan ssh stamp tag telegram timer tmux tor trans tunnel vol vpn yle youtube)
code_modules=(cheatsheet config counter daemon flag help install keyboard mount net os prompt system uninstall unmount user )
[[ -f $HOME/.gururc ]] && installed=true || installed=
TARGET_BIN="$HOME/bin"
TARGET_CFG="$HOME/.config/guru"
bash_rc="$HOME/.bashrc"
core_rc="$HOME/.gururc"
backup_rc="$HOME/.bashrc.backup-by-guru"
export GURU_CALL="guru"
export GURU_USER="$USER"
export GURU_BIN="$TARGET_BIN"
export GURU_CORE_FOLDER="`pwd`/core"
export GURU_CFG="$HOME/.config/guru"
source $GURU_CORE_FOLDER/common.sh
# check if colors possible
if echo "$TERM" | grep "256" >/dev/null ; then
if echo "$COLORTERM" | grep "true" >/dev/null ; then
GURU_FLAG_COLOR=true
# set only needed colors
C_NORMAL='\033[0m'
C_GRAY='\033[38;2;169;169;169m'
C_GREY='\033[38;2;169;169;169m'
C_DARK_GRAY='\033[38;2;128;128;128m'
C_DARK_GREY='\033[38;2;128;128;128m'
C_GREEN='\033[38;2;0;128;0m'
C_RED='\033[38;2;255;0;0m'
C_LIGHT_BLUE='\033[38;2;173;216;230m'
C_WHITE='\033[38;2;255;255;255m'
fi
export GURU_COLOR=true
fi
install.main () {
# Install main
date
# Step 1) parse arguments
install.arguments $@ || gr.msg -x 100 "argumentation error"
# Step 2) check and uninstall previous version
install.check || gr.msg -x 110 "check caused exit"
gr.msg -v1 -c white "installing $(core/core.sh version)"
# Step 3) modify and add .rc files
install.rcfiles || gr.msg -x 120 "rc file modification error"
check.rcfiles
# Step 4) create folder structure
install.folders || gr.msg -x 140 "error during creating folders"
check.folders
# Step 5) install core
install.core || gr.msg -x 150 "error during installing core"
check.core
# Step 6) install options
if [[ $install_dev ]] ; then
install.dev || gr.msg -x 160 "error during installing dev"
#check.dev
fi
# Step 7) install modules
install.modules && check.modules || gr.msg -x 170 "error when installing modules"
# Step 8) set up launcher
ln -f -s "$TARGET_BIN/core.sh" "$TARGET_BIN/$GURU_CALL" || gr.msg -x 180 "core linking error"
# Step 9) save statistics
echo "${code_modules[@]}" > "$TARGET_CFG/installed.core"
echo "${installed_modules[@]}" > "$TARGET_CFG/installed.modules"
echo "${modified_files[@]}" > "$TARGET_CFG/modified.files"
echo "${installed_files[@]}" > "$TARGET_CFG/installed.files"
# Step 10) export user configuration
install.config || gr.msg -x 180 "user configuration error"
# Step 11) printout pass and statistics if verbose set
gr.msg -c white "guru-cli v$($TARGET_BIN/core.sh version) installed"
gr.msg -v1 -c light_blue "installed ${#installed_core[@]} core modules"
gr.msg -v2 -c dark_grey "${installed_core[@]}"
gr.msg -v1 -c light_blue "installed ${#installed_modules[@]} modules"
gr.msg -v2 -c dark_grey "${installed_modules[@]}"
gr.msg -v1 -c light_blue "modified ${#modified_files[@]} file(s)"
gr.msg -v2 -c dark_grey "${modified_files[@]}"
gr.msg -v1 -c light_blue "copied ${#installed_files[@]} files"
gr.msg -v2 -c dark_grey "${installed_files[@]}"
# Step 12) Release pause flag that may be set by uninstaller and return
if [[ $installed ]]; then
source flag.sh
if flag.main running ; then
flag.rm pause
sleep 1
gr.end caps
fi
fi
return 0
}
install.help () {
gr.msg -c white "guru-client install help "
gr.msg
gr.msg "usage: ./install.sh -f|-r|-d|-v|-V|-h|-p [desktop|laptop|server|phone] |-u <user>"
gr.msg
gr.msg -c white "flags:"
gr.msg " -f force re-install "
gr.msg " -u <user> set user name "
# gr.msg " -p [platform] select installation platform: desktop|laptop|server|phone "
gr.msg " -d install also dev stuff "
gr.msg " -r install all module requirements (experimental)"
gr.msg " -v 0..3 set verbose level "
gr.msg " -h print this help "
gr.msg
gr.msg -c white "example:"
gr.msg " ./install.sh -dfV -u $USER"
return 0
}
install.arguments () {
# Process flags and arguments
export GURU_VERBOSE=0
TEMP=`getopt --long -o "dfcrhlsv:u:p:" "$@"`
eval set -- "$TEMP"
while true ; do
case "$1" in
-d) install_dev=true
shift ;;
-f) force_overwrite=true
shift ;;
-c) configure_after_install=true
shift ;;
-r) install_requiremets=true
shift ;;
-s) gr.msg "TBD"
shift ;;
-h) install.help
shift ;;
-l) export LIGTH_INSTALL=true
shift ;;
-v) export GURU_VERBOSE=$2
shift 2 ;;
-u) export GURU_USER=$2
shift 2 ;;
*) break
esac
done
local _arg="$@"
[[ "$_arg" != "--" ]] && ARGUMENTS="${_arg#* }"
case "$1" in
help)
install.help
return 0
esac
}
install.copy () {
# copy folders witout subfolders from source to target and keep track of copied files
local _from="$1" ; shift
local _to="$1" ; shift
gr.msg -n -v1 "$@ " ; gr.msg -v2
_file_list=( $(ls $_from/*) )
for _file_to_copy in "${_file_list[@]}" ; do
if cp -rf "$_file_to_copy" "$_to" ; then
gr.msg -v1 -V2 -n -c grey "."
gr.msg -v2 -c grey "${_file_to_copy/$_from/$_to}"
installed_files=( ${installed_files[@]} ${_file_to_copy/$_from/$_to} )
else
gr.msg -N -c yellow "$_file_to_copy copy failed"
fi
done
gr.msg -v1 -V2 -c green " done"
return 0
}
install.check () {
# Check installation, reinstall if -f or user input
gr.msg -v1 "checking current installation.. "
if grep -q "gururc" "$bash_rc" ; then
[[ $force_overwrite ]] && answer="y" ||read -p "already installed, force re-install [y/n] : " answer
if ! [[ "$answer" == "y" ]]; then
gr.msg -c red -x 2 "aborting.."
fi
if [[ $LIGTH_INSTALL ]] ; then
install.core || gr.msg -x 150 "error during installing core"
check.core
install.modules && check.modules || gr.msg -x 170 "error when installing modules"
gr.end caps
exit 0
fi
if ! [[ $configure_after_install ]] && [[ -f $core_rc ]]; then
cp $core_rc /tmp/temp.rc
fi
if [[ -f "$TARGET_BIN/uninstall.sh" ]] ; then
$TARGET_BIN/uninstall.sh
else
gr.msg "using package uninstaller"
./core/uninstall.sh
fi
fi
return 0
}
install.rcfiles () {
# take .bashrc backup and make .gururc
gr.msg -n -v1 "setting rcfiles "
# make a backup of original .bashrc only if installed first time
[[ -f "$backup_rc" ]] || cp -f "$bash_rc" "$backup_rc"
if ! grep -q ".gururc" "$bash_rc" >/dev/null ; then
printf "# guru-client launcher to bashrc \n\nif [[ -f ~/.gururc ]] ; then \n source ~/.gururc\nfi\n" >>"$bash_rc"
fi
installed_files+=("$backup_rc")
modified_files+=("$backup_rc")
gr.msg -v1 -c green "done"
return 0
}
check.rcfiles () {
# check that rc files were installed
gr.msg -n -v1 "checking rcfiles " ; gr.msg -v2
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -v2 -n -c grey "$bash_rc "
if grep -q "gururc" "$bash_rc" ; then
modified_files=(${modified_files[@]} "$bash_rc")
gr.msg -v2 -c green "ok"
else
gr.msg -c red -x 122 ".bashrc modification error"
fi
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -v2 -n -c grey "$backup_rc"
if [[ -f "$backup_rc" ]] ; then
gr.msg -v1 -c green " ok"
else
gr.msg "warning: .bashrc backup file creation failure"
fi
return 0
}
install.folders () {
# create folder tree
gr.msg -n -v1 "setting up folder structure " ; gr.msg -v2
# make bin folder for scripts, configs and and apps
[[ -d "$TARGET_BIN" ]] || mkdir -p "$TARGET_BIN"
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -v2 -c grey "$TARGET_BIN"
# personal configurations
[[ -d "$TARGET_CFG/$GURU_USER" ]] || mkdir -p "$TARGET_CFG/$GURU_USER"
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -v2 -c grey "$TARGET_CFG/$GURU_USER"
gr.msg -V2 -v1 -c green " done"
return 0
}
check.folders () {
# check that folders were created
gr.msg -n -v1 "checking created folders " ; gr.msg -v2
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -n -v2 -c grey "$TARGET_BIN"
if [[ -d "$TARGET_BIN" ]] ; then
gr.msg -v2 -c green " ok"
else
gr.msg -x 141 -c red "failed: bin folder creation error"
fi
gr.msg -n -v1 -V2 -c grey "." ; gr.msg -n -v2 -c grey "$TARGET_CFG/$GURU_USER"
if [[ -d "$TARGET_CFG/$GURU_USER" ]] ; then
gr.msg -v2 -c green " ok"
else
gr.msg -x 143 -c red "failed: configuration folder creation error"
fi
# pass
gr.msg -V2 -v1 -c green " ok"
return 0
}
install.core () {
# install core files
install.copy cfg $TARGET_CFG "copying configurations"
install.copy core $TARGET_BIN "copying core files"
cp version $TARGET_BIN
installed_core=( ${installed_core[@]} $(ls core | cut -f1 -d '.') )
return 0
}
check.core () {
# check core were installed
gr.msg -n -v1 "checking core modules" ; gr.msg -v2
for _file in $(ls core) ; do
gr.msg -v1 -V2 -n -c grey "."
gr.msg -n -v2 -c grey "$_file"
if [[ -f $TARGET_BIN/$_file ]] ; then
gr.msg -v2 -c green " ok"
else
gr.msg -c red "warning: core module $_file missing"
fi
done
gr.msg -v1 -V2 -c green " ok"
gr.msg -n -v1 "checking configuration files " ; gr.msg -v2
for _file in $(ls cfg) ; do
gr.msg -v1 -V2 -n -c grey "."
gr.msg -n -v2 -c grey "$_file"
if [[ -f $TARGET_CFG/$_file ]] ; then
gr.msg -v2 -c green " ok"
else
gr.msg -c yellow "warning: configuration file $_file missing"
fi
done
# pass
gr.msg -v1 -V2 -c green " ok"
return 0
}
install.dev () {
# install foray, test and all modules
# include all modules to install list, do not copy yet
gr.msg -v1 "adding development files to copy list "
modules_to_install=($(ls modules -p | grep -v / | cut -f1 -d '.'))
return 0
}
# check.dev () {
# # check installed tester files
# gr.msg -v1 "checking development files"
# local _modules_to_install=($(ls foray -p | grep -v /))
# for _file in ${_modules_to_install[@]} ; do
# gr.msg -n -v2 -c grey "$_file.. "
# if [[ -f $TARGET_BIN/$_file ]] ; then
# gr.msg -v2 -c green "ok"
# else
# gr.msg -c yellow "warning: development file $_file missing"
# fi
# done
# # pass
# return 0
# }
install.modules () {
# install modules
gr.msg -n -v1 "installing modules " ; gr.msg -v2
for _module in ${modules_to_install[@]} ; do
#module_file=$(ls modules/${_module}.* 2>/dev/null |head -1 )
module_file=modules/${_module}.sh
if [[ -f modules/${_module}.sh ]]; then
module_file=modules/${_module}.sh
elif [[ -f modules/${_module}.py ]]; then
module_file=modules/${_module}.py
elif [[ -f modules/${_module} ]]; then
module_file=modules/${_module}
fi
gr.msg -n -v1 -V2 -c grey "."
gr.msg -n -v2 -c grey "${module_file#*/} "
if [[ -f $module_file ]] ; then
# copy file modules (and adapters)
if cp -f -r $module_file "$TARGET_BIN" ; then
gr.msg -v2 -c green "done"
else
gr.msg -c yellow "module $_module adapter copy error"
fi
# install module requirements
[[ $install_requiremets ]] && gr.ask "install module $_module requirements" && $module_file install
# add to file list, replace source folder to target folder
installed_files=( ${installed_files[@]} $TARGET_BIN/${module_file#*/} )
installed_modules=( ${installed_modules[@]} ${_module} )
else
gr.msg -c dark_grey -v2 "core will build adapter file on first run"
installed_files+=($TARGET_BIN/${module_file#*/})
installed_modules+=(${_module})
fi
# copy folder modules
if [[ -d modules/$_module ]] ; then
[[ -d $TARGET_BIN/$_module ]] || mkdir "$TARGET_BIN/$_module"
local module_files=( $(ls modules/$_module/*) )
for _file in ${module_files[@]} ; do
_target_file=${_file/"modules/"/"$TARGET_BIN/"}
gr.msg -n -v2 -c grey " ${_file#*/} "
if cp -f "$_file" "$_target_file" ; then
installed_files=( ${installed_files[@]} $_target_file)
gr.msg -n -v1 -V2 -c grey "."
gr.msg -v2 -c green "done"
else
gr.msg -c yellow "module $_module folder copying error"
fi
done
fi
done
gr.msg -v1 -V2 -c green " done"
return 0
}
check.modules () {
# check installed modules (foray folder is not monitored)
gr.msg -n -v1 "checking installed modules " ; gr.msg -v2
for _module in ${modules_to_install[@]} ; do
gr.msg -n -v2 -c grey "$_module "
gr.msg -n -v1 -V2 -c grey "."
if ls $TARGET_BIN/$_module* >/dev/null ; then
gr.msg -v2 -c green "ok"
else
gr.msg -c yellow "warning: module $_module missing"
fi
done
# pass
gr.msg -v1 -V2 -c green "ok"
return 0
}
install.config () {
# copy default config files. Does not overwrite user settings
if ! [[ -f "$TARGET_CFG/$GURU_USER/user.cfg" ]] ; then
gr.msg -c yellow "user specific configuration not found, using default.."
cp -f $TARGET_CFG/user-default.cfg "$TARGET_CFG/$GURU_USER/user.cfg" \
|| gr.msg -c red -x 181 "default user configuration failed"
fi
# export default configuration if -c were used
if [[ $configure_after_install ]] ; then
gr.msg -c white "configuring $GURU_USER.."
source $GURU_CORE_FOLDER/config.sh
config.export "$GURU_USER" || gr.msg -c red "user config export error"
source "$core_rc" || gr.msg -c red "$core_rc error"
gr.msg -n -v1 "setting keyboard shortcuts "
source $GURU_CORE_FOLDER/keyboard.sh
keyboard.main add all || gr.msg -c yellow "error by setting keyboard shortcuts"
installed_files+=($TARGET_CFG/kbbind.backup.cfg )
else
[[ -f /tmp/temp.rc ]] && mv -f /tmp/temp.rc $core_rc
fi
return 0
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
install.main $@
exit "$?"
gr.end caps
fi