This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
installer.sh
executable file
·1174 lines (1034 loc) · 44.2 KB
/
installer.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2013-2014 STACKOPS TECHNOLOGIES S.L.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#!/usr/bin/env bash
set -e
set -o nounset # Treat unset variables as an error
ScriptVersion="1.0"
ScriptName="installer.sh"
InstallPortal="false"
InstallChargeback="false"
InstallMySql="false"
InstallApache="false"
InstallApacheWithSSL="false"
PortalMySqlUsr="portal"
PortalMySqlPassword="stackops"
PortalMySqlSchema="portal"
ActivityMySqlUsr="activity"
ActivityMySqlPassword="stackops"
ActivityMySqlSchema="activity"
ChargebackMySqlUsr="chargeback"
ChargebackMySqlPassword="stackops"
ChargebackMySqlSchema="chargeback"
ChargebackKeystoneUsr="chargeback"
ChargebackKeystonePassword="stackops"
MySqlHost="localhost"
MySqlPort="3306"
KeystoneUrl="http://localhost:5000/v2.0"
MYSQL_ROOT_PASSWORD="stackops"
OS_USERNAME="admin"
OS_PASSWORD=""
OS_TENANT_NAME="admin"
OS_AUTH_URL="http://api.stackops.net:35357/v2.0"
OS_AUTH_TOKEN="stackops"
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USR=guest
RABBITMQ_PASSWORD=guest
ACTIVITY_INTERNAL_URL="http://localhost:8080/activity"
CHARGEBACK_INTERNAL_URL="http://localhost:8080/chargeback"
ACTIVITY_PUBLIC_URL="http://localhost:8080/activity"
CHARGEBACK_PUBLIC_URL="http://localhost:8080/chargeback"
KEYSTONE_DEFAULT_REGION="RegionOne"
usage() {
cat << EOT
Usage : ${ScriptName} [options] <install-args>
Options:
-h|help Display this message
-v|version Display script version
-c|chargeback Installs StackOps Chargeback
-p|portal Installs StackOps Portal
-m|mysql Installs MySQL server
-a|apache Installs Apache server for HTTP traffic
-s|ssl Installs Apache server for HTTPS traffic (SSL)
EOT
}
while getopts "hvcmasp" opt
do
case $opt in
h|help ) usage; exit 0 ;;
v|version ) echo "$0 -- Version $ScriptVersion";
exit 0 ;;
c|chargeback ) echo "\nA StackOps Chargeback will be installed on this server\n"
InstallChargeback="true"; ;;
m|mysql ) echo "\n * A MySQL server will be installed on this server\n"
InstallMySql="true"; ;;
a|apache ) echo "\n * An Apache server for HTTP traffic will be installed on this server\n"
InstallApache="true"; ;;
s|ssl ) echo "\n * An Apache server for HTTPS traffic will be installed on this server\n"
InstallApacheWithSSL="true"; ;;
p|portal ) echo "\nA StackOps Portal will be installed on this server\n"
InstallPortal="true"; ;;
\? ) echo "\n Option does not exist : $OPTARG\n"
usage; exit 1 ;;
esac
echo $opt
done
shift $(($OPTIND-1))
__check_unparsed_options() {
shellopts="$1"
unparsed_options=$( echo "$shellopts" | grep -E '[-]+[[:alnum:]]' )
if [ "x$unparsed_options" != "x" ]; then
usage
echo
echo " * ERROR: options come before install arguments"
echo
exit 1
fi
}
if [ "$#" -gt 5 ]; then
__check_unparsed_options "$*"
usage
echo
echo " * ERROR: Too many arguments."
exit 1
fi
# Root permissions are required to run this script
if [ $(whoami) != "root" ] ; then
echo " * ERROR: Requires root. Please re-run this script as root."
exit 1
fi
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_hardware_info
# DESCRIPTION: Discover hardware information
#-------------------------------------------------------------------------------
__gather_hardware_info() {
if [ -f /proc/cpuinfo ]; then
CPU_VENDOR_ID=$(cat /proc/cpuinfo | grep -E 'vendor_id|Processor' | head -n 1 | awk '{print $3}' | cut -d '-' -f1 )
else
CPU_VENDOR_ID=$( sysctl -n hw.model )
fi
CPU_VENDOR_ID_L=$( echo $CPU_VENDOR_ID | tr '[:upper:]' '[:lower:]' )
CPU_ARCH=$(uname -m 2>/dev/null || uname -p 2>/dev/null || echo "unknown")
CPU_ARCH_L=$( echo $CPU_ARCH | tr '[:upper:]' '[:lower:]' )
}
__gather_hardware_info
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_os_info
# DESCRIPTION: Discover operating system information
#-------------------------------------------------------------------------------
__gather_os_info() {
OS_NAME=$(uname -s 2>/dev/null)
OS_NAME_L=$( echo $OS_NAME | tr '[:upper:]' '[:lower:]' )
OS_VERSION=$(uname -r)
OS_VERSION_L=$( echo $OS_VERSION | tr '[:upper:]' '[:lower:]' )
}
__gather_os_info
#--- FUNCTION ----------------------------------------------------------------
# NAME: __parse_version_string
# DESCRIPTION: Parse version strings ignoring the revision.
# MAJOR.MINOR.REVISION becomes MAJOR.MINOR
#-------------------------------------------------------------------------------
__parse_version_string() {
VERSION_STRING="$1"
PARSED_VERSION=$(
echo $VERSION_STRING |
sed -e 's/^/#/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\)\(\.[0-9][0-9]*\).*$/\1/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\.[0-9][0-9]*\).*$/\1/' \
-e 's/^#[^0-9]*\([0-9][0-9]*\).*$/\1/' \
-e 's/^#.*$//'
)
echo $PARSED_VERSION
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_linux_system_info
# DESCRIPTION: Discover Linux system information
#-------------------------------------------------------------------------------
__gather_linux_system_info() {
DISTRO_NAME=""
DISTRO_VERSION=""
if [ -f /etc/lsb-release ]; then
DISTRO_NAME=$(grep DISTRIB_ID /etc/lsb-release | sed -e 's/.*=//')
DISTRO_VERSION=$(__parse_version_string $(grep DISTRIB_RELEASE /etc/lsb-release | sed -e 's/.*=//'))
fi
if [ "x$DISTRO_NAME" != "x" -a "x$DISTRO_VERSION" != "x" ]; then
# We already have the distribution name and version
return
fi
for rsource in $(
cd /etc && /bin/ls *[_-]release *[_-]version 2>/dev/null | env -i sort | \
sed -e '/^redhat-release$/d' -e '/^lsb-release$/d'; \
echo redhat-release lsb-release
); do
[ -L "/etc/${rsource}" ] && continue # Don't follow symlinks
[ ! -f "/etc/${rsource}" ] && continue # Does not exist
n=$(echo ${rsource} | sed -e 's/[_-]release$//' -e 's/[_-]version$//')
v=$( __parse_version_string "$( (grep VERSION /etc/${rsource}; cat /etc/${rsource}) | grep '[0-9]' | sed -e 'q' )" )
case $(echo ${n} | tr '[:upper:]' '[:lower:]') in
redhat )
if [ ".$(egrep '(Red Hat Enterprise Linux|CentOS)' /etc/${rsource})" != . ]; then
n="<R>ed <H>at <E>nterprise <L>inux"
else
n="<R>ed <H>at <L>inux"
fi
;;
arch ) n="Arch" ;;
centos ) n="CentOS" ;;
debian ) n="Debian" ;;
ubuntu ) n="Ubuntu" ;;
fedora ) n="Fedora" ;;
suse ) n="SUSE" ;;
mandrake*|mandriva ) n="Mandriva" ;;
gentoo ) n="Gentoo" ;;
slackware ) n="Slackware" ;;
turbolinux ) n="TurboLinux" ;;
unitedlinux ) n="UnitedLinux" ;;
* ) n="${n}" ;
esac
DISTRO_NAME=$n
DISTRO_VERSION=$v
break
done
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_sunos_system_info
# DESCRIPTION: Discover SunOS system info
#-------------------------------------------------------------------------------
__gather_sunos_system_info() {
DISTRO_NAME="Solaris"
DISTRO_VERSION=$(
echo "${OS_VERSION}" |
sed -e 's;^4\.;1.;' \
-e 's;^5\.\([0-6]\)[^0-9]*$;2.\1;' \
-e 's;^5\.\([0-9][0-9]*\).*;\1;'
)
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_bsd_system_info
# DESCRIPTION: Discover OpenBSD, NetBSD and FreeBSD systems information
#-------------------------------------------------------------------------------
__gather_bsd_system_info() {
DISTRO_NAME=${OS_NAME}
DISTRO_VERSION=$(echo "${OS_VERSION}" | sed -e 's;[()];;' -e 's/-.*$//')
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __gather_system_info
# DESCRIPTION: Discover which system and distribution we are running.
#-------------------------------------------------------------------------------
__gather_system_info() {
case ${OS_NAME_L} in
linux )
__gather_linux_system_info
;;
sunos )
__gather_sunos_system_info
;;
openbsd|freebsd|netbsd|darwin )
__gather_bsd_system_info
;;
* )
echo " * ERROR: $OS_NAME not supported.";
exit 1
;;
esac
}
#--- FUNCTION ----------------------------------------------------------------
# NAME: __function_defined
# DESCRIPTION: Checks if a function is defined within this scripts scope
# PARAMETERS: function name
# RETURNS: 0 or 1 as in defined or not defined
#-------------------------------------------------------------------------------
__function_defined() {
FUNC_NAME=$1
if [ "${DISTRO_NAME}" = "centos" ]; then
if typeset -f $FUNC_NAME &>/dev/null ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
elif [ "${DISTRO_NAME}" = "ubuntu" ]; then
if $( type ${FUNC_NAME} | grep -q 'shell function' ); then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
# Last resorts try POSIXLY_CORRECT or not
elif test -n "${POSIXLY_CORRECT+yes}"; then
if typeset -f $FUNC_NAME >/dev/null 2>&1 ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
else
# Arch linux seems to fall here
if $( type ${FUNC_NAME} >/dev/null 2>&1 ) ; then
echo " * INFO: Found function $FUNC_NAME"
return 0
fi
fi
echo " * INFO: $FUNC_NAME not found...."
return 1
}
__gather_system_info
echo " * System Information:"
echo " CPU: ${CPU_VENDOR_ID}"
echo " CPU Arch: ${CPU_ARCH}"
echo " OS Name: ${OS_NAME}"
echo " OS Version: ${OS_VERSION}"
echo " Distribution: ${DISTRO_NAME} ${DISTRO_VERSION}"
# Simplify version naming on functions
if [ "x${DISTRO_VERSION}" = "x" ]; then
DISTRO_VERSION_NO_DOTS=""
else
DISTRO_VERSION_NO_DOTS="_$(echo $DISTRO_VERSION | tr -d '.')"
fi
# Simplify distro name naming on functions
DISTRO_NAME_L=$(echo $DISTRO_NAME | tr '[:upper:]' '[:lower:]' | sed 's/[^a-zA-Z0-9_ ]//g' | sed -e 's|[:space:]+|_|g')
#--- FUNCTION ----------------------------------------------------------------
# NAME: __apt_get_noinput
# DESCRIPTION: (DRY) apt-get install with noinput options
#-------------------------------------------------------------------------------
__apt_get_noinput() {
DEBIAN_FRONTEND=noninteractive
apt-get install -y -o DPkg::Options::=--force-confold $@
DEBIAN_FRONTEND=
}
__apt_get_update() {
apt-get update -y
}
__check_command() {
command -v $1 >/dev/null 2>&1 || { echo >&2 "I require $1 but it's not installed. Aborting."; exit 1; }
}
__get_auth_token() {
set +e
credentials=`curl -s -d "{\"auth\":{\"passwordCredentials\": {\"username\": \"$OS_USERNAME\", \"password\": \"$OS_PASSWORD\"}, \"tenantName\": \"$OS_TENANT_NAME\"}}" -H "Content-type: application/json" $OS_AUTH_URL/tokens`
auth_token=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['access']['token']['id'];"`
[ ! -z "${auth_token}" ] || { echo >&2 `echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['error'];"`; }
set -e
echo $auth_token
}
__is_portal_admin() {
credentials=`curl -s $OS_AUTH_URL/tokens/$1 -H "X-Auth-Token:$1" -H "Content-type: application/json"`
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_PORTAL_ADMIN' for d in t) "`
set -e
[ ! -z "${result}" ] || { echo >&2 `echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['error'];"`; }
echo $result
}
__is_chargeback_roles() {
credentials=`curl -s $OS_AUTH_URL/tokens/$1 -H "X-Auth-Token:$1" -H "Content-type: application/json"`
set +e
result_activity=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_ACTIVITY' for d in t) "`
result_accounting=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_ACCOUNTING' for d in t) "`
result_chargeback=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_CHARGEBACK' for d in t) "`
result_activity_admin=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_ACTIVITY_ADMIN' for d in t) "`
result_chargeback_admin=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); t = tok['access']['user']['roles']; print any(d['name'] == 'ROLE_CHARGEBACK_ADMIN' for d in t) "`
set -e
result="True"
if [ "${result_activity}" = "False" ]; then
result="ROLE_ACTIVITY does not exist.\n"
fi
if [ "${result_activity_admin}" = "False" ]; then
result="ROLE_ACTIVITY_ADMIN does not exist.\n"
fi
if [ "${result_accounting}" = "False" ]; then
result="ROLE_ACCOUNTING does not exist.\n"
fi
if [ "${result_chargeback}" = "False" ]; then
result="ROLE_CHARGEBACK does not exist.\n"
fi
if [ "${result_chargeback_admin}" = "False" ]; then
result="ROLE_CHARGEBACK_ADMIN does not exist.\n"
fi
echo $result
}
__configure_apt_repos() {
echo "deb http://repos.stackops.net/ $1 main" > /etc/apt/sources.list.d/stackops.list
wget -O - http://repos.stackops.net/keys/stackopskey_pub.gpg | apt-key add -
__apt_get_update
}
__configure_clinker_key() {
wget $1
set +e
keytool -keystore /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security/cacerts -delete -alias clinker -storepass changeit -noprompt
set -e
keytool -keystore /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/security/cacerts -storepass changeit -import -trustcacerts -v -alias clinker -file clinker.cert -noprompt
rm clinker.cert
}
__configure_apache() {
a2enmod proxy_http
a2enmod rewrite
rm /etc/apache2/sites-enabled/*
rename 's/(.*)/$1.bak/' /etc/apache2/sites-available/*
cat <<EOF > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /portal http://127.0.0.1:8080/portal
ProxyPassReverse /portal http://127.0.0.1:8080/portal
RewriteEngine on
RewriteRule ^/$ http://%{HTTP_HOST}/portal [R]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ErrorLog /var/log/apache2/apache-portal-error.log
TransferLog /var/log/apache2/apache-portal-access.log
</VirtualHost>
EOF
ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf
}
__configure_apache_ssl() {
a2enmod proxy_http
a2enmod ssl
a2enmod rewrite
a2ensite default-ssl
rm /etc/apache2/sites-enabled/*
rename 's/(.*)/$1.bak/' /etc/apache2/sites-available/*
cat <<EOF > /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /portal http://127.0.0.1:8080/portal
ProxyPassReverse /portal http://127.0.0.1:8080/portal
RewriteEngine on
RewriteRule ^/$ https://%{HTTP_HOST}/portal [R]
ReWriteCond %{SERVER_PORT} !^443\$
RewriteRule ^/(.*) https://%{HTTP_HOST}/\$1 [NC,R,L]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ErrorLog /var/log/apache2/apache-portal-error.log
TransferLog /var/log/apache2/apache-portal-access.log
</VirtualHost>
EOF
ln -s /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf
cat <<EOF > /etc/apache2/sites-available/000-default-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName localhost
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /portal http://127.0.0.1:8080/portal
ProxyPassReverse /portal http://127.0.0.1:8080/portal
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ErrorLog /var/log/apache2/apachessl-portal-error.log
TransferLog /var/log/apache2/apachessl-portal-access.log
SSLEngine on
RewriteEngine on
RewriteRule ^/$ https://%{HTTP_HOST}/portal [R]
SSLCertificateFile /etc/ssl/certs/sslcert.crt
SSLCertificateKeyFile /etc/ssl/private/sslcert.key
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
</IfModule>
EOF
ln -s /etc/apache2/sites-available/000-default-ssl.conf /etc/apache2/sites-enabled/000-default-ssl.conf
cat <<EOF > /tmp/nonsecure.key
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAtO4zZwNYOzux+ymvrW7kMojJ9diI7WxmPvESa1FNdY45TN5Z
WYSYcgYKDT/OuHDi9+49LlRPksV35scGNIJbqV9Cr4L0vHXfb9E9EdOIIkv3jOG9
QhhwIPxKrpJQP1hkPyxybWkH/IVHY06OxLIWPJO3NC74sQQvXZ2mMUoOW5KcQwiK
GfWf3mJKCccocNv3MXP4cb6ay7DQtbgQigjZaoQxffkJvq083h3y5lSQpnI56yBE
XHtHam8XCPnu7Axj0v5AGGaTYOa4RAzkG8PKpcvL8TRjPL3TMiiKJM2rQVrHdjcK
qBSOCr+fSNlr7E5KVBN8pfrsmly+NoflhA7hdQIDAQABAoIBAQCyz2rrlsmfGJsI
TyV48MwECV4XYt3IT0YpVFTQzPQRhvKoPmLtbna+0asjdvkVHTOitcevPtG5iwC5
id5fDKoMFMIx9OlsS837kz2YnYa/5nYLvJkvdjly0AP6zU0TnYbNTF72NEQZU5q+
0UeVqy8AxTfdEcLkJu+sxH4X3kmcQvhz2q7L2pbSgZ0JeL1Nfxmy0cjsSKEVy3qY
0tLVm4xHStoYNBpzgXyBqhz/wAhOcctUyl5qvpNzgR+ihASNRKYKIGcpjgjaSryk
0Gp8WmwrSuy1qQ8iqKRkSa5SSWqwl1umWlb1V8+7m4ic0A/GJEhzJ5pfXPMaOQuF
eHG60JNNAoGBAOyA1R1US5mjoaIZmahR2Rl6nYFQQy3HNqQy1AZU5hB4uTrMA2eW
sSxt1RMBjlE9C0sUOFB95w48/gZNI6JPdMFGgcux5WrndDruY8txiVl3rw2Dw7Ih
JMxNBsJRO0AZgijUm11HPBp/tJ4HjppZiqE0exjoNFGOLc/l4VOZ1PbDAoGBAMPY
j0dS7eHcsmu+v6EpxbRFwSyZG0eV51IiT0DFLfiSpsfmtHdA1ZQeqbVadM1WJSLu
ZJ8uvGNRnuLgz2vwKdI6kJFfWYZSS5jfnl874/OF6riNQDseX5CvB5zQvTFVmae+
Mld4x2NYFxQ1vIWnGITGQKhcZonBMyAjaQ9tAnNnAoGASvTOFpyX1VryKHEarSk7
uIKPFuP8Vq7z13iwkE0qGYBZnJP6ZENzZdRtmrd8hqzlPmdrLb+pkm6sSAz8xT2P
kI4rJwb74jT3NpJFmL4kPPHczli7lmJAymuDP+UE9VzgTtaLYzXni7J76TYV8T99
23fJp+w4YLzCMkj2cEuqHocCgYBb2KEBMwwqw4TNcOyP2XZFn/0DPF6FyPBuHXcL
ii2QCL68ux5hWv+O8n5mdaCXd9H8us5ntNRWw71+6y17kmsak6qe8peandekPyMX
yI+T8nbszBmWYB0zTlKEoYRIsbtY5qLXUOY5WeOg776U85NVGWDTVFomOnwOk2y+
9kGS+wKBgD3cL/zabIv/kK7KY84EdWdVH4sal3bRsiNn4ezj7go/ObMgR59O4Lr4
fYqT1igILotduz/knlkleY2fsqltStWYzRrG+/zNryIBco2+cIX8T120AnpbAvlP
gj0YVjuLJXSC9w/URFG+ZGg0kX0Koy1yS6fuxikiA4f5Lw9znjaD
-----END RSA PRIVATE KEY-----
EOF
openssl req -nodes -newkey rsa:2048 -keyout /tmp/nonsecure.key -out /tmp/server.csr -subj "/C=ES/ST=MADRID/L=MADRID/O=STACKOPS TECHNOLOGIES SL./OU=STACKOPS PORTAL/CN=127.0.0.1"
openssl rsa -in /tmp/nonsecure.key -out /tmp/ssl.key
openssl x509 -req -days 365 -in /tmp/server.csr -signkey /tmp/ssl.key -out /tmp/ssl.crt
cp /tmp/ssl.crt /etc/ssl/certs/sslcert.crt
cp /tmp/ssl.key /etc/ssl/private/sslcert.key
}
# Get the tenant Id
__get_tenant_id()
{
credentials=`curl -s $OS_AUTH_URL/tenants -H "X-Auth-Token:$1" -H "Content-type: application/json"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print [d for d in tok['tenants'] if d['name'] == '$2'][0]['id'] " 2> /dev/null`
set -e
echo $result
}
# Get the role Id
__get_role_id() {
credentials=`curl -s $OS_AUTH_URL/OS-KSADM/roles -H "X-Auth-Token:$1" -H "Content-type: application/json"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print [d for d in tok['roles'] if d['name'] == '$2'][0]['id'] " 2> /dev/null`
set -e
echo $result
}
# Create role
__create_role()
{
credentials=`curl -s $OS_AUTH_URL/OS-KSADM/roles -X POST -H "X-Auth-Token:$1" -H "Content-type: application/json" -d "{\"role\": {\"name\": \"$2\"}}"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print 'error' in tok "`
if [ "$result" == "True" ]; then
result=""
else
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['role']['id'] "`
fi
set -e
echo $result
}
# Create role
__create_user()
{
credentials=`curl -s $OS_AUTH_URL/users -X POST -H "X-Auth-Token:$1" -H "Content-type: application/json" -d "{\"user\": {\"email\": null, \"password\": \"$4\", \"enabled\": true, \"name\": \"$2\", \"tenantId\": \"$3\"}}"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print 'error' in tok "`
if [ "$result" == "True" ]; then
result=""
else
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['user']['id'] "`
fi
set -e
echo $result
}
# Get the user Id
__get_user_id()
{
credentials=`curl -s $OS_AUTH_URL/users -H "X-Auth-Token:$1" -H "Content-type: application/json"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print [d for d in tok['users'] if d['name'] == '$2'][0]['id'] " 2> /dev/null`
set -e
echo $result
}
# Bind user to role with tenant
__bind_user_role_tenant()
{
credentials=`curl -s $OS_AUTH_URL/tenants/$4/users/$2/roles/OS-KSADM/$3 -X PUT -H "X-Auth-Token:$1" -H "Content-type: application/json"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print 'error' in tok "`
if [ "$result" == "True" ]; then
result=""
else
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['role']['id'] "`
fi
set -e
echo $result
}
__create_service()
{
credentials=`curl -s $OS_AUTH_URL/OS-KSADM/services -X POST -H "X-Auth-Token:$1" -H "Content-type: application/json" -d "{\"OS-KSADM:service\": {\"type\":\"$3\", \"name\": \"$2\", \"description\": \"$4\"}}"`
service_id=""
set +e
service_id=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print tok['OS-KSADM:service']['id'] "`
set -e
credentials=`curl -s $OS_AUTH_URL/endpoints -X POST -H "X-Auth-Token:$1" -H "Content-type: application/json" -d "{\"endpoint\": {\"adminurl\": \"$7\", \"service_id\": \"$service_id\", \"region\": \"$5\", \"internalurl\": \"$8\", \"publicurl\": \"$6\"}}"`
}
__get_service_id()
{
credentials=`curl -s $OS_AUTH_URL/OS-KSADM/services -H "X-Auth-Token:$1" -H "Content-type: application/json"`
result=""
set +e
result=`echo $credentials | python -c "import sys; import json; tok = json.loads(sys.stdin.read()); print [d for d in tok['OS-KSADM:services'] if d['name'] == '$2'][0]['id'] " 2> /dev/null`
set -e
echo $result
}
__configure_portal_keystone(){
ROLE_PORTAL_ADMIN=`__get_role_id $auth_token ROLE_PORTAL_ADMIN`
ROLE_PORTAL_USER=`__get_role_id $auth_token ROLE_PORTAL_USER`
if [ ! -z "${ROLE_PORTAL_ADMIN}" ]; then
echo "ROLE_PORTAL_ADMIN ID: $ROLE_PORTAL_ADMIN"
else
echo "ROLE_PORTAL_ADMIN role does not exists. Creating."
ROLE_PORTAL_ADMIN=`__create_role $auth_token ROLE_PORTAL_ADMIN`
echo "ROLE_PORTAL_ADMIN ID: $ROLE_PORTAL_ADMIN"
fi
if [ ! -z "${ROLE_PORTAL_USER}" ]; then
echo "ROLE_PORTAL_USER ID: $ROLE_PORTAL_USER"
else
echo "ROLE_PORTAL_USER role does not exists. Creating."
ROLE_PORTAL_USER=`__create_role $auth_token ROLE_PORTAL_USER`
echo "ROLE_PORTAL_USER ID: $ROLE_PORTAL_USER"
fi
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_PORTAL_ADMIN $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_PORTAL_USER $ADMIN_TENANT_ID`
}
__configure_chargeback_keystone(){
ROLE_ACCOUNTING=`__get_role_id $auth_token ROLE_ACCOUNTING`
ROLE_ACTIVITY=`__get_role_id $auth_token ROLE_ACTIVITY`
ROLE_ACTIVITY_ADMIN=`__get_role_id $auth_token ROLE_ACTIVITY_ADMIN`
ROLE_CHARGEBACK=`__get_role_id $auth_token ROLE_CHARGEBACK`
ROLE_CHARGEBACK_ADMIN=`__get_role_id $auth_token ROLE_CHARGEBACK_ADMIN`
if [ ! -z "${ROLE_ADMIN}" ]; then
echo "ROLE_ADMIN_ID: $ROLE_ADMIN"
else
echo "admin role does not exists. There is something wrong in your OpenStack installation."
exit 1
fi
if [ ! -z "${ROLE_ACCOUNTING}" ]; then
echo "ROLE_ACCOUNTING ID: $ROLE_ACCOUNTING"
else
echo "ROLE_ACCOUNTING role does not exists. Creating."
ROLE_ACCOUNTING=`__create_role $auth_token ROLE_ACCOUNTING`
echo "ROLE_ACCOUNTING ID: $ROLE_ACCOUNTING"
fi
if [ ! -z "${ROLE_ACTIVITY}" ]; then
echo "ROLE_ACTIVITY ID: $ROLE_ACTIVITY"
else
echo "ROLE_ACTIVITY role does not exists. Creating."
ROLE_ACTIVITY=`__create_role $auth_token ROLE_ACTIVITY`
echo "ROLE_ACTIVITY ID: $ROLE_ACTIVITY"
fi
if [ ! -z "${ROLE_ACTIVITY_ADMIN}" ]; then
echo "ROLE_ACTIVITY ID: $ROLE_ACTIVITY_ADMIN"
else
echo "ROLE_ACTIVITY_ADMIN role does not exists. Creating."
ROLE_ACTIVITY_ADMIN=`__create_role $auth_token ROLE_ACTIVITY_ADMIN`
echo "ROLE_ACTIVITY_ADMIN ID: $ROLE_ACTIVITY_ADMIN"
fi
if [ ! -z "${ROLE_CHARGEBACK}" ]; then
echo "ROLE_CHARGEBACK ID: $ROLE_CHARGEBACK"
else
echo "ROLE_CHARGEBACK role does not exists. Creating."
ROLE_CHARGEBACK=`__create_role $auth_token ROLE_CHARGEBACK`
echo "ROLE_CHARGEBACK ID: $ROLE_CHARGEBACK"
fi
if [ ! -z "${ROLE_CHARGEBACK_ADMIN}" ]; then
echo "ROLE_CHARGEBACK ID: $ROLE_CHARGEBACK_ADMIN"
else
echo "ROLE_CHARGEBACK_ADMIN role does not exists. Creating."
ROLE_CHARGEBACK_ADMIN=`__create_role $auth_token ROLE_CHARGEBACK_ADMIN`
echo "ROLE_CHARGEBACK_ADMIN ID: $ROLE_CHARGEBACK_ADMIN"
fi
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_PORTAL_ADMIN $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_PORTAL_USER $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_ACCOUNTING $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_ACTIVITY $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_ACTIVITY_ADMIN $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_CHARGEBACK $ADMIN_TENANT_ID`
OK=`__bind_user_role_tenant $auth_token $USER_ADMIN_ID $ROLE_CHARGEBACK_ADMIN $ADMIN_TENANT_ID`
OK=`__get_service_id $auth_token "activity"`
if [ "${OK}" != "" ]; then
echo "Activity service already exists."
else
__create_service $auth_token activity activity "activity" $KEYSTONE_DEFAULT_REGION $ACTIVITY_INTERNAL_URL "" $ACTIVITY_PUBLIC_URL
echo "Activity service created."
fi
OK=`__get_service_id $auth_token "accounting"`
if [ "${OK}" != "" ]; then
echo "Accounting service already exists."
else
__create_service $auth_token accounting accounting "accounting" $KEYSTONE_DEFAULT_REGION $ACTIVITY_INTERNAL_URL "" $ACTIVITY_PUBLIC_URL
echo "Accounting service created."
fi
OK=`__get_service_id $auth_token "chargeback"`
if [ "${OK}" != "" ]; then
echo "Chargeback service already exists."
else
__create_service $auth_token chargeback chargeback "chargeback" $KEYSTONE_DEFAULT_REGION $CHARGEBACK_INTERNAL_URL "" $CHARGEBACK_PUBLIC_URL
echo "Chargeback service created."
fi
SERVICE_TENANT_ID=`__get_tenant_id $auth_token service`
if [ "${SERVICE_TENANT_ID}" != "" ]; then
echo "'service' tenant exists. Everything is ok."
else
echo "'service' tenant does not exists. There is something wrong in your OpenStack installation. Exiting."
exit 1
fi
USER_CHARGEBACK_ID=`__get_user_id $auth_token chargeback`
if [ "${USER_CHARGEBACK_ID}" != "" ]; then
echo "'chargeback' already exists."
else
USER_CHARGEBACK_ID=`__create_user $auth_token chargeback $SERVICE_TENANT_ID ${ChargebackKeystonePassword}`
echo "'chargeback' user created."
fi
OK=`__bind_user_role_tenant $auth_token $USER_CHARGEBACK_ID $ROLE_ADMIN $SERVICE_TENANT_ID`
}
__check_keystone(){
echo "GLOBAL OPENSTACK PARAMETERS"
echo "==========================="
echo "All StackOps componentes follows the design guidelines of an OpenStack architecture. Please enter below the Public and Admin Authentication URLs of your OpenStack platform. You also need to provide the Authentication Admin token. The installer also needs an admin user with credentials to check the correct configuration of the roles for our components."
exitloop="none"
while [ "$exitloop" == "none" ]
do
echo -n "Enter the authentication admin url [$OS_AUTH_URL]: "
read response
if [ -n "$response" ]; then
OS_AUTH_URL=$response
fi
echo "Enter the authentication url [${KeystoneUrl}]: "
read response
if [ -n "$response" ]; then
KeystoneUrl=$response
fi
echo "Enter the authentication admin token [$OS_AUTH_TOKEN]: "
read response
if [ -n "$response" ]; then
OS_AUTH_TOKEN=$response
fi
echo "Enter the username with admin privileges [$OS_USERNAME]: "
read response
if [ -n "$response" ]; then
OS_USERNAME=$response
fi
echo -n "Enter the tenant [$OS_TENANT_NAME]: "
read response
if [ -n "$response" ]; then
OS_TENANT_NAME=$response
fi
exitloop=1
done
exitloop=0
while [ $exitloop -eq 0 ];
do
echo -n "Enter the password: "
read response
if [ -n "$response" ]; then
OS_PASSWORD=$response
exitloop=1
else
echo "Password cannot be empty. Repeat. "
fi
done
echo "GLOBAL MYSQL PARAMETERS"
echo "======================="
echo "The StackOps componentes use MySQL as the default persistent database. You need to provide the root password of your database installation, no matter if you are using an existing database server. If you are using an existing database server the installer will ask for the host and port."
if [ "${InstallMySql}" != "true" ]; then
echo "Enter the MySQL Host [${MySqlHost}]: "
read response
if [ -n "$response" ]; then
MySqlHost=$response
fi
echo "Enter the MySQL Port [${MySqlPort}]: "
read response
if [ -n "$response" ]; then
MySqlPort=$response
fi
fi
echo "Enter the MySQL ROOT password [$MYSQL_ROOT_PASSWORD]: "
read response
if [ -n "$response" ]; then
MYSQL_ROOT_PASSWORD=$response
fi
if [ "${InstallPortal}" = "true" ]; then
echo "STACKOPS PORTAL PARAMETERS"
echo "=========================="
echo "StackOps Portal needs the username, password and the name of the schema. Please enter the information below:"
echo "Enter the Portal MySQL user [${PortalMySqlUsr}]: "
read response
if [ -n "$response" ]; then
PortalMySqlUsr=$response
fi
echo "Enter the Portal MySQL password [${PortalMySqlPassword}]: "
read response
if [ -n "$response" ]; then
PortalMySqlPassword=$response
fi
echo "Enter the Portal MySQL Database Schema [${PortalMySqlSchema}]: "
read response
if [ -n "$response" ]; then
PortalMySqlSchema=$response
fi
fi
if [ "${InstallChargeback}" = "true" ]; then
echo "STACKOPS CHARGEBACK PARAMETERS"
echo "=========================="
echo "StackOps Chargeback needs an schema for data logging and another for rating processing. The install will ask for both username, password and the name of the schema. The installer will ask for the AQMP host and port plus the username and password. Finally, you need to enter the username and password of the account created for the component in keystone. Please enter the information below:"
echo "Enter the Activity MySQL user [${ActivityMySqlUsr}]: "
read response
if [ -n "$response" ]; then
ActivityMySqlUsr=$response
fi
echo "Enter the Activity MySQL password [${ActivityMySqlPassword}]: "
read response
if [ -n "$response" ]; then
ActivityMySqlPassword=$response
fi
echo "Enter the Activity MySQL Database Schema [${ActivityMySqlSchema}]: "
read response
if [ -n "$response" ]; then
ActivityMySqlSchema=$response
fi
echo "Enter the Chargeback MySQL user [${ChargebackMySqlUsr}]: "
read response
if [ -n "$response" ]; then
ChargebackMySqlUsr=$response
fi
echo "Enter the Chargeback MySQL password [${ChargebackMySqlPassword}]: "
read response
if [ -n "$response" ]; then
ChargebackMySqlPassword=$response
fi
echo "Enter the Chargeback MySQL Database Schema [${ChargebackMySqlSchema}]: "
read response
if [ -n "$response" ]; then
ChargebackMySqlSchema=$response
fi
echo "Enter the Chargeback Keystone user [${ChargebackKeystoneUsr}]: "
read response
if [ -n "$response" ]; then
ChargebacKeystoneUsr=$response
fi
echo "Enter the Chargeback Keystone password [${ChargebackKeystonePassword}]: "
read response
if [ -n "$response" ]; then
ChargebackKeystonePassword=$response
fi
echo "Enter the AQMP Host [${RABBITMQ_HOST}]: "
read response
if [ -n "$response" ]; then
RABBITMQ_HOST=$response
fi
echo "Enter the AQMP Port [${RABBITMQ_PORT}]: "
read response
if [ -n "$response" ]; then
RABBITMQ_PORT=$response
fi
echo "Enter the AQMP username [$RABBITMQ_USR]: "
read response
if [ -n "$response" ]; then
RABBITMQ_USR=$response
fi
echo "Enter the AQMP password [$RABBITMQ_PASSWORD]: "
read response
if [ -n "$response" ]; then
RABBITMQ_PASSWORD=$response
fi
fi
auth_token=`__get_auth_token`
#is_portal_admin=`__is_portal_admin $auth_token`
#is_chargeback_roles=`__is_chargeback_roles $auth_token`
ROLE_ADMIN=`__get_role_id $auth_token admin`
USER_ADMIN_ID=`__get_user_id $auth_token admin`
ADMIN_TENANT_ID=`__get_tenant_id $auth_token admin`
if [ ! -z "${ROLE_ADMIN}" ]; then
echo "ROLE_ADMIN_ID: $ROLE_ADMIN"
else
echo "admin role does not exists. There is something wrong in your OpenStack installation."
exit 1
fi
if [ "${InstallPortal}" = "true" ]; then
__configure_portal_keystone
fi
if [ "${InstallChargeback}" = "true" ]; then
__configure_chargeback_keystone
fi
#echo $OS_USERNAME
#echo $OS_PASSWORD
#echo $OS_TENANT_NAME
#echo $OS_AUTH_URL
#echo $auth_token
#echo $is_portal_admin
}
__check_keystone
__check_mysql(){
exitloop=0
while [ $exitloop -eq 0 ];
do
echo -n "Enter the ROOT password of your MySQL installation. Empty is not allowed: "
read response
if [ -n "$response" ]; then
MYSQL_ROOT_PASSWORD=$response
exitloop=1
else
echo "Password cannot be empty. Repeat. "
fi
done
echo " * MySQL ROOT information:"
echo " Password: ${MYSQL_ROOT_PASSWORD}"
echo " * In the post install process the installer will ask you about the connection details to MySQL"
}