forked from irods/externals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_prerequisites.py
executable file
·150 lines (135 loc) · 7.35 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
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
#!/usr/bin/env python
from __future__ import print_function
import build
import errno
import logging
import optparse
import os
import platform
import sys
RUBY_VERSION = build.ruby_requirements['ruby']
RVM_PATH = build.ruby_requirements['path']
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 = 'sudo gpg --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB'
build.run_cmd(cmd, unsafe_shell=True, check_rc='gpg keys not received', retries=10)
cmd = 'curl -sSL https://get.rvm.io | sudo bash -s stable'
build.run_cmd(cmd, unsafe_shell=True, check_rc='curl failed')
cmd = "sudo -E su -c '{rvm_path}/rvm reload && {rvm_path}/rvm requirements run && {rvm_path}/rvm install {ruby_version}'".format(
ruby_version = RUBY_VERSION,
rvm_path = RVM_PATH )
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 = """sudo -E su -c 'PATH="{PATH}"; export PATH; {rvm_path}/rvm reload && {rvm_path}/rvm use {ruby_version} && gem install -v 1.4.0 fpm'""".format(
ruby_version = RUBY_VERSION,
rvm_path = RVM_PATH,
PATH = os.environ['PATH'] )
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')
parser.add_option('-p', '--package', action='store_true', dest='package', default=True)
parser.add_option('-n', '--no-package', action='store_false', dest='package')
(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 == '':
import distro
pld = distro.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','curl','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', 'fuse', 'libfuse2',
'libfuse-dev', 'libmicrohttpd-dev', 'unixodbc-dev']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
# if old, bootstrap g++
if pld in ['Ubuntu'] and platform.linux_distribution()[1] < '14':
# ubuntu12 ships with g++ 4.6 - needs 4.8+ to build clang
log.info('Detected: Old Ubuntu - need to get g++ 4.8 to build clang')
cmd = ['sudo','apt-get','install','-y','python-software-properties']
build.run_cmd(cmd, check_rc='installing add-apt-repository prereq failed')
cmd = ['sudo', 'add-apt-repository', '-y', 'ppa:ubuntu-toolchain-r/test']
build.run_cmd(cmd, check_rc='installing ppa failed')
cmd = ['sudo', 'apt-get', 'update', '-y']
build.run_cmd(cmd, check_rc='getting updates failed')
cmd = ['sudo', 'apt-get', 'install', '-y', 'g++-4.8']
build.run_cmd(cmd, check_rc='installing g++-4.8 failed')
cmd = ['sudo', 'update-alternatives', '--install', '/usr/bin/g++', 'g++', '/usr/bin/g++-4.8', '50']
build.run_cmd(cmd, check_rc='swapping g++-4.8 failed')
cmd = ['sudo', 'update-alternatives', '--install', '/usr/bin/gcc', 'gcc', '/usr/bin/gcc-4.8', '50']
build.run_cmd(cmd, check_rc='swapping gcc-4.8 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','rsync']
build.run_cmd(cmd, check_rc='installing autoconf failed')
if pld in ['Ubuntu'] and platform.linux_distribution()[1] >= '16':
cmd = ['sudo','apt-get','install','-y','patchelf']
build.run_cmd(cmd, check_rc='installing patchelf 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','curl','gcc-c++','git','autoconf','automake','texinfo',
'help2man','rpm-build','rubygems','ruby-devel','python-devel','zlib-devel','fuse','fuse-devel',
'bzip2-devel','libcurl-devel','libmicrohttpd-devel','libxml2-devel','libtool','libuuid-devel','openssl-devel','unixODBC-devel','patchelf']
build.run_cmd(cmd, check_rc='installing prerequisites failed')
elif pld in ['openSUSE ', 'openSUSE Leap', 'SUSE Linux Enterprise Server', 'SLES']:
log.info('Detected: {0}'.format(pld))
# get prerequisites
cmd = ['sudo','zypper','install','-y','curl','tar','gzip','git','ruby-devel','libmicrohttpd-devel','makeinfo','rubygems',
'libopenssl-devel','rpm-build','help2man','python-devel','libbz2-devel','libcurl-devel','libxml2-devel','libtool',
'libuuid-devel','uuid-devel','unixODBC-devel','cyrus-sasl','patchelf']
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
if options.package:
install_rvm_and_ruby()
install_fpm_gem()
if __name__ == '__main__':
sys.exit(main())