-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
executable file
·1832 lines (1418 loc) · 78.4 KB
/
install.py
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
#!/usr/bin/python
import os, os.path, sys
import re
import pdb
import fnmatch
import errno
import types
import urllib2
import string
# make sure they have a proper version of python
if sys.version_info[:3] < (2, 4, 3):
print "Error: Must use Python 2.4.3 or greater for this script"
sys.exit(1)
# ------------------------------------------------------------------------------
# Custom Imports
# ------------------------------------------------------------------------------
try:
sys.path.append('./src/install')
from packages import *
from objects import *
from common import *
except ImportError:
print 'ImportError: Source files not found or invalid.\n' \
'Your tarball may have been damaged.\n' \
'Please contact %s for support' % SUPPORT_EMAIL
sys.exit(1)
# ------------------------------------------------------------------------------
# Settings
# ------------------------------------------------------------------------------
THIRDPARTY_REVISION = ".0"
if determine_bit() == 64:
ArchName = '.x86_64'
else:
ArchName = '.x86_32'
PRE_INSTALL_PKG_NAME = 'preinstall_CentOs_6'+ ArchName
PRE_INSTALL_PKG = PRE_INSTALL_PKG_NAME + '.tar.gz'
PSP_NAME_STARTS_WITH = 'openclovis-safplus-psp' # Look for PKG starting with this name
PSPPKG_DEFAULT = 'openclovis-safplus-psp-6.1-private.tar.gz' # search this package if no 3rdPartyPkg found
SUPPORT_EMAIL = '[email protected]' # email for script maintainer
INSTALL_LOCKFILE = '/tmp/.openclovis_installer' # installer lockfile location
colgreen = """\033[38;5;40m"""
colblue = """\033[38;5;27m"""
colreset = """\033[39m"""
OpenClovisStr = "%sOpen%sClovis%s" % (colgreen,colblue,colreset)
class myTs(string.Template):
delimiter = "%"
def __init__(self,s):
string.Template.__init__(self,s)
def applyTemplate(infile,outfile,sub):
ins = open(infile,"r").read()
ts = myTs(ins)
f = open(outfile,"w")
f.write(ts.substitute(sub))
f.close
class ASPInstaller:
""" Installer for OpenClovis SAFplus Availabliity Scalability Platform """
def __init__(self):
# ------------------------------------------------------------------------------
# Construct local enviroment
# ------------------------------------------------------------------------------
self.NO_INTERACTION = False
self.DEBUG_ENABLED = False
self.CUSTOM_OPENHPI = False
self.CUSTOM_OPENHPI_PKG = None
self.ASP_VERSION = None
self.ASP_REVISION = None
self.INSTALL_DIR = None
self.OS = None
self.WORKING_DIR = syscall('pwd')
self.preinstallQueue = [] # list of preinstall deps
self.installQueue = [] # list of deps to indicate what needs installing
self.locks_out = [] # list of all locks outstanding
self.THIRDPARTY_NAME_STARTS_WITH = '' #third party package name
self.THIRDPARTYPKG_DEFAULT = '' #third party default package name
#self.THIRDPARTYPKG_PATH = ''
#self.PREFIX = ''
#self.BUILDTOOLS = ''
#self.INSTALL_DIR = None
self.PREINSTALL_ONLY = False
self.INSTALL_ONLY = False
self.STANDARD_ONLY = False
self.CUSTOM_ONLY = False
self.BUILD_DIR = os.path.join(self.WORKING_DIR, 'workspace')
self.LOG_DIR = os.path.join(self.WORKING_DIR, 'log')
self.PRE_INSTALL_PKG = os.path.join(os.path.dirname(self.WORKING_DIR),PRE_INSTALL_PKG_NAME)
if determine_bit() == 64:
self.PRE_INSTALL_PKG = os.path.join(os.path.dirname(self.WORKING_DIR),PRE_INSTALL_PKG_NAME)
#self.PREFIX_BIN = ''
self.DEV_BUILD = False
self.INSTALL_IDE = True
self.GPL = False
self.DO_PREBUILD = True
self.DO_SYMLINKS = True
self.HOME = self.expand_path('~')
self.OFFLINE = False
self.INTERNET = True
self.WITH_CM_BUILD = False
# ------------------------------------------------------------------------------
self.NEED_TIPC_CONFIG = False
self.TIPC_CONFIG_VERSION = ''
# ------------------------------------------------------------------------------
self.GENERAL_LOG_PATH = os.path.join(self.LOG_DIR, 'general.log')
self.OS = determine_os()
self.nuke_dir(self.LOG_DIR) # clean and make log directory
self.create_dir(self.LOG_DIR)
self.debug('Determined OS to be: %s, %d-bit' % (self.OS.name, self.OS.bit))
if (sys.argv[0].count('/') >= 2 or len(sys.argv[0]) > len('./install.py')):
self.feedback('Error: Please invoke this sript from its own directory as "./install.py"', True)
# look in our VERSION file to get ASP_VERSION and ASP_REVISION
try:
fh = open('VERSION', 'r')
fdata = fh.readlines()
fh.close()
self.ASP_VERSION = fdata[1].split('=')[1].strip()
self.ASP_REVISION = fdata[3].split('=')[1].strip()
if not self.ASP_VERSION or not self.ASP_REVISION:
raise Exception # Invalid VERSION file format
if self.ASP_REVISION == 'dev':
# we have a development install
self.debug('Development install detected')
self.DEV_BUILD = True
except:
msg = 'Error: \'%s\' file not found or invalid.\n' \
'Your tarball may have been damaged.\n' \
'Please contact %s for support' % (os.path.join(self.WORKING_DIR, 'VERSION'), SUPPORT_EMAIL)
self.feedback(msg, True, False)
# set the thirdparty-package name
self.THIRDPARTY_NAME_STARTS_WITH = '3rdparty-base-'+ self.ASP_VERSION + THIRDPARTY_REVISION + ArchName
self.THIRDPARTYPKG_DEFAULT = '3rdparty-base-'+ self.ASP_VERSION + THIRDPARTY_REVISION + ArchName + '.tar'
# set some flags that may have been passed from command line
self.parse_cl_options()
# make sure os is supported
if not self.DEBUG_ENABLED and (not self.OS or not self.OS.supported):
msg = 'Error: This OS is not supported by this script\n' \
'Please contact %s for support' % SUPPORT_EMAIL
self.feedback(msg, True, False)
if self.DEBUG_ENABLED:
self.nuke_dir(self.BUILD_DIR) # clean old builds only for debugging (otherwise lets keep them to save time if error)
def __del__(self):
# if we are dieing we want to silenty try to remove our lock
self.remove_lock(INSTALL_LOCKFILE)
def parse_cl_options(self):
if '-h' in sys.argv or '--help' in sys.argv:
self.usage()
sys.exit(0)
if '--no-interaction' in sys.argv:
sys.argv.remove('--no-interaction')
self.NO_INTERACTION = True
# check for debug flag
if '--debug' in sys.argv:
sys.argv.remove('--debug')
self.DEBUG_ENABLED = True
if '--custom' in sys.argv:
sys.argv.remove('--custom')
self.CUSTOM_ONLY = True
if '--preinstall' in sys.argv:
if os.getuid() != 0:
self.feedback('\nYou must be root to run the preinstall phase', True)
sys.argv.remove('--preinstall')
self.PREINSTALL_ONLY = True
if '--offline' in sys.argv:
if os.getuid() != 0:
self.feedback('\nYou must be root to run the preinstall phase', True)
sys.argv.remove('--offline')
#self.PREINSTALL_ONLY = True
self.OFFLINE = True
self.INTERNET = False
if '--install' in sys.argv:
sys.argv.remove('--install')
self.INSTALL_ONLY = True
if '--standard' in sys.argv:
sys.argv.remove('--standard')
self.STANDARD_ONLY = True
#if '--nonet' in sys.argv:
#sys.argv.remove('--nonet')
#self.INTERNET = False
#self.OFFLINE = True
if '--install-dir' in sys.argv:
idx = sys.argv.index('--install-dir')
try:
# trailing slash is added
self.INSTALL_DIR = self.expand_path(sys.argv[idx+1])
self.debug('self.INSTALL_DIR set to: %s' % self.INSTALL_DIR)
if not '/' in self.INSTALL_DIR:
raise IndexError
sys.argv.pop(idx+1) # remove these args
sys.argv.pop(idx)
except IndexError:
self.feedback('Error: Invalid options sent to installer\n --install-dir must be followed by a valid path', True)
# make sure we have trailing slash for consistency
assert self.INSTALL_DIR[-1] == '/'
if len(sys.argv) > 1:
self.print_install_header()
self.feedback('Warning: Unrecognized options sent to installer')
for arg in sys.argv[1:]:
print '\t' + arg.strip()
if self.NO_INTERACTION == False:
self.feedback('Please press <enter> to continue or <ctrl-c> to quit this installer')
self.get_user_feedback()
def queuePreinstall(self):
""" Prepare preinstall phase mimicking old preinstall-*.sh scripts """
assert self.OS, "Error: Script OS failure"
self.debug('queuePreinstall()')
# check for root user (must be root for preinstall)
if os.getuid() != 0:
self.feedback('\nYou must be root to run the preinstall phase', True)
# append all pre deps to be installed
self.preinstallQueue.extend(self.OS.pre_dep_list)
assert self.OS.pre_dep_list
assert len(self.OS.pre_dep_list) > 0
if len(self.preinstallQueue) == 0 or not self.OS.pre_dep_list:
self.feedback('This feature has not yet been fully implemented', True) # fixme
def grab_workspace_logs(self):
""" does a find workspace/ -name '*.log' and
copies all found logs into our log directory """
cmd = "find %s -type f -name '*.log' 2>/dev/null" % os.path.join(self.WORKING_DIR, 'workspace')
files = syscall(cmd)
# workaround as to syscall returning different types
# convert files to list if not
if type(files) == type('string'):
files = [files]
for filepath in files:
farr = filepath.split('workspace/')
# ex workspace/openhpi-2.14.0/build/config.log => openhpi-2.14.0-config.log
# ex workspace/glib-2.12.6/config.log => glib-2.12.6-config.log
try:
new_name = farr[1].replace('/build/', '-').replace('/', '-')
except:
# something went horribly wrong
self.debug('Something went horribly wrong with grab_workspace_logs()')
#if self.DEBUG_ENABLED:
# assert 0, 'fixme'
new_path = os.path.join(self.LOG_DIR, new_name)
copy_cmd = 'cp "%s" "%s"' % (filepath.rstrip(), new_path.rstrip())
#print copy_cmd
syscall(copy_cmd)
def tar_log_directory(self):
cmd = 'cd %s; rm -f installer-logs.tgz; tar cfz installer-logs.tgz log/ 2>/dev/null;' % self.WORKING_DIR
syscall(cmd)
self.feedback('Created tarball "installer-logs.tgz" located in "%s"' % self.WORKING_DIR)
self.feedback('Please upload this tarball to %s for help with this issue' % SUPPORT_EMAIL)
def usage(self):
msg = '\ninstall.py - Installation tool for %s SAFplus %s\n\n' \
'Installs %s SAFplus %s to a system intended for use\n' \
'for %s SAFplus development.\n\n' \
'Usage:\n' \
' %s [ --help ] # Prints this information\n' \
' %s [ --preinstall ] # Sets the script to run the preinstall phase only\n' \
' %s [ --install ] # Sets the script to run the install phase only\n' \
' %s [ --standard ] # Sets the script to do a standard install (both phases)\n' \
' %s [ --custom ] # Sets the script to do a custom install (ask user everything, Default)\n' \
' %s [ --install-dir /opt/clovis ] # Sets the install directory (Default: /opt/clovis)\n' \
' %s [ --no-interaction ] # Sets the script to run with default options & no user interaction\n' \
% (OpenClovisStr, self.ASP_VERSION, OpenClovisStr, self.ASP_VERSION, OpenClovisStr, sys.argv[0],sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0])
# ' %s [ -p <openhpi-package-tarball> ] # Allows use of specified OpenHPI package\n' \
self.feedback(msg, False)
def queueInstall(self):
# ------------------------------------------------------------------------------
# Determine which packages this user needs
# ------------------------------------------------------------------------------
# for each dep this OS requires,
for dep in self.OS.dep_list:
if self.DEBUG_ENABLED:
assert dep.pkg_name, "Error: Dependency is missing pkg_name"
assert dep.version, "Error: Dependency is missing version"
assert dep.name, "Error: Dependency is missing name"
assert dep.build_cmds, "Error: Dependency is missing build_cmds"
if dep.force_install:
self.installQueue.append(dep)
continue
# do we need to install this?
if dep.ver_test_cmd:
if '${' in dep.ver_test_cmd:
assert self.PREFIX
dep.ver_test_cmd = dep.ver_test_cmd.replace('${PREFIX}', self.PREFIX)
dep.installedver = syscall(dep.ver_test_cmd)
if not dep.installedver:
dep.installedver = 'None'
assert type(dep.installedver) == type('string'), dep.installedver
if self.version_compare(dep.version, dep.installedver):
# if so, add it to list to be installed
self.installQueue.append(dep)
else:
# special cases, no ver_test_cmd!
dep.installedver = 'N/A'
if dep.name == 'openhpi-subagent':
# openhpi-subagent ONLY gets installed if
# either openhpi or netsnmp will be installed
if os.path.isfile('/usr/local/bin/hpiSubagent') or os.path.isfile('/usr/bin/hpiSubagent') or os.path.isfile('%s/hpiSubagent' % self.PREFIX_BIN):
# already installed somewhere
# do we need reinstallation?
for qdep in self.installQueue:
if qdep.name in ('net-snmp', 'openhpi'):
# if not os.path.isfile('/usr/lib/libelf.so'):
# cmd = 'ln -fs /usr/lib/libelf.so.1 /usr/lib/libelf.so'
# self.debug('calling cmd: ' + cmd)
# ret_code = cli_cmd(cmd)
self.installQueue.append(dep)
continue
else:
#do install
self.installQueue.append(dep)
continue
# SPECIAL CASE, TIPC
elif dep.name == 'tipc':
self.feedback('Install tipc module')
cmd = '/sbin/modinfo tipc > /dev/null 2>&1;'
self.debug('calling cmd: ' + cmd)
ret_code = cli_cmd(cmd)
if ret_code == 1:
# self.feedback('retcode = %s' %ret_code)
#wrong cmd
#if int(syscall('uname -r').split('.')[2]) < 15:
if int((syscall('uname -r').split('.')[2]).split('-')[0]) < 15:
# do install
dep.installedver = 'None'
self.installQueue.append(dep)
else :
if(self.INTERNET == False) :
os.chdir(self.PRE_INSTALL_PKG)
syscall('cp -f tipc.ko /lib/modules/`uname -r`/extra/')
syscall('cp -f tipc.conf /etc/modprobe.d/')
syscall('modprobe tipc')
syscall('depmod -a')
cmd = '/sbin/modinfo tipc > /dev/null 2>&1;'
self.debug('calling cmd: ' + cmd)
test_tipc = cli_cmd(cmd)
if test_tipc == 1 :
self.feedback('Error: cannot install tipc. Please install tipc manually.', True)
else :
self.feedback('Install tipc successfully.')
syscall('cp -f %s/%s/tipc_config.h /usr/include/linux/' %((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
syscall('cp -f %s/%s/tipc.h /usr/include/linux/' %((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
syscall('rm -rf %s/%s'%((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
else :
dep.installedver = 'None'
self.installQueue.append(dep)
self.NEED_TIPC_CONFIG = True
else: #ret_code == 0
#assert ret_code == 0
# self.feedback('retcode = %s' %ret_code)
self.NEED_TIPC_CONFIG = True
dep.installedver = syscall('/sbin/modinfo tipc | grep \'^version\' | tr -s " " | cut -d\ -f 2') # fixme, does this work
elif dep.name == 'tipc-config' and self.NEED_TIPC_CONFIG:
cmd = 'which tipc-config 2>/dev/null'
self.debug('calling cmd: ' + cmd)
ret_code = cli_cmd(cmd)
if ret_code != 0:
# install tipc_config
TIPC_MODULE_VERSION = syscall('/sbin/modinfo tipc | grep \'^version\' | tr -s " " | cut -d\ -f 2')
TIPC_MAJOR_VERSION = int(TIPC_MODULE_VERSION.split('.')[0])
TIPC_MINOR_VERSION = int(TIPC_MODULE_VERSION.split('.')[1])
self.feedback('tipc major : %s - tipc minor : %s '%(TIPC_MAJOR_VERSION,TIPC_MINOR_VERSION))
if TIPC_MAJOR_VERSION != 1:
# install tipcutil 1.1.9
#dep.installedver = 'Warning: incompatible version, won\'t install'
self.TIPC_CONFIG_VERSION ='tipcutils-1.1.9.tar.gz'
dep.pkg_name = self.TIPC_CONFIG_VERSION
self.installQueue.append(dep)
continue
if TIPC_MINOR_VERSION == 5:
dep.installedver = 'Installed'
continue
elif TIPC_MINOR_VERSION == 6:
self.TIPC_CONFIG_VERSION = 'tipcutils-1.0.4.tar.gz'
dep.pkg_name = self.TIPC_CONFIG_VERSION
elif TIPC_MINOR_VERSION == 7:
self.TIPC_CONFIG_VERSION = 'tipcutils-1.1.9.tar.gz'
dep.pkg_name = self.TIPC_CONFIG_VERSION
self.feedback('Update new tipc library')
if self.INTERNET == False :
syscall('cp -f %s/%s/tipc_config.h /usr/include/linux/' %((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
syscall('cp -f %s/%s/tipc.h /usr/include/linux/' %((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
syscall('rm -rf %s/%s'%((os.path.dirname(self.WORKING_DIR)),PRE_INSTALL_PKG_NAME))
self.installQueue.append(dep)
continue
else: #ret_code non zero
# tipc config installed
dep.installedver = 'Installed'
continue
else:
# just add it to queue
self.installQueue.append(dep)
continue
#else:
continue
def expand_path(self, path):
assert self.WORKING_DIR
assert '/' in path or path == '~'
path = os.path.expanduser(path)
path = path.replace('./', self.WORKING_DIR + '/')
path = path.rstrip('/') + '/'
assert path[-1] == '/'
assert '/' in path
assert not '~' in path
return path
def launchGUI(self):
""" Prepare install phase mimicking old install.sh script """
assert self.OS, "Error: Script OS failure"
#KERNEL_VERSION = syscall('uname -r')
self.PACKAGE_NAME = 'sdk'
self.WORKING_ROOT = os.path.dirname(self.WORKING_DIR)
#PROCESSOR = syscall('uname -m')
#INET_ACCESS = syscall('ping -c1 -W1 google.com')
# Custom openhpi pkg?
#if '-p' in sys.argv:
#
# CUSTOM_OPENHPI = 1
#
# for i in range(len(sys.argv)):
# if sys.argv[i] == '-p':
# try:
# CUSTOM_OPENHPI_PKG = sys.argv[i+1].strip()
# break
# except:
# self.feedback('Error: Missing openhpi-package-tarball path. (-p option specified)', True)
#
# if not os.path.isfile(CUSTOM_OPENHPI_PKG):
# self.feedback('Error: Invalid custom openhpi-package-tarball path. Remove -p to use default.', True)
# ------------------------------------------------------------------------------
# Set install lock
# ------------------------------------------------------------------------------
success = self.get_lock(INSTALL_LOCKFILE)
if not success:
msg = 'Error: There is another %s install in progress\n' \
'This script cannot continue\n' \
'If you feel this is an error, please execute\n' \
' rm -f \'%s\'\n' \
'Contact %s for support' % (OpenClovisStr,INSTALL_LOCKFILE, SUPPORT_EMAIL)
self.feedback(msg, True)
# define some essential packages we most definitely need...
# fixme, maybe we should install these if they aren't found?
essentials = ('perl', 'md5sum')
fatal = False
for pkg in essentials:
success = syscall('which ' + pkg)
if not success:
self.feedback('\'%s\' missing and is necessary for installation' % pkg)
fatal = True
# if they were missing an essential package
if fatal:
msg = '\nError: Cannot find the above package(s) in your $PATH environment variable\n' \
' You may need to install the above or properly set your $PATH variable\n'
self.feedback(msg, True)
# ------------------------------------------------------------------------------
# Begin Interactive Installer
# ------------------------------------------------------------------------------
if not (self.PREINSTALL_ONLY or self.INSTALL_ONLY or self.STANDARD_ONLY):
self.print_install_header()
self.feedback('Welcome to the %s SAFplus %s Installer\n' % (OpenClovisStr, self.ASP_VERSION))
self.feedback('This program helps you to install:')
self.feedback(' - Required 3rd-party Packages')
self.feedback(' - The %s SAFplus Availability Scalability Platform\n' % OpenClovisStr)
self.feedback('Installation Directory Prerequisites')
self.feedback(' - At least 512MB free disk space')
self.feedback(' - Write permission to the installation directory\n')
self.feedback('Note: You may experience slow installation if the target installation')
self.feedback(' directory is mounted from a remote file system (e.g., NFS).\n')
if self.NO_INTERACTION == False:
self.feedback('Please press <enter> to continue or <ctrl-c> to quit this installer')
self.get_user_feedback()
# ------------------------------------------------------------------------------
# Selection of installation type
# ------------------------------------------------------------------------------
if not (self.STANDARD_ONLY or self.CUSTOM_ONLY):
# Show this picker unless they already specified
self.print_install_header()
self.feedback('Installation Type:\n')
self.feedback(' 1) Standard - Select all default options')
self.feedback(' 2) Custom - Recommended')
self.feedback(' 3) Preinstall Only - Only does the preinstall phase')
self.feedback(' 4) Install Only - Only does the install phase')
if self.NO_INTERACTION == True:
strin = '1'
else:
strin = self.get_user_feedback('\nPlease choose an installation option [default: 2]: ')
if strin == '1':
# default install (fast install)
# go_to_standard_install # fix
self.STANDARD_ONLY = True
self.debug('Standard Install Selected')
elif strin == '3':
self.PREINSTALL_ONLY = True
self.debug('Preinstall Only Selected')
elif strin == '4':
self.INSTALL_ONLY = True
self.debug('Install Only Selected')
else: # nothing or 2
# Custom install
self.CUSTOM_ONLY = True
self.debug('Custom Install Selected')
# ------------------------------------------------------------------------------
# Begin prompting for various installation options
# ------------------------------------------------------------------------------
# could be set via CL
if not self.INSTALL_DIR:
self.INSTALL_DIR = '/opt/clovis'
if self.DEBUG_ENABLED:
self.INSTALL_DIR = '/tmp/clovis'
else:
self.debug('self.INSTALL_DIR already set (via cl) to %s' % self.INSTALL_DIR)
if not (self.PREINSTALL_ONLY or self.STANDARD_ONLY):
self.print_install_header()
if self.NO_INTERACTION == True:
strin = INSTALL_DIR
else:
strin = self.get_user_feedback('Enter the installation root directory [default: %s]: ' % self.INSTALL_DIR)
if strin:
# they provided a path. expand '~' and './' references
self.INSTALL_DIR = self.expand_path(strin)
else:
# accept default
pass
if not os.access(self.WORKING_DIR, os.W_OK):
msg = ERROR_WPERMISSIONS % self.WORKING_DIR
msg += 'Copy the contents of this folder to a directory where you have write permission and try again.'
self.feedback(msg, True)
self.INSTALL_DIR = os.path.join(self.INSTALL_DIR,self.ASP_VERSION)
if not self.PREINSTALL_ONLY:
self.BUILDTOOLS = os.path.join(self.INSTALL_DIR, 'buildtools')
self.PACKAGE_ROOT = os.path.join(self.INSTALL_DIR, self.PACKAGE_NAME)
self.ASP_PREBUILD_DIR= os.path.join(self.PACKAGE_ROOT, 'prebuild')
self.PREFIX = os.path.join(self.BUILDTOOLS, 'local')
self.PREFIX_BIN = os.path.join(self.PREFIX, 'bin')
self.PREFIX_LIB = os.path.join(self.PREFIX, 'lib')
self.IDE_ROOT = os.path.join(self.INSTALL_DIR, 'IDE') # IDE is installed here
self.DOC_ROOT = os.path.join(self.PACKAGE_ROOT, 'doc') # DOCS are copied here
self.BIN_ROOT = os.path.join(self.PACKAGE_ROOT, 'bin') # scripts are copied here
self.LIB_ROOT = os.path.join(self.PACKAGE_ROOT, 'lib') # copy rc scripts in this directory
self.ASP_ROOT = os.path.join(self.PACKAGE_ROOT, 'src/SAFplus') # ASP sources are copied here
self.MODULES = os.path.join(self.PREFIX, 'modules')
self.ECLIPSE = os.path.join(self.IDE_ROOT, 'eclipse')
self.ESC_ECLIPSE_DIR = syscall("echo %s/eclipse | sed -e 's;/;\\\/;g'" % self.PACKAGE_ROOT)
# check for GPL
if self.INSTALL_IDE and os.path.isdir('src/IDE'):
self.GPL = True
# setup self.NET_SNMP_CONFIG
NET_CONFIG = os.path.join(self.PREFIX_BIN, 'net-snmp-config')
self.NET_SNMP_CONFIG = 'net-snmp-config'
if os.path.isdir(self.PREFIX) and os.path.isfile(NET_CONFIG):
self.NET_SNMP_CONFIG = NET_CONFIG
#self.CACHE_DIR = "${HOME}/.clovis/$PACKAGE_NAME"
self.CACHE_DIR = self.join_list_as_path([self.HOME, '.clovis', self.PACKAGE_NAME])
self.CACHE_FILE = "install.cache"
# make all these dirs
for DIR in (self.INSTALL_DIR, self.BUILDTOOLS, self.PACKAGE_ROOT, self.PREFIX, self.PREFIX_BIN, self.PREFIX_LIB, self.IDE_ROOT,
self.ASP_ROOT, self.DOC_ROOT, self.BIN_ROOT, self.LIB_ROOT, self.BUILD_DIR, self.MODULES,
self.CACHE_DIR, self.ECLIPSE):
# attempt to create each of these dirs
self.create_dir(DIR)
if not os.access(self.INSTALL_DIR, os.W_OK):
self.feedback(ERROR_WPERMISSIONS % self.INSTALL_DIR)
self.feedback(ERROR_CANT_CONTINUE, True)
# ------------------------------------------------------------------------------
# Preinstall Dependencies
# ------------------------------------------------------------------------------
if (self.CUSTOM_ONLY):
self.print_install_header()
self.queuePreinstall()
self.feedback('Here are the preinstall dependencies:\n')
depnames = []
for dep in self.preinstallQueue:
depnames.append(dep.name)
# this is used to sort our word list
# by length of word so that we can
# print the dep list in a nicer way
def bylength(word1, word2):
return len(word1) - len(word2)
depnames.sort(cmp=bylength)
#self.debug(str(depnames))
# this may look odd but it is simply
# printing the dep names in a nice way
while len(depnames):
print depnames[0],
depnames.pop(0) # O(n)
if len(depnames):
print ' ' + depnames[-1]
depnames.pop() # removes last item
print '\n\n',
cmd = 'apt-get install'
if self.OS.yum:
cmd = 'yum install'
self.feedback('These will be installed via the "%s" command. Some of these may already be installed.\n' % cmd)
if self.NO_INTERACTION == False:
self.feedback('Please press <enter> to continue or <ctrl-c> to quit this installer')
self.get_user_feedback()
elif self.PREINSTALL_ONLY or self.STANDARD_ONLY:
# standard needs a queue here
self.queuePreinstall()
if not self.INSTALL_ONLY:
self.doPreinstall()
# we may return here because we are done if preinstall only
if self.PREINSTALL_ONLY:
return
# ------------------------------------------------------------------------------
# Install Dependencies
# ------------------------------------------------------------------------------
try:
longest = len(self.OS.dep_list[0].name)
except IndexError:
msg = 'Error: OS dependency list empty.\n' \
'Your tarball may have been damaged.\n' \
'Please contact %s for support\n' % SUPPORT_EMAIL
self.feedback(msg, True)
self.queueInstall()
if (self.CUSTOM_ONLY):
self.print_install_header()
self.feedback('Here are the install dependencies for %s %d-bit:\n' % (self.OS.name, self.OS.bit))
for dep in self.OS.dep_list:
l = len(dep.name)
if l > longest:
longest = l
head = 'Module' + ' '*(8+longest-6) + 'Needed (Installed)'
self.feedback(head)
self.feedback('-'*len(head))
for dep in self.OS.dep_list:
if dep in self.installQueue:
self.feedback(dep.name + ' '*(8+longest - len(dep.name)) + dep.version + '*' + ' '*(10-len(dep.version)) + '(%s)' % dep.installedver.strip())
else:
self.feedback(dep.name + ' '*(8+longest - len(dep.name)) + dep.version + ' '*(10-len(dep.version)) + ' (%s)' % dep.installedver.strip())
self.feedback('\n(* needs install)')
if self.NO_INTERACTION == False:
self.feedback('\nPlease press <enter> to continue or <ctrl-c> to quit this installer')
self.get_user_feedback()
# ------------------------------------------------------------------------------
# 3rd party package validation
# ------------------------------------------------------------------------------
WORKING_ROOT = self.WORKING_ROOT
self.feedback('Working root set to [%s], package root at [%s]' %(WORKING_ROOT, self.PACKAGE_ROOT) )
os.chdir ('%s' % WORKING_ROOT)
ThirdPartyList = fnmatch.filter(os.listdir(WORKING_ROOT),"%s.*tar" %self.THIRDPARTY_NAME_STARTS_WITH)
self.feedback('List %s' %(ThirdPartyList))
Pkg_Found = 0 # a flag to check for 3rdPartyPkg presence
max_ver = 0
if len (ThirdPartyList) == 0:
thirdPartyPkg = self.THIRDPARTYPKG_DEFAULT
elif len (ThirdPartyList) == 1:
Pkg_Found = 1
thirdPartyPkg = ThirdPartyList[0]
else:
Pkg_Found = 1
for ThirdParty in ThirdPartyList:
sub_vers = re.sub("\D", "", re.sub (self.THIRDPARTY_NAME_STARTS_WITH, "", ThirdParty))
if sub_vers:
sub_vers = int (sub_vers)
if sub_vers > max_ver:
max_ver = sub_vers
thirdPartyPkg = ThirdParty
self.THIRDPARTYPKG_PATH = os.path.join(WORKING_ROOT, thirdPartyPkg)
THIRDPARTYMD5 = os.path.splitext(thirdPartyPkg)[0] + '.md5'
THIRDPARTYMD5_PATH = os.path.join(WORKING_ROOT, THIRDPARTYMD5)
# do they have the third party pkg tarball?
if not Pkg_Found:
if not self.INTERNET:
self.feedback('Error: Cannot find \'%s\' in directory \'%s\'\n' % (thirdPartyPkg, WORKING_ROOT),True)
self.print_install_header()
self.feedback('Error: Cannot find \'%s\' in directory \'%s\'\n' % (thirdPartyPkg, WORKING_ROOT))
THIRDPARTYPKG_FTPURL = os.path.join('ftp://ftp.openclovis.com/', thirdPartyPkg)
#THIRDPARTYMD5_FTPURL = os.path.join('ftp://ftp.openclovis.com/pub/release/', THIRDPARTYMD5)
#THIRDPARTYPKG_FTPURL = os.path.join("https://github.com/downloads/OpenClovis/SAFplus-Availability-Scalability-Platform/", thirdPartyPkg)
# attempt to download the package. Requires wget
cmd = ''
if syscall('which wget 2>/dev/null'):
cmd = 'wget -t 3 --no-check-certificate '
elif syscall('which curl 2>/dev/null'):
cmd = 'curl -OL '
if cmd:
if self.NO_INTERACTION == True:
strin = 'y'
else:
strin = self.get_user_feedback('Would you like to attempt download of this necessary package? <y|n> [y]: ')
if not strin or strin.lower().startswith('y'):
if not os.access(WORKING_ROOT, os.W_OK):
self.feedback(ERROR_WPERMISSIONS % WORKING_ROOT)
self.feedback('Error: Script could not continue', True)
try:
# cleanup inturrupted files
if os.path.exists(thirdPartyPkg):
os.remove(thirdPartyPkg)
syscall('%s "%s"' % (cmd, THIRDPARTYPKG_FTPURL))
syscall('mv "%s" "%s" 2>/dev/null' % (thirdPartyPkg, self.THIRDPARTYPKG_PATH))
except KeyboardInterrupt:
try:
# cleanup inturrupted files
os.remove(thirdPartyPkg)
os.remove(self.THIRDPARTYPKG_PATH)
except:
pass
self.feedback(WARNING_INCOMPLETE, True)
# did it download successfully?
if not os.path.exists(self.THIRDPARTYPKG_PATH):
msg = 'Error: You need %s to continue, script will now exit\n' \
' Please check \'%s\' for this necessary package,\n' \
' and place it in \'%s\'' % (thirdPartyPkg, THIRDPARTYPKG_FTPURL, WORKING_ROOT)
self.feedback(msg, True)
if not os.access(self.THIRDPARTYPKG_PATH, os.R_OK):
self.print_install_header()
msg = 'Error: Invalid permission (cannot read from) \'%s\'\n' \
'Please set the proper permissions so that this script may continue\n' % self.THIRDPARTYPKG_PATH
self.feedback(msg, True)
# should preform MD5 validation?
if os.path.exists(THIRDPARTYMD5_PATH):
self.feedback('Please wait, performing checksum validation...')
try:
# is there a better way to do this?
md5sum1 = syscall('md5sum ' + self.THIRDPARTYPKG_PATH).strip(' ')[0]
md5sum2 = syscall('cat ' + THIRDPARTYMD5_PATH).strip(' ')[0]
if md5sum1 == md5sum2:
self.debug('Checksum validation passed')
else:
raise Exception
except:
msg = 'Error: \'%s\' checksum validation failed.\n' % thirdPartyPkg
msg += 'Your tarball may have been damaged.\n'
msg += 'Please contact %s for support' % SUPPORT_EMAIL
self.feedback(msg, True)
else:
self.feedback('Warning: Unable to find \'%s\'. Proceeding without checksum validation...' % THIRDPARTYMD5_PATH)
# doInstallation
self.doInstallation()
def doPreinstall(self):
"""
After queueing up preinstall phase deps, this function is used to install them
Returns True on success
"""
if len(self.preinstallQueue) == 0:
self.debug('Warning: doPreinstall called with 0 items')
return
assert self.OS.apt != self.OS.yum, 'install script error: cannot use apt AND yum'
self.debug('doPreinstall() %d items to install' % len(self.preinstallQueue))
if self.OS.apt and not syscall('which apt-get'):
self.feedback('Error: Could not find apt-get, cannot continue.\n\tMay be a problem with $PATH', True)
elif self.OS.yum and not syscall('which yum'):
self.feedback('Error: Could not find yum, cannot continue.\n\tMay be a problem with $PATH', True)
self.feedback('Beginning preinstall phase... please wait. This may take up to 5 minutes.')
install_str = ''
install_lst = []
for dep in self.preinstallQueue:
if type(dep.name) == type(""): # A string means its a simple dependency
install_str += '%s ' % dep.name
else:
install_lst.append(dep) # This is a complex dependency that must be installed individually
if self.OS.apt:
if self.OFFLINE:
res = syscall ("dpkg -i -R preinstall")
print str (res)
# lets build a string in order to pass apt-get ALL our deps at once
# this is MUCH faster than doing them one at a time although errors
# are much harder to detect
else:
syscall('apt-get update;')
self.debug('Apt-Get Installing: ' + install_str)
(retval, result, signal, core) = system('apt-get -y --force-yes install %s' % install_str)
if "Could not get lock" in "".join(result):
self.feedback("Could not get the lock, is another package manager running?\n", fatal=True)
self.feedback('Successfully installed preinstall dependencies.')
else:
if self.INTERNET :
instCmd = 'yum -y install %s 2>&1'
cmd = instCmd % install_str
self.debug('Yum Installing: ' + cmd)
result = syscall(cmd)
self.debug(str(result))
#yum -y update kernel
for dep in install_lst:
if type(dep.name) is type([]): # Any one of these to successfully install is ok
for name in dep.name:
cmd = instCmd % name
self.debug('Yum Installing: ' + cmd)
result = syscall(cmd)
self.debug(str(result))
self.feedback('Successfully installed preinstall dependencies.')
else:
os.chdir ('%s' %(os.path.dirname(self.WORKING_DIR)))
syscall('tar zxf %s' % PRE_INSTALL_PKG)
self.feedback('install preinstall dependencies without internet')
os.chdir(self.PRE_INSTALL_PKG)
pre_Install_List = fnmatch.filter(os.listdir(self.PRE_INSTALL_PKG),"*.rpm")
self.feedback('There are %d items to install' % len(pre_Install_List))