-
Notifications
You must be signed in to change notification settings - Fork 19
/
install_prerequisites.py
executable file
·114 lines (101 loc) · 4.94 KB
/
install_prerequisites.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
#!/usr/bin/env python
from __future__ import print_function
import build
import errno
import logging
import optparse
import os
import platform
import sys
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else:
raise
def install_rvm_and_ruby():
cmd = 'gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB'
build.run_cmd(cmd, unsafe_shell=True,check_rc='gpg keys not received')
cmd = 'curl -sSL https://get.rvm.io | bash -s stable'
build.run_cmd(cmd, unsafe_shell=True, check_rc='curl failed')
cmd = 'rvm reload && rvm requirements run && rvm install 2.6'
build.run_cmd(cmd, unsafe_shell=True, run_env=True, check_rc='rvm ruby install failed')
def install_fpm_gem():
build.set_ruby_path()
cmd = 'rvm reload && rvm use 2.6 && gem install -v 1.4.0 fpm'
build.run_cmd(cmd, unsafe_shell=True, run_env=True, check_rc='fpm gem install failed')
def main():
# configure parser
parser = optparse.OptionParser()
parser.add_option('-v', '--verbose', action="count", dest='verbosity', default=1, help='print more information to stdout')
parser.add_option('-q', '--quiet', action='store_const', const=0, dest='verbosity', help='print less information to stdout')
(options, args) = parser.parse_args()
# configure logging
log = logging.getLogger()
if options.verbosity >= 2:
log.setLevel(logging.DEBUG)
elif options.verbosity == 1:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.WARNING)
ch = logging.StreamHandler()
formatter = logging.Formatter("%(levelname)s - %(message)s")
ch.setFormatter(formatter)
log.addHandler(ch)
pld = platform.linux_distribution()[0]
if pld in ['debian', 'Ubuntu']:
log.info('Detected: {0}'.format(pld))
cmd = ['sudo', 'apt-get', 'update', '-y']
build.run_cmd(cmd, check_rc='getting updates failed')
# get prerequisites
cmd = ['sudo','apt-get','install','-y','automake','make','autoconf2.13','texinfo',
'help2man','g++','git','lsb-release','libtool','python-dev','libbz2-dev','zlib1g-dev',
'libcurl4-gnutls-dev','libxml2-dev','pkg-config','uuid-dev','libssl-dev','libfuse-dev']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
# if new, get autoconf
if pld in ['Ubuntu'] and platform.linux_distribution()[1] > '16':
log.info('Detected: Ubuntu 16+ - need to get autoconf')
cmd = ['sudo','apt-get','install','-y','autoconf']
build.run_cmd(cmd, check_rc='installing autoconf failed')
elif pld in ['CentOS', 'CentOS Linux', 'Red Hat Enterprise Linux Server', 'Scientific Linux']:
log.info('Detected: {0}'.format(pld))
# prep
cmd = ['sudo', 'rpm', '--rebuilddb']
build.run_cmd(cmd, check_rc='rpm rebuild failed')
cmd = ['sudo','yum','clean','all']
build.run_cmd(cmd, check_rc='yum clean failed')
cmd = ['sudo','yum','install','centos-release-scl-rh', '-y']
build.run_cmd(cmd, check_rc='yum install failed')
cmd = ['sudo','yum','update','-y','glibc*','yum*','rpm*','python*']
build.run_cmd(cmd, check_rc='yum update failed')
# get prerequisites
cmd = ['sudo','yum','install','-y','epel-release','wget','openssl','ca-certificates']
build.run_cmd(cmd, check_rc='installing epel failed')
cmd = ['sudo','yum','install','-y','gcc-c++','git','autoconf','automake','texinfo',
'help2man','rpm-build','fuse','fuse-devel','python-devel','zlib-devel',
'bzip2-devel','libcurl-devel','libxml2-devel','libtool','libuuid-devel','openssl-devel']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
elif pld in ['openSUSE ', 'SUSE Linux Enterprise Server']:
log.info('Detected: {0}'.format(pld))
# get prerequisites
cmd = ['sudo','zypper','install','-y','ruby-devel','makeinfo','rubygems','libopenssl-devel',
'help2man','python-devel','libbz2-devel','libcurl-devel','libxml2-devel','uuid-devel']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
else:
if platform.mac_ver()[0] != '':
log.info('Detected: {0}'.format(platform.mac_ver()[0]))
# get prerequisites
cmd = ['brew','install','git','help2man','texinfo','libtool']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
cmd = ['brew','link','texinfo','--force']
build.run_cmd(cmd, check_rc='linking texinfo failed')
else:
log.error('Cannot determine prerequisites for platform [{0}]'.format(pld))
return 1
# get necessary ruby gems
install_rvm_and_ruby()
install_fpm_gem()
if __name__ == '__main__':
sys.exit(main())