diff options
-rwxr-xr-x | contrib/fj-mkdeb.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/fj-mkdeb.py b/contrib/fj-mkdeb.py new file mode 100755 index 000000000..8027daa5b --- /dev/null +++ b/contrib/fj-mkdeb.py | |||
@@ -0,0 +1,51 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # This script is automate the workaround for https://github.com/netblue30/firejail/issues/772 | ||
4 | |||
5 | import os, re, shlex, subprocess, sys | ||
6 | |||
7 | def run(srcdir, args): | ||
8 | os.chdir(srcdir) | ||
9 | |||
10 | dry_run=False | ||
11 | escaped_args=[] | ||
12 | # 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 | if a.startswith('--prefix'): | ||
15 | # prefix should ALWAYS be /usr here. Discard user-set values | ||
16 | args.remove(a) | ||
17 | elif a == '--only-fix-mkdeb': | ||
18 | # for us, not configure | ||
19 | dry_run=True | ||
20 | args.remove(a) | ||
21 | else: | ||
22 | escaped_args.append(shlex.quote(a)) | ||
23 | |||
24 | # Fix up mkdeb.sh to include custom configure options. | ||
25 | with open('mkdeb.sh', 'rb') as f: | ||
26 | sh=str(f.read(), 'utf_8') | ||
27 | rx=re.compile(r'^\./configure\s.*$', re.M) | ||
28 | with open('mkdeb.sh', 'wb') as f: | ||
29 | f.write(bytes(rx.sub('./configure --prefix=/usr '+(' '.join(escaped_args)), sh), 'utf_8')) | ||
30 | |||
31 | if dry_run: return 0 | ||
32 | |||
33 | # now run configure && make | ||
34 | if subprocess.call(['./configure', '--prefix=/usr']+args) == 0: | ||
35 | subprocess.call(['make', 'deb']) | ||
36 | |||
37 | return 0 | ||
38 | |||
39 | |||
40 | if __name__ == '__main__': | ||
41 | if len(sys.argv) == 2 and sys.argv[1] == '--help': | ||
42 | print('''Build a .deb of firejail with custom configure options | ||
43 | |||
44 | usage: {script} [--only-fix-mkdeb] [CONFIGURE_OPTIONS [...]] | ||
45 | |||
46 | --only-fix-mkdeb: don't run configure or make after modifying mkdeb.sh | ||
47 | CONFIGURE_OPTIONS: arguments for configure | ||
48 | '''.format(script=sys.argv[0])) | ||
49 | sys.exit(0) | ||
50 | else: | ||
51 | sys.exit(run(os.path.dirname(os.path.abspath(sys.argv[0]+'/..')), sys.argv[1:])) | ||