-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
install.bash
executable file
·1081 lines (927 loc) · 39.6 KB
/
install.bash
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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# shellcheck disable=SC1117,SC1090
# Script: install.bash
# Purpose: Install and configure HomeSetup
# Created: Aug 26, 2018
# Author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior
# Mailto: homesetup@gmail.com
# Site: https://github.com/yorevs/homesetup
# License: Please refer to <https://opensource.org/licenses/MIT>
#
# Copyright (c) 2024, HomeSetup team
{
# This script name
APP_NAME="${0##*/}"
# Help message to be displayed by the script
USAGE="
usage: $APP_NAME [OPTIONS] <args>
-l | --local : Local installation. This is just going to replace the dotfiles.
-r | --repair : Repair current installation.
-i | --interactive : Install all scripts into the user HomeSetup directory interactively.
-p | --prefix : HomeSetup installation prefix. Defaults to USER's HOME directory '~/'.
-q | --quiet : Do not prompt for questions, use all defaults.
"
# Define USER and HOME variables
if [[ -n "${SUDO_USER}" ]]; then
USER="${SUDO_USER}"
HOME="$(eval echo ~"${SUDO_USER}")"
else
USER="${USER:-$(whoami)}"
HOME="${HOME:-$(eval echo ~"${USER}")}"
[[ -n "${GITHUB_ACTIONS}" ]] && SUDO=sudo
fi
[[ -z "${USER}" || -z "${HOME}" ]] && quit 1 "Unable to determine USER/HOME -> ${USER}/${HOME}"
# Functions to be unset after quit
UNSETS=(
quit usage has check_current_shell check_inst_method install_dotfiles clone_repository check_required_tools
activate_dotfiles compatibility_check install_dependencies configure_python install_hspylib ensure_brew
copy_file create_directory install_homesetup abort_install check_prefix configure_starship install_brew
install_tools query_askai_install create_destination_dirs configure_askai_rag configure_blesh
)
# Awesome icons
STAR_ICN='\xef\x80\x85' #
HAND_PEACE_ICN='\xef\x89\x9b' #
POINTER_ICN='\xef\x90\xb2' #
# VT-100 Terminal colors
ORANGE='\033[38;5;202m'
WHITE='\033[97m'
BLUE='\033[34m'
CYAN='\033[36m'
GREEN='\033[32m'
YELLOW='\033[93m'
RED='\033[31m'
NC='\033[m'
# Installation log file
INSTALL_LOG="${HOME}/install.log"
touch "${INSTALL_LOG}"
[[ -f "${INSTALL_LOG}" ]] || quit 1 "Unable initialize installation logs -> ${INSTALL_LOG}"
[[ -f "${INSTALL_LOG}" ]] && echo -e "${ORANGE}Installation logs can be accessed here: ${BLUE}${INSTALL_LOG}${NC}"
# HomeSetup GitHub repository URL
HHS_REPO_URL='https://github.com/yorevs/homesetup.git'
# HomeSetup GitHub issues URL
ISSUES_URL="https://github.com/yorevs/homesetup/issues"
# HomeSetup installation prefix file
HHS_PREFIX_FILE="${HOME}/.hhs-prefix"
# Define the user HomeSetup installation prefix
HHS_PREFIX=
# Option to allow install to be interactive or not
OPT='all'
# HomeSetup installation method
METHOD=
# Whether to install it without prompts
QUIET=
# Whether the script is running from a stream
STREAMED="$([[ -t 0 ]] || echo 'Yes')"
# Whether to install the AskAI functionalities or not
INSTALL_AI="${GITHUB_ACTIONS:-}"
# Streamed installation is disabled by default
[[ -n "${STREAMED}" && -z "${GITHUB_ACTIONS}" ]] && unset INSTALL_AI
# Shell type
SHELL_TYPE="${SHELL##*/}"
# All .dotfiles we will manage
ALL_DOTFILES=()
# Supported shell types. For now, only bash is supported
SUPP_SHELL_TYPES=('bash')
# Timestamp used to backup files
TIMESTAMP=$(\date "+%s%S")
# README link for HomeSetup
README_LINK="${HHS_HOME}/README.MD"
# HSPyLib python modules to install
PYTHON_MODULES=(
'hspylib-clitt'
'hspylib-setman'
'hspylib-vault'
'hspylib-firebase'
)
# User's operating system
MY_OS=$(uname -s)
# OS Application manager. Defined later on the installation process
OS_APP_MAN=
# HomeBrew prefix
BREW=
# OS type. Defined later on the installation process
OS_TYPE=
# HomeSetup application dependencies
DEPENDENCIES=(
'git' 'curl' 'ruby' 'rsync' 'mkdir' 'vim' 'gawk' 'hexdump'
)
# Missing HomeSetup dependencies
MISSING_DEPS=()
if [[ "${MY_OS}" == "Darwin" ]]; then
MY_OS_NAME=$(sw_vers -productName)
GROUP=${GROUP:-staff}
elif [[ "${MY_OS}" == "Linux" ]]; then
MY_OS_NAME="$(grep '^ID=' '/etc/os-release' 2>/dev/null)"
MY_OS_NAME="${MY_OS_NAME#*=}"
GROUP=${GROUP:-${USER}}
fi
# Purpose: Quit the program and exhibits an exit message if specified
# @param $1 [Req] : The exit return code. 0 = SUCCESS, 1 = FAILURE, * = ERROR ${RED}.
# @param $2 [Opt] : The exit message to be displayed.
quit() {
# Unset all declared functions
unset -f "${UNSETS[*]}"
exit_code=${1:-0}
shift
[[ ${exit_code} -ne 0 && ${#} -ge 1 ]] && echo -en "${RED}${APP_NAME}: " 1>&2
[[ ${#} -ge 1 ]] && echo -e "${*} ${NC}" 1>&2
[[ ${#} -gt 0 ]] && echo ''
exit "${exit_code}"
}
# Usage message
usage() {
quit 2 "${USAGE}"
}
# @function: Check if a command exists
# @param $1 [Req] : The command to check
has() {
type "${1}" &>/dev/null
}
# @function: Create a directory and check for write permissions
# @Param $1 [Req] : The directory name
create_directory() {
local dir="${1}"
if [[ ! -d "${dir}" && ! -L "${dir}" ]]; then
echo -en "\n${WHITE}Creating: ${dir} directory... "
\mkdir -p "${dir}" || quit 2 "Unable to create directory ${dir}"
echo -e "${GREEN}OK${NC}"
else
# Trying to write at the created directory to validate write permissions.
\touch "${dir}/tmpfile" &>/dev/null || quit 2 "Not enough permissions to write to \"${dir}\" directory!"
\rm -f "${dir:?}/tmpfile" &>/dev/null
fi
}
# @function: Copy file from source to destination.
# @Param $1 [Req] : The source file/dir.
# @Param $2 [Req] : The destination file/dir.
copy_file() {
local src_file dest_file
src_file="${1}"
dest_file="${2}"
echo ''
if [[ -f "${dest_file}" || -d "${dest_file}" ]]; then
echo -e "${WHITE}Skipping: ${YELLOW}${dest_file} file/dir was not copied because it already exists. ${NC}"
else
echo -en "${WHITE}Copying: ${BLUE} ${src_file} -> ${dest_file}... "
\rsync --archive "${src_file}" "${dest_file}"
\chown "${USER}":"${GROUP}" "${dest_file}" &>/dev/null
[[ -f "${dest_file}" ]] && echo -e "${GREEN}OK${NC}"
[[ -f "${dest_file}" ]] || echo -e "${RED}FAILED${NC}"
fi
}
# @function: Link file from source to destination.
# @Param $1 [Req] : The source file/dir.
# @Param $2 [Req] : The destination file/dir.
link_file() {
local src_file dest_file
src_file="${1}"
dest_file="${2}"
# Backup existing dest_file into ${HHS_BACKUP_DIR}.
[[ -s "${dest_file}" && ! -L "${dest_file}" ]] && \mv "${dest_file}" "${HHS_BACKUP_DIR}/$(basename "${dest_file}".orig)"
echo ''
echo -en "${WHITE}Linking: ${BLUE}"
echo -en "$(\ln -sfv "${src_file}" "${dest_file}")...${NC}"
[[ -L "${dest_file}" ]] && echo -e " ${GREEN}OK${NC}"
[[ -L "${dest_file}" ]] || quit 1 " ${RED}FAILED${NC}"
}
# shellcheck disable=SC2199,SC2076
# Check current active User shell type.
check_current_shell() {
if [[ ! " ${SUPP_SHELL_TYPES[@]} " =~ " ${SHELL##*/} " ]]; then
quit 2 "Your current shell is not supported: \"${SHELL}\""
fi
}
# shellcheck disable=SC1091
# Check which installation method should be used
check_inst_method() {
# Loop through the command line options
while test -n "$1"; do
case "$1" in
-l | --local)
METHOD='local'
;;
-r | --repair)
METHOD='repair'
;;
-i | --interactively)
OPT=''
;;
-p | --prefix)
HHS_PREFIX="${2}"
[[ -d "${HHS_PREFIX}" ]] || quit 2 "Installation prefix is not a valid directory \"${HHS_PREFIX}\""
shift
;;
-q | --quiet)
QUIET=1
;;
*)
quit 2 "Invalid option: \"$1\""
;;
esac
shift
done
# Installation prefix
HHS_PREFIX="${HHS_PREFIX:-$([[ -s "${HHS_PREFIX_FILE}" ]] && \grep . "${HHS_PREFIX_FILE}")}"
# Installation location
HHS_HOME="${HHS_PREFIX:-${HOME}/HomeSetup}"
# Configuration files location
HHS_DIR="${HOME}/.config/hhs"
# Binaries location
HHS_BIN_DIR="${HHS_DIR}/bin"
# MOTD location
HHS_MOTD_DIR="${HHS_DIR}/motd"
# Backup location
HHS_BACKUP_DIR="${HHS_DIR}/backup"
# Logs directory
HHS_LOG_DIR="${HHS_DIR}/log"
# Shell options file
HHS_SHOPTS_FILE="${HHS_DIR}/shell-opts.toml"
# Version file
HHS_VERSION_FILE="${HHS_HOME}/.VERSION"
# Ble Bash plug installation in location
HHS_BLESH_DIR="${HHS_DIR}/ble-sh"
# Fonts destination location
if [[ "Darwin" == "${MY_OS}" ]]; then
FONTS_DIR="${HOME}/Library/Fonts"
elif [[ "Linux" == "${MY_OS}" ]]; then
FONTS_DIR="${HOME}/.local/share/fonts"
fi
# Dotfiles source location
DOTFILES_DIR="${HHS_HOME}/dotfiles/${SHELL_TYPE}"
# Applications source location
APPS_DIR="${HHS_HOME}/bin/apps"
# Auto-completions source location
COMPLETIONS_DIR="${HHS_HOME}/bin/completions"
# Key-Bindings source location
BINDINGS_DIR="${HHS_HOME}/bin/key-bindings"
# Check if the user passed help or version options
[[ "$1" == '-h' || "$1" == '--help' ]] && quit 0 "${USAGE}"
[[ "$1" == '-v' || "$1" == '--version' ]] && quit 0 "HomeSetup v$(\grep . "${HHS_VERSION_FILE}")"
[[ -z "${USER}" || -z "${GROUP}" ]] && quit 1 "Unable to detect USER:GROUP => [${USER}:${GROUP}]"
[[ -z "${HOME}" || -z "${SHELL}" ]] && quit 1 "Unable to detect HOME/SHELL => [${HOME}:${SHELL}]"
[[ -s "${HHS_HOME}/.VERSION" ]] &&
echo -e "\n${GREEN}HomeSetup© ${YELLOW}v$(grep . "${HHS_VERSION_FILE}") ${GREEN}installation ${NC}"
# Check the installation method
if [[ -z "${METHOD}" ]]; then
if [[ -d "${HHS_HOME}" || -f "${HHS_HOME}/.VERSION" ]]; then
METHOD='local'
elif [[ -n "${STREAMED}" ]]; then
METHOD='remote'
else
METHOD='repair'
fi
fi
}
# Prompt the user for AskAI installation
query_askai_install() {
PIP=$(command -v pip3 2>/dev/null)
if PIP show hspylib-askai &>/dev/null; then
INSTALL_AI=1
elif [[ -z "${STREAMED}" && -z "${GITHUB_ACTIONS}" ]]; then
echo -e "${ORANGE}"
read -rn 1 -p 'Would you like to install HomeSetup AI capabilities (y/[n])? ' ANS
echo -e "${NC}" && [[ -n "${ANS}" ]] && echo ''
if [[ "${ANS}" =~ ^[yY]$ ]]; then
INSTALL_AI=1
fi
unset ANS
fi
}
# Create all HomeSetup destination directories
create_destination_dirs() {
# Create HomeSetup .hhs directory
create_directory "${HHS_DIR}"
# Create HomeSetup bin directory
create_directory "${HHS_BIN_DIR}"
# Create HomeSetup motd directory
create_directory "${HHS_MOTD_DIR}"
# Create HomeSetup backup directory
create_directory "${HHS_BACKUP_DIR}"
# Create HomeSetup logs directory
create_directory "${HHS_LOG_DIR}"
# Create fonts destination directory
create_directory "${FONTS_DIR}"
}
# Check HomeSetup required tools
check_required_tools() {
local pad pad_len install check_pkg
[[ -n "${INSTALL_AI}" ]] && PYTHON_MODULES+=('hspylib-askai')
# macOS
if [[ "${MY_OS}" == "Darwin" ]]; then
OS_TYPE='macOS'
OS_APP_MAN='brew'
DEPENDENCIES+=('sudo' 'xcode-select')
[[ -n "${INSTALL_AI}" ]] &&
DEPENDENCIES+=('ffmpeg' 'portaudio' 'libmagic')
install="${SUDO} brew install -f"
check_pkg="brew list "
# Debian: Ubuntu
elif has 'apt'; then
OS_TYPE='Debian'
OS_APP_MAN='apt'
DEPENDENCIES+=('sudo' 'file' 'build-essential' 'python3' 'python3-pip')
[[ -n "${INSTALL_AI}" ]] &&
DEPENDENCIES+=('ffmpeg' 'python3-pyaudio' 'portaudio19-dev' 'libasound-dev' 'libmagic-dev')
install="${SUDO} apt install -y"
check_pkg="apt list --installed | grep"
# RedHat: Fedora, CentOS
elif has 'dnf'; then
OS_TYPE='RedHat'
OS_APP_MAN='dnf'
DEPENDENCIES+=('sudo' 'file' 'make' 'automake' 'gcc' 'gcc-c++' 'kernel-devel' 'python3' 'python3-pip')
[[ -n "${INSTALL_AI}" ]] &&
DEPENDENCIES+=('ffmpeg' 'python3-pyaudio' 'portaudio-devel' 'redhat-rpm-config' 'libmagic-dev')
install="${SUDO} yum install -y"
check_pkg="dnf list installed | grep"
# Alpine: Busybox
elif has 'apk'; then
OS_TYPE='Alpine'
OS_APP_MAN='apk'
DEPENDENCIES+=('file' 'python3' 'pip3')
unset INSTALL_AI # AskAI is not tested on Alpine
install="apk add --no-cache"
check_pkg="apk list | grep"
# ArchLinux
elif has 'pacman'; then
OS_TYPE='ArchLinux'
OS_APP_MAN='pacman'
DEPENDENCIES+=('sudo' 'file' 'python3' 'python3-pip')
unset INSTALL_AI # AskAI is not tested on ArchLinux
install="${SUDO} pacman -Sy"
check_pkg="pacman -Q | grep"
else
quit 1 "Unable to find package manager for $(uname -s)"
fi
echo -e "\nUsing ${YELLOW}\"${OS_APP_MAN}\"${NC} application manager!\n"
echo -e "${BLUE}[${OS_TYPE}] ${WHITE}Checking required tools using ${YELLOW}'${check_pkg}'${WHITE} ...${NC}\n"
pad=$(printf '%0.1s' "."{1..60})
pad_len=20
for tool_name in "${DEPENDENCIES[@]}"; do
echo -en "${BLUE}[${OS_TYPE}] ${WHITE}Checking: ${YELLOW}${tool_name}${NC}..."
printf '%*.*s' 0 $((pad_len - ${#tool_name})) "${pad}"
if has "${tool_name}" || ${check_pkg} "${tool_name}" &>/dev/null; then
echo -e " ${GREEN}√ INSTALLED${NC}"
else
echo -e " ${RED}X NOT INSTALLED${NC}"
MISSING_DEPS+=("${tool_name}")
fi
done
# Install packages using the default package manager
install_dependencies "${install}" "${check_pkg}" "${MISSING_DEPS[@]}"
ensure_brew
}
# shellcheck disable=SC2206
# Install missing required tools.
install_dependencies() {
local install="${1}" check_pkg="${2}" tools pkgs
shift
shift
tools=(${@})
pkgs="${tools[*]}"
pkgs="${pkgs// /\\n |-}"
if [[ ${#tools[@]} -gt 0 ]]; then
[[ -n "${SUDO}" ]] &&
echo -e "\n${ORANGE}Using 'sudo' to install apps. You may be prompted for the password.${NC}\n"
echo -e "${BLUE}[${OS_TYPE}] ${WHITE}Installing required packages using: ${YELLOW}\"${install}\"${NC}"
echo -e " |-${pkgs}"
for tool_name in "${tools[@]}"; do
echo -en "${BLUE}[${OS_TYPE}] ${WHITE}Installing: ${YELLOW}${tool_name}${NC}..."
if ${install} "${tool_name}" >>"${INSTALL_LOG}" 2>&1; then
printf '%*.*s' 0 $((pad_len - ${#tool_name})) "${pad}"
echo -e " ${GREEN}√ OK${NC}"
else
echo -e " ${RED}X FAILED${NC}"
MISSING_DEPS+=("${tool_name}")
quit 2 "Failed to install dependencies. Please manually install the missing tools and try again."
fi
done
fi
}
# Make sure HomeBrew is installed. In the future will use HomeBrew as the default HHS package manager.
ensure_brew() {
if [[ ${OS_TYPE} == macOS ]]; then
echo ''
if ! has 'brew'; then
echo -en "${YELLOW}HomeBrew is not installed!${NC}"
install_brew || quit 2 "### Failed to install HomeBrew !"
else
echo -e "${BLUE}HomeBrew is already installed -> $(brew --prefix) ${NC}"
fi
elif [[ ${OS_TYPE} =~ Debian|RedHat ]]; then
echo -e "${YELLOW}Skipping brew installation (not enforced): \"${OS_TYPE}\""
else
echo -e "${YELLOW}Skipping brew installation (not supported OS): \"${OS_TYPE}\""
fi
}
# Install HomeBrew
install_brew() {
echo -e "${BLUE}[${OS_TYPE}] Attempting to install HomeBrew [${OS_TYPE}]... "
if ${SUDO} curl -fsSL https://raw.githubusercontent.com/HomeBrew/install/HEAD/install.sh | bash >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
if [[ "${MY_OS}" == "Linux" ]]; then
[[ -d ~/.linuxbrew ]] && eval "$(~/.linuxbrew/bin/brew shellenv)"
[[ -d /home/linuxbrew/.linuxbrew ]] && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
${SUDO} eval "$("$(brew --prefix)"/bin/brew shellenv)"
fi
BREW="$(brew --prefix)/bin/brew"
if command -v brew &>/dev/null; then
echo -e "\n${GREEN}@@@ Successfully installed HomeBrew -> ${BREW}${NC}"
else
quit 2 "### Could not find HomeBrew installation !"
fi
else
echo -e "${RED}FAILED${NC}"
quit 2 "### Failed to install HomeBrew !"
fi
}
# Install HomeSetup.
install_homesetup() {
echo -e "HomeSetup installation started: $(date)\n" >"${INSTALL_LOG}"
echo ''
echo -e "${WHITE}Using ${YELLOW}\"${METHOD}\"${NC} installation method!"
# Select the installation method and call the underlying functions
case "${METHOD}" in
remote)
query_askai_install
check_required_tools
create_destination_dirs
clone_repository
install_dotfiles
compatibility_check
configure_python
configure_starship
configure_gtrash
configure_blesh
configure_askai_rag
;;
repair)
query_askai_install
check_required_tools
create_destination_dirs
install_dotfiles
compatibility_check
configure_python
configure_starship
configure_gtrash
configure_blesh
configure_askai_rag
;;
local)
install_dotfiles
configure_starship
configure_askai_rag
;;
*)
quit 2 "Installation method \"${METHOD}\" is not valid!"
;;
esac
# Finish installation and activate HomeSetup.
activate_dotfiles
}
# Clone the repository and install dotfiles.
clone_repository() {
has git || quit 2 "You need git installed in order to install HomeSetup remotely !"
[[ -d "${HHS_HOME}" ]] && echo -e "\n${YELLOW}Installation directory was already created: \"${HHS_HOME}\" !"
echo -e "${NC}"
if [[ ! -d "${HHS_HOME}" ]]; then
echo -en "${WHITE}Cloning HomeSetup repository... ${NC}"
if git clone "${HHS_REPO_URL}" "${HHS_HOME}" >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
else
quit 2 "Unable to properly clone HomeSetup repository !"
fi
else
cd "${HHS_HOME}" &>/dev/null || quit 1 "Unable to enter \"${HHS_HOME}\" directory !"
echo -e "${WHITE}Pulling HomeSetup repository... ${NC}"
if git pull --rebase >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
else
quit 2 "Unable to properly update HomeSetup repository !"
fi
cd - &>/dev/null || quit 1 "Unable to leave \"${HHS_HOME}\" directory !"
fi
[[ -d "${DOTFILES_DIR}" ]] || quit 2 "Unable to find dotfiles directories \"${DOTFILES_DIR}\" !"
}
# Install all dotfiles.
install_dotfiles() {
local dotfile is_streamed
# Find all dotfiles used by HomeSetup according to the current shell type
while read -r dotfile; do
ALL_DOTFILES+=("${dotfile}")
done < <(find "${DOTFILES_DIR}" -maxdepth 1 -type f -name "*.${SHELL_TYPE}" -exec basename {} \;)
[[ -z ${STREAMED} ]] && is_streamed='No'
[[ -z ${INSTALL_AI} ]] && is_askai='No'
echo ''
echo -e "${WHITE}### ${GREEN}HomeSetup© ${WHITE}Installation Settings ###${NC}"
echo -e ""
echo -e "${WHITE} Shell: ${YELLOW}${MY_OS}-${MY_OS_NAME}/${SHELL_TYPE}"
echo -e "${WHITE} Install Type: ${YELLOW}${METHOD}"
echo -e "${WHITE} Install Prefix: ${YELLOW}${HHS_PREFIX:-none}"
echo -e "${WHITE} Install Dir: ${YELLOW}${HHS_HOME}"
echo -e "${WHITE} Enable AI: ${YELLOW}${is_askai:=Yes}"
echo -e "${WHITE} Configurations: ${YELLOW}${HHS_DIR}"
echo -e "${WHITE} PyPi Packages: ${YELLOW}${PYTHON_MODULES[*]}"
echo -e "${WHITE} User/Group: ${YELLOW}${USER}:${GROUP}"
echo -e "${WHITE} Streamed: ${YELLOW}${is_streamed:=Yes}"
echo -e "${NC}"
if [[ "${METHOD}" != "local" && -z "${QUIET}" && -z "${STREAMED}" ]]; then
echo -e "${ORANGE}"
if [[ -z "${ANS}" ]]; then
read -rn 1 -p 'Your current .dotfiles will be replaced and your old files backed up. Continue (y/[n])? ' ANS
fi
echo -e "${NC}" && [[ -n "${ANS}" ]] && echo ''
if [[ ! "${ANS}" =~ ^[yY]$ ]]; then
echo "Installation cancelled: " >>"${INSTALL_LOG}" 2>&1
echo ">> ANS=${ANS} QUIET=${QUIET} METHOD=${METHOD} STREAM=${STREAMED}" >>"${INSTALL_LOG}"
quit 1 "${RED}Installation cancelled !${NC}"
fi
echo -e "${BLUE}Installing HomeSetup ...${NC}"
else
echo -e "${BLUE}Installing HomeSetup ${YELLOW}quietly ${NC}"
fi
# Create all user custom files.
[[ -s "${HHS_DIR}/.aliases" ]] || \touch "${HHS_DIR}/.aliases"
[[ -s "${HHS_DIR}/.cmd_file" ]] || \touch "${HHS_DIR}/.cmd_file"
[[ -s "${HHS_DIR}/.colors" ]] || \touch "${HHS_DIR}/.colors"
[[ -s "${HHS_DIR}/.env" ]] || \touch "${HHS_DIR}/.env"
[[ -s "${HHS_DIR}/.functions" ]] || \touch "${HHS_DIR}/.functions"
[[ -s "${HHS_DIR}/.path" ]] || \touch "${HHS_DIR}/.path"
[[ -s "${HHS_DIR}/.profile" ]] || \touch "${HHS_DIR}/.profile"
[[ -s "${HHS_DIR}/.prompt" ]] || \touch "${HHS_DIR}/.prompt"
[[ -s "${HHS_DIR}/.saved_dirs" ]] || \touch "${HHS_DIR}/.saved_dirs"
# Create alias and input definitions.
copy_file "${HHS_HOME}/dotfiles/inputrc" "${HOME}/.inputrc"
copy_file "${HHS_HOME}/dotfiles/aliasdef" "${HHS_DIR}/.aliasdef"
copy_file "${HHS_HOME}/dotfiles/homesetup.toml" "${HHS_DIR}/.homesetup.toml"
# NeoVim integration
[[ -d "${HOME}/.config/nvim" ]] || \mkdir -p "${HOME}/.config/nvim"
copy_file "${HHS_HOME}/dotfiles/nvim-init" "${HOME}/.config/nvim/init.vim"
pushd "${DOTFILES_DIR}" &>/dev/null || quit 1 "Unable to enter dotfiles directory \"${DOTFILES_DIR}\" !"
echo ">>> Linked dotfiles:" >>"${INSTALL_LOG}"
# If `all' option is used, copy all files.
if [[ "$OPT" == 'all' ]]; then
# Link all dotfiles
for next in "${ALL_DOTFILES[@]}"; do
dotfile="${HOME}/.${next//\.${SHELL_TYPE}/}"
link_file "${DOTFILES_DIR}/${next}" "${dotfile}"
echo "${next} -> ${DOTFILES_DIR}/${next}" >>"${INSTALL_LOG}"
done
# If `all' option is NOT used, prompt for confirmation.
else
# Link all dotfiles
for next in "${ALL_DOTFILES[@]}"; do
dotfile="${HOME}/.${next//\.${SHELL_TYPE}/}"
echo ''
[[ -z ${QUIET} && -z "${STREAMED}" ]] && read -rn 1 -sp "Link ${dotfile} (y/[n])? " ANS
[[ ! "${ANS}" =~ ^[yY]$ ]] && continue
echo ''
link_file "${DOTFILES_DIR}/${next}" "${dotfile}"
echo "${next} -> ${DOTFILES_DIR}/${next}" >>"${INSTALL_LOG}"
done
fi
# Remove old apps.
echo -en "\n${WHITE}Removing old links... ${BLUE}"
echo ">>> Removed old links:" >>"${INSTALL_LOG}"
if find "${HHS_BIN_DIR}" -maxdepth 1 -type l -delete -print >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
else
quit 2 "Unable to remove old app links from \"${HHS_BIN_DIR}\" directory !"
fi
# Link apps into place.
echo -en "\n${WHITE}Linking apps from ${BLUE}${APPS_DIR} to ${HHS_BIN_DIR}..."
echo ">>> Linked apps:" >>"${INSTALL_LOG}"
if find "${APPS_DIR}" -maxdepth 3 -type f -iname "**.${SHELL_TYPE}" \
-print \
-exec ln -sfv {} "${HHS_BIN_DIR}" \; \
-exec chmod +x {} \; >>"${INSTALL_LOG}" 2>&1; then
echo -e " ${GREEN}OK${NC}"
else
quit 2 "Unable to link apps into \"${HHS_BIN_DIR}\" directory !"
fi
# Link auto-completes into place.
echo -en "\n${WHITE}Linking auto-completes from ${BLUE}${COMPLETIONS_DIR} to ${HHS_BIN_DIR}... "
echo ">>> Linked auto-completes:" >>"${INSTALL_LOG}"
if find "${COMPLETIONS_DIR}" -maxdepth 2 -type f -iname "**-completion.${SHELL_TYPE}" \
-print \
-exec ln -sfv {} "${HHS_BIN_DIR}" \; \
-exec chmod +x {} \; >>"${INSTALL_LOG}" 2>&1; then
echo -e " ${GREEN}OK${NC}"
else
quit 2 "Unable to link auto-completes into bin (${HHS_BIN_DIR}) directory !"
fi
# Link key-bindings into place.
echo -en "\n${WHITE}Linking key-bindings from ${BLUE}${BINDINGS_DIR} to ${HHS_BIN_DIR}... "
echo ">>> Linked key-bindings:" >>"${INSTALL_LOG}"
if find "${BINDINGS_DIR}" -maxdepth 2 -type f -iname "**-key-bindings.${SHELL_TYPE}" \
-print \
-exec ln -sfv {} "${HHS_BIN_DIR}" \; \
-exec chmod +x {} \; >>"${INSTALL_LOG}" 2>&1; then
echo -e " ${GREEN}OK${NC}"
else
quit 2 "Unable to link key-bindings into bin (${HHS_BIN_DIR}) directory !"
fi
# Copy HomeSetup fonts into place.
echo -en "\n${WHITE}Copying HomeSetup fonts into ${BLUE}${FONTS_DIR}... "
echo ">>> Copied HomeSetup fonts" >>"${INSTALL_LOG}"
[[ -d "${FONTS_DIR}" ]] || quit 2 "Unable to locate fonts (${FONTS_DIR}) directory !"
if find "${HHS_HOME}"/assets/fonts -maxdepth 1 -type f \( -iname "*.otf" -o -iname "*.ttf" \) \
-print \
-exec rsync --archive {} "${FONTS_DIR}" \; \
-exec chown "${USER}":"${GROUP}" {} \; >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
else
quit 2 "Unable to copy HHS fonts into fonts (${FONTS_DIR}) directory !"
fi
# -----------------------------------------------------------------------------------
# Set default HomeSetup terminal options
case "${SHELL_TYPE}" in
bash)
# Creating the shell-opts file
echo -en "\n${WHITE}Creating the Shell Options file ${BLUE}${HHS_SHOPTS_FILE}... "
\shopt | awk '{print $1" = "$2}' >"${HHS_SHOPTS_FILE}" || quit 2 "Unable to create the Shell Options file !"
echo -e "${GREEN}OK${NC}"
;;
esac
# Copy MOTDs file into place
[[ -d "${HHS_MOTD_DIR}" ]] || create_directory "${HHS_MOTD_DIR}"
\cp "${HHS_HOME}"/.MOTD "${HHS_MOTD_DIR}"/000-hhs-motd &>/dev/null
\popd &>/dev/null || quit 1 "Unable to leave dotfiles directory !"
}
# Configure python and HomeSetup python library.
configure_python() {
echo ''
echo -en "${WHITE}Detecting local python environment... ${NC}"
# Detecting system python and pip versions.
PYTHON=$(command -v python3 2>/dev/null)
PIP=$(command -v pip3 2>/dev/null)
[[ -z "${PYTHON}" ]] && quit 2 "Python3 is required to install HomeSetup !"
[[ -z "${PIP}" ]] && quit 2 "Pip3 is required to install HomeSetup !"
python_version="$(${PYTHON} -V)"
pip_version="$(${PIP} -V | \cut -d ' ' -f2)"
${PIP} freeze >>"${INSTALL_LOG}" 2>&1 || quit 2 "PIP3 is required to install HomeSetup !"
echo -e "${GREEN}OK${NC}"
echo ''
echo -e "${WHITE}Using Python ${YELLOW}v${python_version}${WHITE} and Pip ${YELLOW}v${pip_version}${NC}"
install_hspylib "${PYTHON}" "${PIP}"
}
# Install HomeSetup python libraries.
install_hspylib() {
# Define python tools
PYTHON="${1}"
PIP="${2}"
echo -en "\n${BLUE}[$(basename "${PYTHON}")] ${WHITE}Installing HSPyLib packages... "
pkgs=$(mktemp)
echo "${PYTHON_MODULES[*]}" | tr ' ' '\n' >"${pkgs}"
if \
${PIP} install --upgrade --break-system-packages -r "${pkgs}" >>"${INSTALL_LOG}" 2>&1 ||
${PIP} install --upgrade -r "${pkgs}" >>"${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
\rm -f "$(mktemp)"
echo "Installed HSPyLib python modules:" >>"${INSTALL_LOG}"
${PIP} freeze | grep hspylib >>"${INSTALL_LOG}"
else
quit 2 "${RED}FAILED${NC} Unable to install PyPi packages!"
fi
}
# Check for backward HomeSetup backward compatibility.
compatibility_check() {
echo -e "\n${WHITE}Checking HomeSetup backward compatibility${BLUE}"
# Cleaning up old dotfiles links
[[ -d "${HHS_BIN_DIR}" ]] && rm -f "${HHS_BIN_DIR:?}/*.*"
# .profile Needs to be renamed, so, we guarantee that no dead lock occurs.
if [[ -f "${HOME}/.profile" ]]; then
\mv -f "${HOME}/.profile" "${HHS_BACKUP_DIR}/profile.orig"
echo ''
echo -e "\n${YELLOW}Your old ${HOME}/.profile had to be renamed to ${HHS_BACKUP_DIR}/profile.orig "
echo -e "This is to avoid invoking dotfiles multiple times. If you are sure that your .profile don't source either"
echo -e ".bash_profile or .bashrc, then, you can rename it back to .profile: "
echo -e "$ mv ${HHS_BACKUP_DIR}/profile.orig ${HOME}/.profile"
echo ''
[[ -z "${STREAMED}" ]] && read -rn 1 -p "Press any key to continue...${NC}"
fi
# Moving old hhs files into the proper directory.
[[ -f "${HOME}/.cmd_file" ]] && \mv -f "${HOME}/.cmd_file" "${HHS_DIR}/.cmd_file"
[[ -f "${HOME}/.saved_dir" ]] && \mv -f "${HOME}/.saved_dir" "${HHS_DIR}/.saved_dirs"
[[ -f "${HOME}/.punches" ]] && \mv -f "${HOME}/.punches" "${HHS_DIR}/.punches"
[[ -f "${HOME}/.firebase" ]] && \mv -f "${HOME}/.firebase" "${HHS_DIR}/.firebase"
# From hspylib integration on
[[ -f "${HOME}/.aliases" ]] && \mv -f "${HOME}/.aliases" "${HHS_DIR}/.aliases"
[[ -f "${HOME}/.aliasdef" ]] && \mv -f "${HOME}/.aliasdef" "${HHS_DIR}/.aliasdef"
[[ -f "${HOME}/.colors" ]] && \mv -f "${HOME}/.colors" "${HHS_DIR}/.colors"
[[ -f "${HOME}/.env" ]] && \mv -f "${HOME}/.env" "${HHS_DIR}/.env"
[[ -f "${HOME}/.functions" ]] && \mv -f "${HOME}/.functions" "${HHS_DIR}/.functions"
[[ -f "${HOME}/.profile" ]] && \mv -f "${HOME}/.profile" "${HHS_DIR}/.profile"
[[ -f "${HOME}/.prompt" ]] && \mv -f "${HOME}/.prompt" "${HHS_DIR}/.prompt"
# Removing the old ${HOME}/bin folder.
if [[ -L "${HOME}/bin" ]]; then
\rm -f "${HOME:?}/bin"
echo -e "\n${YELLOW}Your old ${HOME}/bin link had to be removed. ${NC}"
fi
# .bash_aliasdef was renamed to .aliasdef and it is only copied if it does not exist. #9c592e0 .
if [[ -L "${HOME}/.bash_aliasdef" ]]; then
\rm -f "${HOME}/.bash_aliasdef"
echo -e "\n${YELLOW}Your old ${HOME}/.bash_aliasdef link had to be removed. ${NC}"
fi
# .inputrc Needs to be updated, so, we need to replace it.
if [[ -f "${HOME}/.inputrc" ]]; then
\mv -f "${HOME}/.inputrc" "${HHS_BACKUP_DIR}/inputrc-${TIMESTAMP}.bak"
copy_file "${HHS_HOME}/dotfiles/inputrc" "${HOME}/.inputrc"
echo -e "\n${YELLOW}Your old ${HOME}/.inputrc had to be replaced by a newer version. Your old file it located at ${HHS_BACKUP_DIR}/inputrc-${TIMESTAMP}.bak ${NC}"
fi
# .aliasdef Needs to be updated, so, we need to replace it.
if [[ -f "${HOME}/.aliasdef" ]]; then
\mv -f "${HOME}/.aliasdef" "${HHS_BACKUP_DIR}/aliasdef-${TIMESTAMP}.bak"
copy_file "${HHS_HOME}/dotfiles/aliasdef" "${HHS_DIR}/.aliasdef"
echo -e "\n${YELLOW}Your old .aliasdef had to be replaced by a newer version. Your old file it located at ${HHS_BACKUP_DIR}/aliasdef-${TIMESTAMP}.bak ${NC}"
fi
if [[ -f "${HHS_DIR}/.homesetup.toml" ]]; then
# Check if the homesetup.toml is outdated
user_version=$(grep -o '^# @version: v[0-9]*\.[0-9]*\.[0-9]*' "${HHS_DIR}/.homesetup.toml" | sed 's/# @version: v//')
hhs_version=$(grep -o '^# @version: v[0-9]*\.[0-9]*\.[0-9]*' "${HHS_HOME}/dotfiles/homesetup.toml" | sed 's/# @version: v//')
user_num=$(echo "${user_version}" | awk -F. '{ printf "%d%02d%03d", $1, $2, $3 }')
hhs_num=$(echo "${hhs_version}" | awk -F. '{ printf "%d%02d%03d", $1, $2, $3 }')
if [[ "${hhs_num}" -gt "${user_num}" ]]; then
\mv -f "$HHS_DIR/.homesetup.toml" "${HHS_BACKUP_DIR}/homesetup-${TIMESTAMP}.toml.bak"
copy_file "${HHS_HOME}/dotfiles/homesetup.toml" "${HHS_DIR}/.homesetup.toml"
echo -e "\n${YELLOW}Your old .homesetup.toml had to be replaced by a newer version. Your old file it located at ${HHS_BACKUP_DIR}/homesetup-${TIMESTAMP}.toml.bak ${NC}"
fi
fi
# Moving .path file to .hhs .
if [[ -f "${HOME}/.path" ]]; then
\mv -f "${HOME}/.path" "${HHS_DIR}/.path"
echo -e "\n${YELLOW}Moved file ${HOME}/.path into ${HHS_DIR}/.path"
fi
# .bash_completions was renamed to .bash_completion. #e6ce231 .
# .bash_completion was deleted.
[[ -L "${HOME}/.bash_completions" ]] && \rm -f "${HOME}/.bash_completions"
[[ -L "${HOME}/.bash_completion" ]] && \rm -f "${HOME}/.bash_completion"
# Removing the old python lib directories and links.
[[ -d "${HHS_HOME}/bin/apps/bash/hhs-app/lib" ]] &&
\rm -rf "${HHS_HOME}/bin/apps/bash/hhs-app/lib"
[[ -L "${HHS_HOME}/bin/apps/bash/hhs-app/plugins/firebase/lib" ]] &&
\rm -rf "${HHS_HOME}/bin/apps/bash/hhs-app/plugins/firebase/lib"
[[ -L "${HHS_HOME}/bin/apps/bash/hhs-app/plugins/vault/lib" ]] &&
\rm -rf "${HHS_HOME}/bin/apps/bash/hhs-app/plugins/vault/lib"
# Moving orig and bak files to backup folder.
find "${HHS_DIR}" -maxdepth 1 \
-type f \( -name '*.bak' -o -name '*.orig' \) \
-print -exec mv {} "${HHS_BACKUP_DIR}" \;
# .tailor Needs to be updated, so, we need to replace it.
if [[ -f "${HHS_DIR}/.tailor" ]]; then
\mv -f "${HHS_DIR}/.tailor" "${HHS_BACKUP_DIR}/tailor-${TIMESTAMP}.bak"
echo -e "\n${YELLOW}Your old .tailor had to be replaced by a newer version. Your old file it located at ${HHS_BACKUP_DIR}/tailor-${TIMESTAMP}.bak ${NC}"
fi
# Old $HHS_DIR/starship.toml changed to $HHS_DIR/.starship.toml
if [[ -f "${HHS_DIR}/starship.toml" ]]; then
\mv -f "${HHS_DIR}/starship.toml" "${HHS_BACKUP_DIR}/starship.toml-${TIMESTAMP}.bak"
echo -e "\n${YELLOW}Your old starship.toml had to be replaced by a newer version. Your old file it located at ${HHS_BACKUP_DIR}/starship.toml-${TIMESTAMP}.bak ${NC}"
fi
# Old hhs-init file changed to homesetup.toml
if [[ -f "${HHS_DIR}/.hhs-init" ]]; then
\rm -f "${HHS_DIR}/.hhs-init"
echo -e "\n${YELLOW}Your old .hhs-init renamed to .homesetup.toml and the old file was deleted.${NC}"
fi
# Init submodules case it's not there yet
if [[ ! -s "${HHS_HOME}/tests/bats/bats-core/bin/bats" ]]; then
pushd "${HHS_HOME}" &>/dev/null || quit 1 "Unable to enter homesetup directory \"${HHS_HOME}\" !"
echo -en "\n${YELLOW}Pulling bats submodules... ${NC}"
if git submodule update --init &>/dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Bats test will not be available${NC}"
fi
popd &>/dev/null || quit 1 "Unable to leave homesetup directory \"${HHS_HOME}\" !"
fi
# From HomeSetup 1.7+, we changed the HomeSetup config dir from $HOME/.hhs to $HOME/.config/hhs to match
# common the standard.
if [[ -d "${HOME}/.hhs" ]]; then
if rsync --archive "${HOME}/.hhs" "${HOME}/.config"; then
echo -e "\n${YELLOW}Your old ~/.hhs folder was moved to ~/.config/hhs !${NC}"
\rm -rf "${HOME}/.hhs" &>/dev/null || echo -e \
"${RED}Unable to delete the old .hhs directory. It was moved to ~/.config. Feel free to wipe it out!${NC}"
fi
fi
}
# Install Starship prompt.
configure_starship() {
if ! command -v starship &>/dev/null; then
echo -en "\n${WHITE}Installing Starship prompt... "
if curl -sSL "https://starship.rs/install.sh" 1>"${HHS_DIR}/install_starship.sh" \
&& chmod a+x "${HHS_DIR}"/install_starship.sh \
&& "${HHS_DIR}"/install_starship.sh -y -b "${HHS_BIN_DIR}" &>/dev/null; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Starship prompt will not be available${NC}"
fi
fi
}
# Install GTrash application
configure_gtrash() {
if ! command -v gtrash &>/dev/null; then
echo -en "\n${WHITE}Installing ${BLUE}GTrash${NC} app... "
if \
curl -sSL "https://github.com/umlx5h/gtrash/releases/latest/download/gtrash_$(uname -s)_$(uname -m).tar.gz" | tar xz \
&& chmod a+x ./gtrash \
&& \mv ./gtrash "${HHS_DIR}/bin/gtrash"; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}GTrash will not be available${NC}"
fi
fi
}
# Install ble.sh plug-in
configure_blesh() {
ble_repo="https://github.com/akinomyoga/ble.sh.git"
echo -en "\n${WHITE}Installing ${BLUE}Blesh${NC} plug-in... "
[[ -d "${HHS_BLESH_DIR}" ]] && \rm -rfv "${HHS_BLESH_DIR:?}" &>/dev/null
if \
git clone --recursive --depth 1 --shallow-submodules "${ble_repo}" "${HHS_BLESH_DIR}" >> "${INSTALL_LOG}" 2>&1 \
&& make -C "${HHS_BLESH_DIR}" >> "${INSTALL_LOG}" 2>&1; then
echo -e "${GREEN}OK${NC}"
else
echo -e "${RED}FAILED${NC}"
echo -e "${YELLOW}Ble-sh will not be available${NC}"
fi
}
# Configure AskAI HomeSetup/RAG documents
configure_askai_rag() {
if [[ -n "${INSTALL_AI}" ]]; then
# Copy HomeSetup AskAI prompts into place.
echo -en "\n${WHITE}Copying HomeSetup RAG docs... "
echo ">>> Copied HomeSetup RAG docs" >>"${INSTALL_LOG}"
copy_code="
from askai.core.component.rag_provider import RAGProvider