-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-klibio.sh
executable file
·182 lines (164 loc) · 5.69 KB
/
install-klibio.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
#!/bin/bash
#
# install klibio bootstrap libraries and tools
#
# activate bash checks
if [[ ${debug:-false} == true ]]; then
set -o xtrace # activate bash debug
fi
# activate bash checks
set -o nounset # exit with error on unset variables
set -o errexit # exit if any statement returns a non-true return value
set -o pipefail # exit if any pipe command is failing
# tool variables
eclipse=0
java=0
oomph=0
overwrite=false
unsafe=""
for i in "$@"; do
case $i in
# tool parameter
-e|--eclipse)
eclipse=1
;;
-j|--java)
java=1
;;
-o|--oomph)
oomph=1
;;
# for develoment purposes
-f|--force)
overwrite=true
;;
-u|--unsafe)
export unsafe=k
;;
-b=*|--branch=*)
branch="${i#*=}"
shift # past argument=value
;;
--dev)
export LOCAL_DEV=HOME_devel
;;
--dev=*)
dev_suffix="${i#*=}"
export LOCAL_DEV=HOME_devel_${dev_suffix}
shift # past argument=value
;;
# default for unknown parameter
-*|--*)
echo "unknow option $i provided"
exit 1
;;
*)
;;
esac
done
# define and set KLIBIO root folder
branch=${branch:-main}
if [[ ${LOCAL_DEV:-false} == HOME_devel* ]]; then
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-.}" )" &> /dev/null && pwd )
export HOME=${script_dir}/${LOCAL_DEV}
export KLIBIO=${HOME}/.klibio
mkdir -p ${KLIBIO}
cp -rf ${script_dir}/.klibio/* ${KLIBIO}
# to be reviewed
# mkdir -p ${KLIBIO}/.ssh
# cp ${HOME}/.ssh/id_rsa ${KLIBIO}/.ssh/id_rsa
echo "sourcing klibio.sh"
. ${KLIBIO}/klibio.sh
echo "###########################################################"
echo "# LOCAL DEV ACTIVE # install-klibio.sh inside ${LOCAL_DEV} "
echo "###########################################################"
else
export KLIBIO=$(echo ${HOME}/.klibio)
lib_url=https://raw.githubusercontent.com/klibio/bootstrap/${branch}/.klibio/klibio.sh
echo "# sourcing klibio library - ${lib_url}"
install_dir=${HOME}
$(curl -fs${unsafe:-}SLO ${lib_url})
. klibio.sh
rm klibio.sh
fi
# https://manytools.org/hacker-tools/ascii-banner/
headline "$(cat <<-EOM
###########################################################
██╗ ██╗██╗ ██╗██████╗ ██╗ ██████╗
██║ ██╔╝██║ ██║██╔══██╗██║██╔═══██╗
█████╔╝ ██║ ██║██████╔╝██║██║ ██║
██╔═██╗ ██║ ██║██╔══██╗██║██║ ██║
██║ ██╗███████╗██║██████╔╝██║╚██████╔╝
╚═╝ ╚═╝╚══════╝╚═╝╚═════╝ ╚═╝ ╚═════╝
███████╗███████╗████████╗██╗ ██╗██████╗
██╔════╝██╔════╝╚══██╔══╝██║ ██║██╔══██╗
███████╗█████╗ ██║ ██║ ██║██████╔╝
╚════██║██╔══╝ ██║ ██║ ██║██╔═══╝
███████║███████╗ ██║ ╚██████╔╝██║
╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚═╝
###########################################################
EOM
)"
headline "provision sources into ${KLIBIO}"
if [[ ${LOCAL_DEV:-false} == HOME_devel* ]]; then
tar xvzf .klibio.tar.gz -C $(dirname ${KLIBIO})
else
github_provision .klibio.tar.gz $(dirname ${KLIBIO})
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
set +o errexit
brew --version >/dev/null 2>&1; brew_installed=$?
set -o errexit
if [[ 0 != ${brew_installed} ]]; then
echo "homebrew is not installed, but required - see https://docs.brew.sh/Installation"
else
brew list | grep coreutil >/dev/null 2>&1; coreutils_installed=$?
if [[ 0 != ${coreutils_installed} ]]; then
echo "coreutils in homebrew is not installed, hence installing it"
/bin/bash -c "NONINTERACTIVE=1; brew install coreutils"
fi
fi
if [[ -z $(grep "# klibio zsh extension" ~/.zshrc 2>/dev/null) ]]; then
headline "configure klibio extension inside ~/.zshrc/.zshrc"
cat << EOT >> ~/.zshrc
# klibio zsh extension
export KLIBIO=${KLIBIO}
export PATH=\${KLIBIO}:\${PATH}
if [[ -f \${KLIBIO}/.klibio_profile ]]; then
. \${KLIBIO}/.klibio_profile
fi
EOT
else
headline "klibio extension already inside ~/.zshrc"
fi
else
if [[ -z $(grep "# klibio bash extension" ~/.bashrc 2>/dev/null) ]]; then
headline "configure klibio extension inside ~/.bashrc"
cat << EOT >> ~/.bashrc
# klibio bash extension
export KLIBIO=${KLIBIO}
export PATH=\${KLIBIO}:\${PATH}
if [[ -f \${KLIBIO}/.klibio_profile ]]; then
. \${KLIBIO}/.klibio_profile
fi
EOT
else
headline "klibio extension already inside ~/.bashrc"
fi
fi
provide_tool () {
tool=$1
provision_tool=${KLIBIO}/provision-${tool}.sh
headline "provision ${tool} start"
. ${provision_tool}
headline "provision ${tool} finished"
}
${KLIBIO}/provision-tools.sh
((${eclipse})) && provide_tool eclipse || echo "skip eclipse provisioning"
((${java})) && provide_tool java || echo "skip java provisioning"
((${oomph})) && provide_tool oomph || echo "skip oomph provisioning"
. ${KLIBIO}/.klibio_profile
headline "klibio setup script completed"
set +o nounset # exit with error on unset variables
set +o errexit # exit if any statement returns a non-true return value
set +o pipefail # exit if any pipe command is failing