-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
270 lines (233 loc) · 8.6 KB
/
install.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
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
#!/bin/bash
CYAN='\033[0;36m' # Cyan
RED='\033[0;31m' # Red
NC='\033[0m' # No Color
if [ "$(id -u)" != "0" ]; then
echo -e "${RED}This script must be run as root.${NC}" 1>&2
exit 1
fi
# Initialize
echo -e "Welcome to the Tipoca City setup!"
echo -e "Visit the README for help using this script: ${CYAN}https://github.com/evanjd711/TipocaCity/blob/main/README.md${NC}\n"
sudo apt update
sudo apt install git curl ca-certificates gnupg ldap-utils
sudo apt-get update
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
git clone --recursive https://github.com/evanjd711/TipocaCity /opt/TipocaCity
cd /opt/TipocaCity
# Starting Port Group
echo -ne "${CYAN}Enter Starting Port Group ${NC}(1000-4096, Default: 1801): "
read startingportgroup
startingportgroup=${startingportgroup:-1801}
# Ending Port Group
echo -ne "${CYAN}Enter Ending Port Group ${NC}(1000-4096, Default: 4000): "
read endingportgroup
endingportgroup=${endingportgroup:-4000}
# Use HTTPS
echo -ne "${CYAN}Use HTTPS ${NC}(Y/N, Default: Y): "
read https
if [ -z "$https" ]; then
https="true"
elif [[ "$https" =~ ^[Yy]$ ]]; then
https="true"
elif [[ "$https" =~ ^[Nn]$ ]]; then
https="false"
fi
# vCenter FQDN
echo -ne "${CYAN}vCenter FQDN: ${NC}"
read vcenterurl
if [ -z "$vcenterurl" ]; then
echo -e "${RED}[ERROR] - vCenter FQDN is required.${NC}"
exit 1
fi
export vcenterurl=$vcenterurl
# vCenter API Account
echo -ne "${CYAN}vCenter API Account: ${NC}"
read -r vcenterusername
if [ -z "$vcenterusername" ]; then
echo -e "${RED}[ERROR] - vCenter Username is required.${NC}"
exit 1
fi
export vcenterusername=$vcenterusername
# vCenter API Password
echo -ne "${CYAN}vCenter API Password: ${NC}"
read -s vcenterpassword
echo
if [ -z "$vcenterpassword" ]; then
echo -e "${RED}[ERROR] - vCenter Password is required.${NC}"
exit 1
fi
export vcenterpassword=$vcenterpassword
# vCenter Datacenter
echo -ne "${CYAN}vCenter Datacenter: ${NC}"
read datacenter
if [ -z "$datacenter" ]; then
echo -e "${RED}[ERROR] - vCenter Datacenter is required.${NC}"
exit 1
fi
export datacenter=$datacenter
# vCenter Cluster or host
echo -ne "${CYAN}vCenter Cluster or Host ${NC}(for Resource Pools): "
read cluster
if [ -z "$cluster" ]; then
echo -e "${RED}[ERROR] - vCenter Cluster or Host is required.${NC}"
exit 1
fi
export cluster=$cluster
# Parent Resource Pool
echo -ne "${CYAN}Parent Resource Pool ${NC}(Default: Kamino): "
read parentresourcepool
parentresourcepool=${parentresourcepool:-"Kamino"}
export parentresourcepool=$parentresourcepool
# Template Resource Pool
echo -ne "${CYAN}Template Resource Pool ${NC}(Default: Kamino-Templates): "
read presettemplateresourcepool
presettemplateresourcepool=${presettemplateresourcepool:-"Kamino-Templates"}
export presettemplateresourcepool=$presettemplateresourcepool
# Destination Resource Pool for Clones
echo -ne "${CYAN}Clone Resource Pool for Clones ${NC}(Default: Kamino-Clones): "
read targetresourcepool
targetresourcepool=${targetresourcepool:-"Kamino-Clones"}
export targetresourcepool=$targetresourcepool
# Inventory Location for Kamino VMs
echo -ne "${CYAN}Inventory Location for Kamino VMs ${NC}(Default: Kamino): "
read inventorylocation
inventorylocation=${inventorylocation:-"Kamino"}
export inventorylocation=$inventorylocation
# Datastore for Kamino VMs
echo -ne "${CYAN}Datastore for Kamino VMs ${NC}: "
read datastore
if [ -z "$datastore" ]; then
echo -e "${RED}[ERROR] - Datastore is required.${NC}"
exit 1
fi
# WAN Port Group
echo -ne "${CYAN}WAN Port Group: ${NC}"
read wanportgroup
if [ -z "$wanportgroup" ]; then
echo -e "${RED}[ERROR] - WAN Port Group is required.${NC}"
exit 1
fi
# WAN Network
echo -ne "${CYAN}WAN Network ID ${NC}(e.g. 172.16): "
read firsttwooctets
if [ -z "$firsttwooctets" ]; then
echo -e "${RED}[ERROR] - WAN Network's First Two Octets are required.${NC}"
exit 1
fi
# Maximum Pods per User
echo -ne "${CYAN}Maximum Pods per User ${NC}(Default: 5):"
read maxpodlimit
maxpodlimit=${maxpodlimit:-5}
# vSphere Distributed Switch
echo -ne "${CYAN}vSphere Distributed Switch: ${NC}"
read maindistributedswitch
if [ -z "$maindistributedswitch" ]; then
echo -e "${RED}[ERROR] - vSphere Distributed Switch is required.${NC}"
exit 1
fi
# Kamino Port Groups Suffix
echo -ne "${CYAN}Kamino Port Groups Suffix ${NC}(Default: KaminoNetwork): "
read portgroupsuffix
portgroupsuffix=${portgroupsuffix:-"KaminoNetwork"}
# VM Template Folder
echo -ne "${CYAN}VM Template Folder ${NC}(Default: Templates): "
read templatefolder
templatefolder=${templatefolder:-"Templates"}
export templatelocation=$templatefolder
# LDAP Password
echo -ne "${CYAN}LDAP Server Admin Password: ${NC}"
read -s ldapadminpassword
if [ -z "$ldapadminpassword" ]; then
echo -ne "${RED}[ERROR] - LDAP Server Admin Password is required.${NC}"
exit 1
fi
export ldapadminpassword=$ldapadminpassword
echo -ne "${CYAN}FQDN to Kamino to Use (Example: kamino.your.domain): ${NC}"
read fqdn
echo -ne "${CYAN}Password for pfSense NAT Template: ${NC}(Default: pfsense): "
read -s pfsensepassword
pfsensepassword=${pfsensepassword:-"pfsense"}
export pfsensepassword=$pfsensepassword
# Setting Configs
echo -e "${CYAN}Configurating...${NC}"
# Create config files
echo "Creating config files..."
cat << EOF > cyclone/config.conf
startingportgroup = $startingportgroup
endingportgroup = $endingportgroup
https = $https
key = "./tls/key.pem"
cert = "./tls/cert.pem"
port = 8080
vCenterURL = "$vcenterurl"
vCenterUsername = "$vcenterusername"
vCenterPassword = "$vcenterpassword"
ldapadminpassword = "$ldapadminpassword"
datacenter = "$datacenter"
presettemplateresourcepool = "$presettemplateresourcepool"
targetresourcepool = "$targetresourcepool"
domain = "kamino.labs"
wanportgroup = "$wanportgroup"
maxpodlimit = $maxpodlimit
logPath = "/opt/cyclone/logs/cyclone.log"
maindistributedswitch = "$maindistributedswitch"
EOF
# Create SSL Certs
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=US/ST=CA/L=Pomona/O=Kamino/OU=Kamino/CN=tipoca.kamino.labs"
mkdir ./cyclone/tls
cp *.pem ./cyclone/tls/
mkdir ./kamino-frontend/tls
cp *.pem ./kamino-frontend/tls/
#Configure Kamino Frontend
sed -i "s/{fqdn}/https:\/\/$fqdn/g" /opt/TipocaCity/kamino-frontend/src/pages/Dashboard/*.vue
sed -i "s/{fqdn}/https:\/\/$fqdn/g" /opt/TipocaCity/kamino-frontend/src/pages/UserProfile/*.vue
sed -i "s/{fqdn}/https:\/\/$fqdn/g" /opt/TipocaCity/kamino-frontend/src/pages/*.vue
sed -i "s/{fqdn}/https:\/\/$fqdn/g" /opt/TipocaCity/kamino-frontend/src/router/*.js
# Setup Cyclone
mkdir /opt/TipocaCity/cyclone/logs
mkdir ./cyclone/lib
mkdir ./cyclone/lib/creds
sed -i "s/{vcenterfqdn}/$vcenterurl/g" /opt/TipocaCity/cyclone/pwsh/*.ps1
sed -i "s/{fqdn}/https:\/\/$fqdn/g" /opt/TipocaCity/cyclone/main.go
sed -i "s/{portgroupsuffix}/$portgroupsuffix/g" /opt/TipocaCity/cyclone/vsphere.go
sed -i "s/{templatefolder}/$templatefolder/g" /opt/TipocaCity/cyclone/vsphere.go
# Setup Kamino PowerShell Module
sed -i "s/{firsttwooctets}/$firsttwooctets/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
sed -i "s/{portgroupsuffix}/$portgroupsuffix/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
sed -i "s/{inventorylocation}/$inventorylocation/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
sed -i "s/{datastore}/$datastore/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
sed -i "s/{targetresourcepool}/$targetresourcepool/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
sed -i "s/{maindistributedswitch}/$maindistributedswitch/g" /opt/TipocaCity/cyclone/pwsh/Kamino/Kamino.psm1
cd /opt/TipocaCity
docker-compose up -d
if [ $https == "true" ]; then
url="https://$fqdn:8080/ping"
else
url="http://$fqdn:8080/ping"
fi
while true; do
response=$(curl -o /dev/null -s -w "%{http_code}\n" "$url" -k)
if [ "$response" -eq 200 ]; then
echo -e "${CYAN}Kamino is now running.${NC}"
break
else
echo -e "${RED}Waiting for Kamino to start...${NC}"
sleep 5
fi
done
# Cleanup
rm /opt/TipocaCity/*.pem
rm -rf /opt/TipocaCity/cyclone/pwsh/install
rm /opt/TipocaCity/install.sh
rm-rf /opt/TipocaCity/ldap
chmod 600 /opt/TipocaCity/cyclone/lib/creds/*
chmod 600 /opt/TipocaCity/cyclone/config.conf