-
Notifications
You must be signed in to change notification settings - Fork 16
/
make-ppa
executable file
·159 lines (127 loc) · 5.46 KB
/
make-ppa
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
#!/usr/bin/env python
# Creates source packages and uploads them to Launchpad.
#
# Put this script somewhere, then run it from a git repository containing
# sources for a debian package. Resulting packages will be created in a
# subdirectory next to the make-ppa script.
from __future__ import print_function
import sys
import os
import subprocess
import re
import argparse
CHANGELOG = 'debian/changelog'
DISTS = ['trusty', 'xenial', 'bionic', 'focal', 'jammy', 'kinetic']
VERSION_PATTERN = re.compile(
r'^(?P<name>[+-.a-z0-9]+)\s+\((?P<version>[^)]+)\)\s+(?P<dist>[^)]+); urgency=(?P<urgency>.+)$')
OUTPUT_DIR = os.path.dirname(os.path.abspath(__file__))
if sys.version_info[0] < 3:
input = raw_input
class Package(object):
def __init__(self, dists=DISTS, ppa='yubico/stable'):
self.dists = dists
file = open(CHANGELOG, 'r')
self.changelog = file.readlines()
file.close()
match = VERSION_PATTERN.match(self.changelog[0])
self.ppa = ppa
self.name = match.group('name')
self.dist = match.group('dist')
self.urgency = match.group('urgency')
orig_version = match.group('version')
base_target = "%s/%s/%s" % (OUTPUT_DIR, self.name, orig_version)
if '~ppa' in orig_version:
print("Version '%s %s' already looks like a ppa version!" % \
(orig_version, self.dist))
sys.exit(1)
ppa_version = 1
while os.path.exists('%s~ppa%d' % (base_target, ppa_version)):
ppa_version += 1
self.version = '%s~ppa%s' % (orig_version, ppa_version)
self.target = "%s/%s/%s" % (OUTPUT_DIR, self.name, self.version)
def build_dist(self, dist):
version = '%s~%s1' % (self.version, dist)
line = "%s (%s) %s; urgency=%s" % \
(self.name, version, dist, self.urgency)
print("Build %s" % line)
changelog = list(self.changelog)
changelog[0] = line
file = open(CHANGELOG, 'w')
file.writelines(changelog)
file.close()
os.system('debuild -S -sa -us -uc')
os.system('mv ../%s_%s* %s/' %
(self.name, version, self.target))
def build(self, install_deps):
upstream_version = self.version.split('-', 1)[0]
orig = '%s_%s.orig.tar.gz' % (self.name, upstream_version)
if not os.path.exists('../%s' % orig):
try:
res = subprocess.check_output('pristine-tar list', shell=True)
if not orig in res.split():
print("../%s is missing!" % orig)
sys.exit(1)
os.system('pristine-tar checkout %s' % orig)
os.system('mv %s ../' % orig)
except:
# Try without orig, might be a native package.
pass
os.system('mkdir -p %s' % self.target)
os.system('cp ../%s %s/' % (orig, self.target))
if install_deps:
os.system('yes | sudo mk-build-deps --install --remove')
for dist in self.dists:
self.build_dist(dist)
file = open(CHANGELOG, 'w')
file.writelines(self.changelog)
file.close()
def sign(self, key, program):
args = [
("-k %s" % key) if key else "",
("-p %s" % program) if program else "",
]
cmd = ('debsign %s %s/%s_%s*_source.changes' %
(" ".join(args), self.target, self.name, self.version))
os.system(cmd)
def upload(self):
for file in os.listdir(self.target):
if file.endswith('.changes'):
os.system('dput ppa:%s %s/%s' % (self.ppa, self.target, file))
if __name__ == '__main__':
parser = argparse.ArgumentParser('Create source packages for PPA',
add_help=True)
parser.add_argument('--no-sign', action='store_false', dest='sign',
help='Do not sign the packages (implies --no-upload)')
parser.add_argument('--no-upload', action='store_false', dest='upload',
help='Do not upload the (signed) packages')
parser.add_argument('--dists', nargs='+', default=DISTS, metavar='DIST',
help='Distributions to build for')
parser.add_argument('--ppa', nargs='?', default='yubico/stable',
help='PPA to upload to')
parser.add_argument('--force', action='store_true', dest='force',
help='Do not prompt for confirmation before running')
parser.add_argument('--install-deps', action='store_true', dest='install_deps',
help='Install build dependencies')
parser.add_argument('-k', '--key', nargs='?',
help='GPG key id to use for signing')
parser.add_argument('-p', '--program', nargs='?',
help='GPG program to use for signing')
args = parser.parse_args()
do_sign = args.sign
do_upload = do_sign and args.upload
package = Package(dists=args.dists, ppa=args.ppa)
print("Building %s %s for distributions: %s" % \
(package.name, package.version, ', '.join(package.dists)))
if do_sign:
print("Will sign packages!")
if do_upload:
print("Will upload packages!")
print("PPA: %s" % args.ppa)
if not args.force:
input("Enter to continue, Ctrl+C to abort")
package.build(args.install_deps)
if do_sign:
package.sign(args.key, args.program)
if do_upload:
package.upload()
print("All done!")