blob: 884fa1647ebd25c3a38a8f21da49c3b311a5e789 [file] [log] [blame]
Andrew Geisslerf103a7f2021-05-07 16:09:40 -05001From 808577f8464f542076840d0d93fe168a5f79442c Mon Sep 17 00:00:00 2001
2From: Silcet <camorga1@gmail.com>
3Date: Tue, 27 Apr 2021 05:40:03 +0000
Patrick Williamsb48b7b42016-08-17 15:04:38 -05004Subject: [PATCH] setup: add an option to specify iptables location
5
6When cross-compiling it isn't certain that the location of iptables on the
7target will be the same as on the host. It also doesn't make sense the
8test the version of the host during setup. We provide an option to
9specify an alternate iptables directory. This is assumed to be a
10cross-compile environment and therefore no attempt is made to verify the
11version of iptables to be used.
12
13Upstream-Status: Pending
14
15Signed-off-by: Joe MacDonald <joe_macdonald@mentor.com>
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050016
17The patch was imported from the OpenEmbedded git server
18(git://git.openembedded.org/openembedded) as of commit id
192cc1bd9dd060f5002c2fde7aacba86fe230c12af.
20
21Signed-off-by: Silcet <camorga1@gmail.com>
Patrick Williamsb48b7b42016-08-17 15:04:38 -050022---
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050023 setup.py | 65 ++++++++++++++++++++++++++++++++------------------------
24 1 file changed, 37 insertions(+), 28 deletions(-)
Patrick Williamsb48b7b42016-08-17 15:04:38 -050025
26diff --git a/setup.py b/setup.py
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050027index 09204d3..2343bc9 100644
Patrick Williamsb48b7b42016-08-17 15:04:38 -050028--- a/setup.py
29+++ b/setup.py
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050030@@ -246,41 +246,50 @@ shutil.copytree('src', 'staging')
Patrick Williamsb48b7b42016-08-17 15:04:38 -050031 os.unlink(os.path.join('staging', 'ufw-init'))
32 os.unlink(os.path.join('staging', 'ufw-init-functions'))
33
34+iptables_set = 0
35 iptables_exe = ''
36 iptables_dir = ''
37
38-for e in ['iptables']:
39- for dir in ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin', \
40- '/usr/local/bin']:
41- if e == "iptables":
42- if os.path.exists(os.path.join(dir, e)):
43- iptables_dir = dir
44- iptables_exe = os.path.join(iptables_dir, "iptables")
45- print("Found '%s'" % iptables_exe)
46- else:
47- continue
48-
49- if iptables_exe != "":
50- break
51-
Patrick Williamsb48b7b42016-08-17 15:04:38 -050052+if "--iptables-dir" in sys.argv:
53+ iptables_dir = sys.argv[sys.argv.index("--iptables-dir") + 1]
54+ iptables_exe = os.path.join(iptables_dir, "iptables")
55+ iptables_set = 1
56+ print("INFO: iptables manually set: '%s'" % (iptables_exe))
57+ sys.argv.remove(iptables_dir)
58+ sys.argv.remove("--iptables-dir")
59+
60+if not iptables_set:
61+ for e in ['iptables']:
62+ for dir in ['/sbin', '/bin', '/usr/sbin', '/usr/bin', '/usr/local/sbin', \
63+ '/usr/local/bin']:
64+ if e == "iptables":
65+ if os.path.exists(os.path.join(dir, e)):
66+ iptables_dir = dir
67+ iptables_exe = os.path.join(iptables_dir, "iptables")
68+ print("Found '%s'" % iptables_exe)
69+ else:
70+ continue
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050071
72-if iptables_exe == '':
73- print("ERROR: could not find required binary 'iptables'", file=sys.stderr)
74- sys.exit(1)
Patrick Williamsb48b7b42016-08-17 15:04:38 -050075+ if iptables_exe != "":
76+ break
Andrew Geisslerf103a7f2021-05-07 16:09:40 -050077
78-for e in ['ip6tables', 'iptables-restore', 'ip6tables-restore']:
79- if not os.path.exists(os.path.join(iptables_dir, e)):
80- print("ERROR: could not find required binary '%s'" % (e), file=sys.stderr)
Patrick Williamsb48b7b42016-08-17 15:04:38 -050081+ if iptables_exe == '':
82+ print("ERROR: could not find required binary 'iptables'", file=sys.stderr)
83 sys.exit(1)
84
85-(rc, out) = cmd([iptables_exe, '-V'])
86-if rc != 0:
87- raise OSError(errno.ENOENT, "Could not find version for '%s'" % \
88- (iptables_exe))
89-version = re.sub('^v', '', re.split('\s', str(out))[1])
90-print("Found '%s' version '%s'" % (iptables_exe, version))
91-if version < "1.4":
92- print("WARN: version '%s' has limited IPv6 support. See README for details." % (version), file=sys.stderr)
93+ for e in ['ip6tables', 'iptables-restore', 'ip6tables-restore']:
94+ if not os.path.exists(os.path.join(iptables_dir, e)):
95+ print("ERROR: could not find required binary '%s'" % (e), file=sys.stderr)
96+ sys.exit(1)
97+
98+ (rc, out) = cmd([iptables_exe, '-V'])
99+ if rc != 0:
100+ raise OSError(errno.ENOENT, "Could not find version for '%s'" % \
101+ (iptables_exe))
102+ version = re.sub('^v', '', re.split('\s', str(out))[1])
103+ print("Found '%s' version '%s'" % (iptables_exe, version))
104+ if version < "1.4":
105+ print("WARN: version '%s' has limited IPv6 support. See README for details." % (version), file=sys.stderr)
106
107 setup (name='ufw',
108 version=ufw_version,