This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
init.sh
executable file
·226 lines (195 loc) · 7.02 KB
/
init.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
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
#!/bin/sh
AUTHORS="Michael Surbey, Eric D. Schabell"
DOCKER_MAJOR_VER=17
DOCKER_MINOR_VER=06
OC_MAJOR_VER="v3"
OC_MINOR_VER=5
GIT_REPO="https://github.com/redhatdemocentral/rhcs-cloudforms-demo"
# Adjust these variables to point to an OCP instance.
OPENSHIFT_USER=admin
OPENSHIFT_PWD=admin
HOST_IP=yourhost.com
OCP_PRJ=cloudforms
CF_IMAGE_TEMPLATE="https://raw.githubusercontent.com/openshift/openshift-ansible/master/roles/openshift_examples/files/examples/v3.6/cfme-templates/cfme-template.yaml"
# prints the documentation for this script.
function print_docs()
{
echo "This project can be installed on any OpenShift platform, such as the OpenShift Container"
echo "Platform (OCP). It is possible to install it on any available installation, just point"
echo "this installer at your installation by passing an IP of your OpenShift installation:"
echo
echo " $ ./init.sh IP"
echo
echo "If using Red Hat OCP, IP should look like: 192.168.99.100"
echo
}
# check for a valid passed IP address.
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
# wipe screen.
clear
echo
echo "#####################################################################"
echo "## ##"
echo "## Setting up your very own ##"
echo "## ##"
echo "## #### # ### # # #### ##### ### ##### # # #### ##"
echo "## # # # # # # # # # # # # # ## ## # ##"
echo "## # # # # # # # # #### # # ##### # # # ### ##"
echo "## # # # # # # # # # # # # # # # # ##"
echo "## #### ##### ### ### #### # ### # # # # #### ##"
echo "## ##"
echo "## $GIT_REPO ##"
echo "## ##"
echo "## Contributors: $AUTHORS ##"
echo "## ##"
echo "#####################################################################"
echo
# validate OpenShift host IP.
if [ $# -eq 1 ]; then
if valid_ip "$1" || [ "$1" == "$HOST_IP" ]; then
echo "OpenShift host given is a valid IP..."
HOST_IP=$1
echo
echo "Proceeding with OpenShift host: $HOST_IP..."
echo
else
# bad argument passed.
echo "Please provide a valid IP that points to an OpenShift installation..."
echo
print_docs
echo
exit
fi
elif [ $# -gt 1 ]; then
print_docs
echo
exit
else
# no arguments, prodeed with default host.
print_docs
echo
exit
fi
# make some checks first before proceeding.
command -v oc -v >/dev/null 2>&1 || { echo >&2 "OpenShift command line tooling is required but not installed yet... download here: https://access.redhat.com/downloads/content/290"; exit 1; }
echo "OpenShift commandline tooling is installed..."
echo
echo "Logging in to OpenShift as $OPENSHIFT_USER..."
echo
oc login $HOST_IP:8443 --password=$OPENSHIFT_PWD --username=$OPENSHIFT_USER
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during 'oc login' command!"
exit
fi
echo
echo "Creating a new project..."
echo
oc new-project $OCP_PRJ
echo
echo "Logging in to OpenShift as system admin..."
echo
oc login $HOST_IP:8443 -u system:admin
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during 'oc login' as system admin command!"
exit
fi
echo
echo "Creating service account for CloudForms..."
echo
oc create serviceaccount cfme -n $OCP_PRJ
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred creating service account for CloudForms!"
exit
fi
echo
echo "Granting service account cluster-admin access to CloudForms..."
echo
oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:cloudforms:cfme
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred granting service account cluster-admin access!"
exit
fi
echo
echo "Adding policy for service account to run CloudForms..."
echo
oc adm policy add-scc-to-user anyuid system:serviceaccount:cloudforms:cfme-anyuid
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during adding policy for service account!"
exit
fi
echo
echo "Setting policy privileges for running CloudForms..."
echo
oc adm policy add-scc-to-user privileged system:serviceaccount:cloudforms:default
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during setting policy privileges for service account!"
exit
fi
echo
echo "Importing CloudForms image template..."
echo
oc create -f $CF_IMAGE_TEMPLATE -n openshift
echo
echo "Logging in to OpenShift as $OPENSHIFT_USER..."
echo
oc login $HOST_IP:8443 --username=$OPENSHIFT_USER --password=$OPENSHIFT_PWD
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during 'oc login' command!"
exit
fi
echo
echo "Installing CloudForms..."
echo
oc new-app -p=APPLICATION_MEM_REQ=3072Mi --template=$OCP_PRJ -n $OCP_PRJ
if [ "$?" -ne "0" ]; then
echo
echo "Error occurred during install of CloudForms!"
exit
fi
echo "================================================================"
echo "= ="
echo "= Install complete, get ready to rock your new Red Hat ="
echo "= CloudForms management engine. ="
echo "= ="
echo "= The CloudForms log in is accessible via web at: ="
echo "= ="
echo "= https://cloudforms-cloudforms.$HOST_IP.nip.io ="
echo "= ="
echo "= Log in as: ="
echo "= ="
echo "= username: admin ="
echo "= password: smartvm ="
echo "= ="
echo "= Self service login at: ="
echo "= ="
echo "= https://cloudforms-cloudforms.$HOST_IP.nip.io/self_service ="
echo "= ="
echo "= username: admin ="
echo "= password: smartvm ="
echo "= ="
echo "= Note: it will take a few mintues for CloudForms to become ="
echo "= fully available, so login to Openshift connsole and watch ="
echo "= the deployments spin up. ="
echo "= ="
echo "================================================================"
echo