-
Notifications
You must be signed in to change notification settings - Fork 36
/
prepare.sh
executable file
·187 lines (165 loc) · 5.86 KB
/
prepare.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
#!/bin/bash
if [ ! -d /etc/trinity ]; then
mkdir /etc/trinity
fi
# --------------------------------------------------------------------------------------
function add_message() {
echo -e "$1" | fold -w70 -s >> /tmp/mesg.$$.dat
}
function show_message() {
echo "****************************************************************************"
echo "* *"
while read -r LINE
do
printf '* %-70s *\n' "$LINE"
done < /tmp/mesg.$$.dat
echo "* *"
echo "****************************************************************************"
truncate -s0 /tmp/mesg.$$.dat
}
function get_confirmation() {
local DEFAULT=$1
local MESG=$2
local CONFIRM=""
while [ ! "$CONFIRM" ]; do
case $DEFAULT in
[Yy]|yes|Yes|YES)
echo -n "$MESG? (<y>|n): " >&2
;;
*)
echo -n "$MESG? (y|<n>): " >&2
;;
esac
read -t 600 CONFIRM
RET=$?
if [ "$RET" == "142" ] || [ ! "$CONFIRM" ]; then
CONFIRM=$DEFAULT
fi
case $CONFIRM in
[Yy]|yes|Yes|YES)
echo yes
;;
[Nn]|no|No|NO)
echo no
;;
*)
CONFIRM=""
;;
esac
done
}
function store_config() {
local KEY=$1
local VALUE=$2
if [ -f /etc/trinity/prepare.conf ] && [ "$(grep '^'$KEY'=' /etc/trinity/prepare.conf)" ]; then
sed -i 's/^'$KEY'=.*$/'$KEY'='$VALUE'/' /etc/trinity/prepare.conf
else
echo "$KEY=$VALUE" >> /etc/trinity/prepare.conf
fi
}
# --------------------------------------------------------------------------------------
if [ -f /etc/trinity/prepare.conf ]; then
while IFS='=' read -ra line; do
comment=$(echo $line | grep '^#')
if [ ! "$comment" ]; then
if [ "$line" ]; then
key=$(echo ${line[0]})
value=$(echo ${line[1]})
declare -x "${key}"="${value}"
echo "$key = $value"
fi
fi
done < /etc/trinity/prepare.conf
fi
# --------------------------------------------------------------------------------------
if [[ `getenforce` == "Disabled" ]]; then
add_message "SELinux in disabled mode is not supported. Please reboot to run in permissive mode"
if [[ `grep "^SELINUX=disabled$" /etc/selinux/config` ]]; then
sed -i 's/SELINUX=disabled/SELINUX=permissive/g' /etc/selinux/config
show_message
exit 1
fi
fi
if [ ! -f TrinityX.pdf ]; then
add_message "Please run from within the cloned TrinityX folder"
else
# To disable SElinux on the controller node
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
if [ ! "$GITLAB_CI" ]; then
if [ -f site/tui_configurator ]; then
rm -f site/tui_configurator
fi
if [ ! "$(which wget)" ]; then
dnf -y install wget
fi
TRIX_VER=$(grep 'trix_version' site/group_vars/all.yml.example 2> /dev/null | grep -oE '[0-9\.]+' || echo '14.1')
wget --directory-prefix site/ https://updates.clustervision.com/trinityx/${TRIX_VER}/install/tui_configurator
chmod 755 site/tui_configurator
fi
# inside a runner (test mode) we do not update the kernel.
if [ "$GITLAB_CI" ]; then
dnf update -y --exclude=kernel*
else
dnf update -y
fi
dnf install curl tar git -y
REDHAT_RELEASE=''
if [[ `grep -i "Red Hat Enterprise Linux 8" /etc/os-release` ]]; then
REDHAT_RELEASE=8
elif [[ `grep -i "Red Hat Enterprise Linux 9" /etc/os-release` ]]; then
REDHAT_RELEASE=9
fi
if [ "$REDHAT_RELEASE" ]; then
subscription-manager repos --enable codeready-builder-for-rhel-${REDHAT_RELEASE}-x86_64-rpms
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-${REDHAT_RELEASE}.noarch.rpm -y
dnf install ansible-core -y
dnf install ansible -y
else
dnf install epel-release -y
dnf install ansible -y
fi
ansible-galaxy install OndrejHome.pcs-modules-2
# kernel check. Did we pull in a newer kernel?
CURRENT_KERNEL=$(uname -r)
LATEST_KERNEL=$(ls -tr /lib/modules/|tail -n1)
if [ "$USE_CURRENT_KERNEL" != "yes" ] && [ "$CURRENT_KERNEL" != "$LATEST_KERNEL" ] && [ ! "$GITLAB_CI" ]; then
add_message "Current running kernel is not the latest installed. It comes highly recommended to reboot prior continuing installation."
add_message "After reboot, please re-run prepare.sh to make sure all requirements are met."
show_message
USE_CURRENT_KERNEL=$(get_confirmation n "Do you want to proceed with current kernel")
if [ "$USE_CURRENT_KERNEL" == "no" ]; then
exit 1
fi
fi
if [ ! "$WITH_ZFS" ] && [ ! "$GITLAB_CI" ]; then
add_message "Would you prefer to include ZFS?"
add_message "ZFS is supported in the shared_fs_disk/HA role. If you prefer to use ZFS there, please confirm below."
show_message
WITH_ZFS=$(get_confirmation y "Do you want to install ZFS")
fi
store_config 'WITH_ZFS' $WITH_ZFS
if [ "$WITH_ZFS" == "yes" ] || [ "$GITLAB_CI" ]; then
yes y | dnf -y install https://zfsonlinux.org/epel/zfs-release-2-2$(rpm --eval "%{dist}").noarch.rpm
yes y | dnf -y install zfs zfs-dkms
echo "zfs" >> /etc/modules-load.d/zfs.conf
modprobe zfs
fi
if [ ! -f site/hosts ]; then
add_message "Please modify the site/hosts.example and save it as site/hosts"
else
if ! grep -q "^$(hostname -s)\s*" site/hosts; then
add_message "Please note the hostnames are not matching (see site/hosts)."
fi
fi
if [ ! -f site/group_vars/all.yml ]; then
add_message "Please modify the site/group_vars/all.yml.example and save it as site/group_vars/all.yml"
else
if ! grep -q "^trix_ctrl1_hostname:\s*$(hostname -s)\s*$" site/group_vars/all.yml; then
add_message "Please note the hostnames are not matching (see site/group_vars/all.yml)."
fi
fi
add_message "Please configure the network before starting Ansible"
fi
touch /etc/trinity/prepare.done
show_message