summaryrefslogtreecommitdiffstats
path: root/contrib/fj-mkdeb.py
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/fj-mkdeb.py')
-rwxr-xr-xcontrib/fj-mkdeb.py102
1 files changed, 54 insertions, 48 deletions
diff --git a/contrib/fj-mkdeb.py b/contrib/fj-mkdeb.py
index 3cc13b758..89b4e46a9 100755
--- a/contrib/fj-mkdeb.py
+++ b/contrib/fj-mkdeb.py
@@ -4,42 +4,46 @@
4 4
5import os, re, shlex, subprocess, sys 5import os, re, shlex, subprocess, sys
6 6
7
7def run(srcdir, args): 8def run(srcdir, args):
8 if srcdir: os.chdir(srcdir) 9 if srcdir: os.chdir(srcdir)
9 10
10 dry_run=False 11 dry_run = False
11 escaped_args=[] 12 escaped_args = []
12 # We need to modify the list as we go. So be sure to copy the list to be iterated! 13 # We need to modify the list as we go. So be sure to copy the list to be iterated!
13 for a in args[:]: 14 for a in args[:]:
14 if a.startswith('--prefix'): 15 if a.startswith('--prefix'):
15 # prefix should ALWAYS be /usr here. Discard user-set values 16 # prefix should ALWAYS be /usr here. Discard user-set values
16 args.remove(a) 17 args.remove(a)
17 elif a == '--only-fix-mkdeb': 18 elif a == '--only-fix-mkdeb':
18 # for us, not configure 19 # for us, not configure
19 dry_run=True 20 dry_run = True
20 args.remove(a) 21 args.remove(a)
21 else: 22 else:
22 escaped_args.append(shlex.quote(a)) 23 escaped_args.append(shlex.quote(a))
23 24
24 # Fix up mkdeb.sh to include custom configure options. 25 # Fix up mkdeb.sh to include custom configure options.
25 with open('mkdeb.sh', 'rb') as f: 26 with open('mkdeb.sh', 'rb') as f:
26 sh=str(f.read(), 'utf_8') 27 sh = str(f.read(), 'utf_8')
27 rx=re.compile(r'^\./configure\s.*$', re.M) 28 rx = re.compile(r'^\./configure\s.*$', re.M)
28 with open('mkdeb.sh', 'wb') as f: 29 with open('mkdeb.sh', 'wb') as f:
29 f.write(bytes(rx.sub('./configure --prefix=/usr '+(' '.join(escaped_args)), sh), 'utf_8')) 30 f.write(
31 bytes(
32 rx.sub('./configure --prefix=/usr ' + (' '.join(escaped_args)),
33 sh), 'utf_8'))
30 34
31 if dry_run: return 0 35 if dry_run: return 0
32 36
33 # now run configure && make 37 # now run configure && make
34 if subprocess.call(['./configure', '--prefix=/usr']+args) == 0: 38 if subprocess.call(['./configure', '--prefix=/usr'] + args) == 0:
35 subprocess.call(['make', 'deb']) 39 subprocess.call(['make', 'deb'])
36 40
37 return 0 41 return 0
38 42
39 43
40if __name__ == '__main__': 44if __name__ == '__main__':
41 if len(sys.argv) == 2 and sys.argv[1] == '--help': 45 if len(sys.argv) == 2 and sys.argv[1] == '--help':
42 print('''Build a .deb of firejail with custom configure options 46 print('''Build a .deb of firejail with custom configure options
43 47
44usage: 48usage:
45{script} [--fj-src=SRCDIR] [--only-fix-mkdeb] [CONFIGURE_OPTIONS [...]] 49{script} [--fj-src=SRCDIR] [--only-fix-mkdeb] [CONFIGURE_OPTIONS [...]]
@@ -51,24 +55,26 @@ usage:
51 --only-fix-mkdeb: don't run configure or make after modifying mkdeb.sh 55 --only-fix-mkdeb: don't run configure or make after modifying mkdeb.sh
52 CONFIGURE_OPTIONS: arguments for configure 56 CONFIGURE_OPTIONS: arguments for configure
53'''.format(script=sys.argv[0])) 57'''.format(script=sys.argv[0]))
54 sys.exit(0) 58 sys.exit(0)
55 else: 59 else:
56 # Find the source directory 60 # Find the source directory
57 srcdir=None 61 srcdir = None
58 args=sys.argv[1:] 62 args = sys.argv[1:]
59 for a in args: 63 for a in args:
60 if a.startswith('--fj-src='): 64 if a.startswith('--fj-src='):
61 args.remove(a) 65 args.remove(a)
62 srcdir=a[9:] 66 srcdir = a[9:]
63 break 67 break
64 if not(srcdir): 68 if not (srcdir):
65 # srcdir not manually specified, try to auto-detect 69 # srcdir not manually specified, try to auto-detect
66 srcdir=os.path.dirname(os.path.abspath(sys.argv[0]+'/..')) 70 srcdir = os.path.dirname(os.path.abspath(sys.argv[0] + '/..'))
67 if not(os.path.isfile(srcdir+'/mkdeb.sh')): 71 if not (os.path.isfile(srcdir + '/mkdeb.sh')):
68 # Script is probably installed. Check the cwd. 72 # Script is probably installed. Check the cwd.
69 if os.path.isfile('./mkdeb.sh'): 73 if os.path.isfile('./mkdeb.sh'):
70 srcdir=None 74 srcdir = None
71 else: 75 else:
72 print('Error: Could not find the firejail source tree. Exiting.') 76 print(
73 sys.exit(1) 77 'Error: Could not find the firejail source tree. Exiting.'
74 sys.exit(run(srcdir, args)) 78 )
79 sys.exit(1)
80 sys.exit(run(srcdir, args))