forked from kubash/kubash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap
executable file
·317 lines (299 loc) · 9.32 KB
/
bootstrap
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
#!/bin/bash -l
: ${KUBASH_DIR:=$HOME/.kubash}
: ${KUBASH_BIN:=$KUBASH_DIR/bin}
: ${GOPATH:=$HOME/.go}
PIP_INSTALL_PKGS="netaddr ceph-deploy"
APT_OPTS='-o DPkg::Lock::Timeout=60'
if [[ "$1" == '-y' ]]; then
echo 'using YES'
YES='-y'
YES_ARCH='--noconfirm'
else
YES=' '
YES_ARCH=' '
fi
set -ex
check_shell () {
THIS_SHELL=$(echo $SHELL| rev | cut -d'/' -f 1 | rev)
if [[ "$THIS_SHELL" == "zsh" ]]; then
. $HOME/.zshrc
elif [[ "$THIS_SHELL" == "bash" ]]; then
. $HOME/.bashrc
else
echo 'unsupported shell'
exit 1
fi
}
squawk () {
# This function simplifies error reporting and verbosity
# call it by preceding your message with a verbosity level
# e.g. `squawk 13 "This is a squawk"`
# if the current verbosity level is greater than or equal
# the number given then this function will echo out your message
# and pad it with # to let you now how verbose that message was
squawk_lvl=$1
shift
squawk=$1
shift
squawk_opt=$@
if [[ "$VERBOSITY" -ge "$squawk_lvl" ]] ; then
count_squawk=0
while [[ "$count_squawk" -lt "$squawk_lvl" ]]; do
echo -n "#"
count_squawk=`expr $count_squawk + 1`
done
echo " $squawk"
fi
}
# Check if a command exists
check_cmd () {
if ! type "$1" > /dev/null; then
echo "$1 was not found in your path!"
echo "To proceed please install $1 to your path and try again!"
exit 1
fi
}
# Check if a command exists, and if not install it
check_install () {
if ! type "$1" > /dev/null; then
squawk 10 "Installing $1"
cd ~/.kubash
make $1
else
squawk 10 "$1 is already installed"
fi
}
flight_checks () {
# Let's display everything on stderr.
exec 1>&2
UNAME=$(uname)
if [ "$UNAME" = "CYGWIN_NT-10.0" ] ; then
PLATFORM="os.cygwin.x86_64"
echo "WARNING: Cygwin is not supported at this time!"
exit 1
fi
if [ "$UNAME" == "Linux" ] ; then
if [[ $VERBOSITY -gt '1' ]]; then
squawk 10 " $UNAME is a Supported OS"
fi
elif [ "$UNAME" == "Darwin" -o "$UNAME" == "FreeBSD" ] ; then
if [[ $VERBOSITY -gt '1' ]]; then
echo " $UNAME is not a Supported OS"
exit 1
fi
elif [ "$UNAME" ">" "MINGW" -a "$UNAME" "<" "MINGX" ] ; then
if [[ $VERBOSITY -gt '1' ]]; then
echo " $UNAME is not a Supported OS"
exit 1
fi
else
echo " $UNAME is not a Supported OS"
echo "Sorry, this OS is not supported yet via this installer."
exit 1
fi
if [ "$UNAME" = "Linux" ] ; then
### Linux ###
LINUX_ARCH=$(uname -m)
if [ "${LINUX_ARCH}" = "x86_64" ] ; then
PLATFORM="os.linux.x86_64"
else
echo "Unusable architecture: ${LINUX_ARCH}"
echo "Kubash only supports x86_64 for now on Linux."
exit 1
fi
fi
# make reqs
if [ "$PLATFORM" = "os.linux.x86_64" ] ; then
squawk 10 "Installing on Linux"
fi
}
upgrade_go () {
GOTMP=$(mktemp -d)
cd $GOTMP
wget https://go.dev/dl/go1.19.2.linux-amd64.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.19.2.linux-amd64.tar.gz
}
apt_runner () {
if type "apt-get" &> /dev/null; then
check_cmd apt-get
$PSEUDO apt-get update
$PSEUDO apt-get $YES $APT_OPTS install $DEB_PKG_GET
fi
export PATH=/usr/local/go/bin:$PATH
}
main () {
. /etc/os-release
cat /etc/os-release
WHOAMI=$(whoami)
if [[ "$WHOAMI" = "root" ]]; then
PSEUDO=''
else
check_cmd sudo
PSEUDO='sudo'
fi
if [[ "$NAME" = 'Debian GNU/Linux' || $NAME = 'Ubuntu' ]]; then
if [[ "$CIRCLE_STAGE" == "acceptance-test" ]]; then
DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm net-tools dnsutils'
apt_runner
elif [[ "$VERSION_CODENAME" == "buster" ]]; then
DEB_PKG_GET='sudo jq git build-essential unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-clients libvirt-daemon-system net-tools dnsutils'
apt_runner
upgrade_go
elif [[ "$VERSION_CODENAME" == "bullseye" ]]; then
DEB_PKG_GET='sudo jq git build-essential unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-clients libvirt-daemon-system net-tools dnsutils'
apt_runner
upgrade_go
elif [[ "$UBUNTU_CODENAME" == "xenial" ]]; then
DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils'
apt_runner
elif [[ "$UBUNTU_CODENAME" == "bionic" ]]; then
DEB_PKG_GET='sudo jq git build-essential unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-clients libvirt-daemon-system net-tools dnsutils'
apt_runner
upgrade_go
elif [[ "$UBUNTU_CODENAME" == "focal" ]]; then
DEB_PKG_GET='sudo jq git build-essential unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils'
apt_runner
upgrade_go
elif [[ "$UBUNTU_CODENAME" == "jammy" ]]; then
DEB_PKG_GET='sudo jq git build-essential golang unzip curl wget parallel ansible rlwrap rsync nmap python3-pip virtinst qemu-kvm libvirt-daemon-system net-tools dnsutils'
apt_runner
else
echo 'OS not detected! bailing out. you are on your own.'
exit 1
fi
elif [[ "$NAME" = 'CentOS Linux' ]]; then
YUM_PKG_GET='sudo jq @development python3-pip golang unzip curl wget parallel ansible rlwrap rsync nmap net-tools qemu-kvm qemu-img virt-manager libvirt libvirt-python3 libvirt-client virt-install virt-viewer bridge-utils'
if type "yum" &> /dev/null; then
check_cmd yum
$PSEUDO yum $YES update
$PSEUDO yum install $YES epel-release
$PSEUDO yum $YES update
$PSEUDO yum install $YES $YUM_PKG_GET
fi
elif [[ "$NAME" = 'Arch Linux' ]]; then
check_cmd pacman
ARCH_PKG_GET='sudo awk nettle gettext jq git make go unzip curl wget parallel ansible rlwrap python-pip openbsd-netcat rsync nmap net-tools openssh'
#echo "$PSEUDO pacman -Sy"
#$PSEUDO pacman -Sy
#$PSEUDO pacman -Su $YES_ARCH
$PSEUDO pacman -Syu $YES_ARCH $ARCH_PKG_GET
# if type "powerpill" &> /dev/null; then
# check_cmd powerpill
# #echo "$PSEUDO powerpill -S $YES_ARCH $ARCH_PKG_GET"
# #$PSEUDO powerpill -S $YES_ARCH $ARCH_PKG_GET
# $PSEUDO pacman -S $YES_ARCH $ARCH_PKG_GET
# elif type "pacman" &> /dev/null; then
# echo "$PSEUDO pacman -Sy $YES_ARCH $ARCH_PKG_GET"
# fi
fi
check_cmd git
check_cmd ssh
check_cmd ansible
check_cmd curl
check_cmd unzip
check_cmd uname
check_cmd go
if [[ -x /usr/bin/pip3 ]]; then
echo 'Setting PIP=/usr/bin/pip3'
PIP=/usr/bin/pip3
elif [[ -x $(which pip3) ]]; then
echo 'Setting PIP=pip3'
PIP=pip3
else
echo 'Cannot find pip3 Setting PIP=pip'
PIP=pip
fi
check_cmd $PIP
check_cmd make
check_cmd parallel
check_cmd 'grep'
check_cmd 'sed'
flight_checks
if [[ "$CIRCLECI" == true ]]; then
echo 'in CircleCI skipping git clone'
elif [ ! -d $KUBASH_DIR ]; then
git clone https://github.com/kubash/kubash.git $KUBASH_DIR
else
echo "KUBASH_DIR=$KUBASH_DIR found"
echo 'using found kubash directory'
cd $KUBASH_DIR
pwd
git log -n1|cat
fi
export PATH=$HOME/.kubash/bin:$PATH
$KUBASH_DIR/scripts/dotfiles
check_shell
cd $KUBASH_DIR
if [[ "$CI_BUILD_REF_SLUG" == "fulltest" ]]; then
THISGITLAB_EXISTS=$(git remote|grep thisgitlab|wc -l)
if [[ "$THISGITLAB_EXISTS" == "0" ]]; then
git remote add -f thisgitlab https://gitlab.com/kubash/kubash.git
else
echo 'no need to add remote'
fi
git fetch --all
git checkout fulltest
fi
echo 'Updating submodules in the kubash directory'
git submodule update --init --recursive
echo 'ensure openebs is installed'
make submodules/openebs
if [[ "$CIRCLE_STAGE" == "acceptance-test" ]]; then
echo 'circleci acceptance-test so nvm is installed!'
else
echo 'ensure nvm is installed'
make nvm
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install lts/fermium
nvm use --default lts/fermium
nvm alias default node
fi
check_cmd npm
echo 'ensure jinja2 is installed'
cd $KUBASH_DIR
$PIP install --user --upgrade jinja2-cli
#cat $HOME/.bashrc
. $HOME/.bashrc
#echo $PATH
#check_install jinja2
cd $KUBASH_DIR
make yaml2json
#echo 'ensure ct is installed'
cd $KUBASH_DIR
make ct
#check_install ct
#make ct
check_install helm
check_install oc
# These need to exist in .kubash/bin/
cd $KUBASH_DIR
make cfssl
cd $KUBASH_DIR
make packer
cd $KUBASH_DIR
# coreOS is deprecated
#make coreos_key
cd $KUBASH_DIR
make kubectl
cd $KUBASH_DIR
check_install crictl
# onessl is deprecated and is being removed
#check_install onessl
$PIP install --user --upgrade $PIP_INSTALL_PKGS
if [ -w /usr/local/bin ] ; then
touch /usr/local/bin/test_file_01
rm /usr/local/bin/test_file_01
echo '/usr/local/bin is writeable by the current user'
else
echo '/usr/local/bin is not writeable by the current user'
echo 'Please ensure the current user can write to /usr/local/bin'
#exit 1
fi
echo 'logout and log back in, or source your RC files'
}
time main "$@"
echo 'bootstrap complete'
exit 0