-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·146 lines (118 loc) · 2.99 KB
/
install
File metadata and controls
executable file
·146 lines (118 loc) · 2.99 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
#! /usr/bin/env bash
set -e
CLIUM_PATH="$( cd "$( dirname "$BASH_SOURCE" )" && pwd )"
CLIUM_SOURCE_PATH="$CLIUM_PATH/src/source"
source "$CLIUM_SOURCE_PATH/constants"
source "$CLIUM_SOURCE_PATH/error_handler"
set +e
report() {
printf "\n>>> ${PURPLE}%s${DEFAULT_COLOR}\n" "$@"
}
report_done() {
printf "<<< ${GREEN}%s${DEFAULT_COLOR}\n" "$@"
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
make_initial_checks() {
report "Making basic requirement checks"
if [ -z "$SHELL" ]
then
a_echo_err '$SHELL is null' || return_error
fi
report_done "Basic requirement checks passed"
}
#
# select loop is rather not the best choice for me.
# When I first used select loop, I was stuck cuz I
# didn't knew that a number needs to be selected and not
# text.
#
ask_yes_or_no() {
local yn
while true; do
read yn
case $yn in
[Yy]*)
return 0
;;
[Nn]*)
return 1
;;
*)
echo "Please enter [y/n]:"
;;
esac
done
}
dependency_checks() {
report "Making dependency checks"
IFS=$'\n'
for dep_name in $( < "$CLIUM_PATH/dependencies")
do
if ! command_exists "$dep_name"
then
echo "$dep_name is an important dependency of $PROG_NAME"
echo "$dep_name not found in PATH, do you still wish to proceeed?[y/n]"
ask_yes_or_no || return_error
fi
done
report_done "Dependency checks passed"
}
is_shell_bash() {
local shell_name
shell_name="${SHELL##*/}"
test "$shell_name" == "bash"
}
is_shell_zsh() {
local shell_name
shell_name="${SHELL##*/}"
test "$shell_name" == "zsh"
}
add_source_scripts() {
local code_to_add
if [ -n "$__SOURCE_GUARD_CLIUM__" ]
then
report_done "$CLIUM_PATH/to_source.sh already sourced, not adding it again"
return 0
fi
code_to_add="
# clium source scripts START
source '$CLIUM_PATH/to_source.sh'
# clium source scripts END"
if is_shell_zsh
then
report "Adding to_source.sh to .zshrc and .zlogin"
echo "$code_to_add" >> "$HOME/.zshrc"
echo "$code_to_add" >> "$HOME/.zlogin"
elif is_shell_bash
then
report "Adding to_source.sh to .bashrc and .bash_profile"
echo "$code_to_add" >> "$HOME/.bashrc"
echo "$code_to_add" >> "$HOME/.bash_profile"
else
a_printf_err "%s\n" \
"Only supported with bash or zsh as user's default shell" \
"Your shell = $SHELL"
return_error
fi
report_done "to_source.sh successfully added"
}
install_qtc_vim_syntax_highlighting() {
printf "\n%s\n" "Do you want to install vim syntax highlighting for .qtc files?[y/n]"
ask_yes_or_no || return 0
report "Adding vim syntax files"
mkdir -p "$HOME/.vim/syntax" || return_error
mkdir -p "$HOME/.vim/ftdetect" || return_error
cp "$CLIUM_PATH/vim/syntax/qtc.vim" "$HOME/.vim/syntax/" || return_error
cp "$CLIUM_PATH/vim/ftdetect/qtc.vim" "$HOME/.vim/ftdetect/" || return_error
report_done "Successfully added vim syntax files"
}
install() {
make_initial_checks || return_error
dependency_checks || return_error
add_source_scripts || return_error
install_qtc_vim_syntax_highlighting || return_error
report_done "Installation successful"
}
install "$@"