-
Notifications
You must be signed in to change notification settings - Fork 3
/
buildpackages.py
131 lines (100 loc) · 3.83 KB
/
buildpackages.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
#!/bin/env python
import json
import os
import platform
import subprocess
import sys
# Global
dist = platform.linux_distribution()
linux = dist[0]
osmajorver = dist[1]
currentpath = os.path.dirname(os.path.realpath(sys.argv[0]))
list_of_spec_files = os.listdir(os.path.join(currentpath, 'SPECS'))
# Functions
class colors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
def print_ok(string):
print(colors.OKGREEN + string + colors.ENDC)
def print_warn(string):
print(colors.WARNING + string + colors.ENDC)
def print_err(string):
print(colors.FAIL + string + colors.ENDC)
def print_diff(string):
print(colors.ENDC + string + colors.ENDC)
def check_for_gpgkey():
config = json.load(open('config.json'))
private_gpg_key_id = config['gpg_key_id']
if len(private_gpg_key_id) < 8:
print_err('value gpg_key_id not found in config, or value invalid')
exit(1)
command_line = "/usr/bin/gpg --list-secret-keys {0}".format(private_gpg_key_id)
command_result = subprocess.Popen(command_line, stdout=subprocess.PIPE, shell=True)
command_output = command_result.communicate()[0]
if not command_result.returncode == 0:
print_err("Error finding the configured private key.")
print_err(command_output)
exit(1)
def check_macros():
config = json.load(open('config.json'))
private_gpg_key_name = config['gpg_key_name']
if len(private_gpg_key_name) < 1:
print_err('value private_gpg_key_name not found in config, or value invalid')
exit(1)
with open(os.path.expanduser('~/.rpmmacros'), 'w') as f:
f.write('%_signature gpg\n')
f.write('%_gpg_path ~/.gnupg\n')
f.write('%_gpg_name {0}\n'.format(private_gpg_key_name))
f.write('%_gpgbin /usr/bin/gpg\n')
def process_specfile(specfile):
config = json.load(open('config.json'))
gpg_key_pass = config['gpg_key_pass']
global currentpath
specfile_fullpath = os.path.join(currentpath, 'SPECS', specfile)
print_ok('Starting with specfile {0}'.format(specfile))
print_ok('-------------------')
# download all requirements for spec file
command_line = "/usr/bin/spectool -R -g {0}".format(specfile_fullpath)
print_ok('Running command \'{0}\''.format(command_line))
command_result = subprocess.Popen(command_line, stdout=subprocess.PIPE, shell=True)
command_output = command_result.communicate()[0]
if not command_result.returncode == 0:
print_warn(command_output)
else:
print_diff(command_output)
# download all requirements for spec file
command_line = '/usr/bin/expect build-and-sign.exp {0} {1}'.format(
specfile_fullpath, gpg_key_pass)
print_ok('Running command \'{0}\''.format(command_line))
command_result = subprocess.Popen(command_line, stdout=subprocess.PIPE, shell=True)
command_output = command_result.communicate()[0]
if not command_result.returncode == 0:
print_warn(command_output)
else:
print_diff(command_output)
print_ok(' ')
print("scp ha* hongens@hon-web-01:/home/domains/hongens/haproxy/repo/centos/7/x86_64/")
if not linux.upper().startswith('CENTOS'):
print_err("Error, not a centos machine..")
exit(1)
# check if we have a private key so we can sign the packages
check_for_gpgkey()
# Check rpmmacros
check_macros()
if osmajorver.startswith('7'):
# loop through each specfile for EL7
for specfile in list_of_spec_files:
if '.el7.' in specfile:
process_specfile(specfile)
elif osmajorver.startswith('6'):
# loop through each specfile for EL6
for specfile in list_of_spec_files:
if '.el6.' in specfile:
process_specfile(specfile)
else:
print_err("Error, version {0} not supported..".format(osmajorver))
exit(1)