diff --git a/kura/distrib/src/main/ant/build_equinox_distrib.xml b/kura/distrib/src/main/ant/build_equinox_distrib.xml
index 8ee078325bd..112d728ac14 100644
--- a/kura/distrib/src/main/ant/build_equinox_distrib.xml
+++ b/kura/distrib/src/main/ant/build_equinox_distrib.xml
@@ -554,6 +554,8 @@ fi]]>
prefix="${build.output.name}/${install.folder}" />
+
lanInterfaceNames = new ArrayList<>();
+ List> netInterfaceConfigs = config
+ .getModifiedNetInterfaceConfigs();
+ for (NetInterfaceConfig extends NetInterfaceAddressConfig> netInterfaceConfig : netInterfaceConfigs) {
+ boolean isLan = ((AbstractNetInterface>) netInterfaceConfig)
+ .getInterfaceStatus() == NetInterfaceStatus.netIPv4StatusEnabledLAN;
+ if (isLan && (netInterfaceConfig.getType() == NetInterfaceType.ETHERNET
+ || netInterfaceConfig.getType() == NetInterfaceType.WIFI)) {
+ lanInterfaceNames.add(netInterfaceConfig.getName());
+ }
+ }
+
+ lanInterfaceNames.sort(null);
+ writeDhcpClientConfig(lanInterfaceNames);
+ }
+
+ private void writeDhcpClientConfig(List interfaceNames) {
+ String hookScriptFileName = DhcpClientManager.getHookScriptFileName();
+ if (hookScriptFileName == null || hookScriptFileName.isEmpty()) {
+ logger.debug("Hook script file name not defined. Do nothing.");
+ return;
+ }
+
+ try {
+ writeDhclientHookScript(interfaceNames, hookScriptFileName);
+ } catch (KuraIOException e) {
+ logger.error("Failed to write dhclient hook script", e);
+ }
+ }
+
+ private void writeDhclientHookScript(List interfaceNames, String hookScriptFileName)
+ throws KuraIOException {
+ StringBuilder interfacesLine = new StringBuilder("interfaces=\"");
+ interfacesLine.append(interfaceNames.stream().collect(Collectors.joining(" ")));
+ interfacesLine.append("\"\n");
+ String hookScriptContent = DEFAULT_HOOK_SCRIPT.replace("interfaces=\"\"\n", interfacesLine);
+
+ Path hookScriptFilePath = Paths.get(hookScriptFileName);
+ try {
+ if (Files.exists(hookScriptFilePath) && Files.isReadable(hookScriptFilePath)) {
+ String currentHookScriptContent = new String(Files.readAllBytes(hookScriptFilePath),
+ StandardCharsets.UTF_8);
+ if (!hookScriptContent.equals(currentHookScriptContent)) {
+ writeFile(hookScriptFilePath, hookScriptContent);
+ }
+ } else {
+ writeFile(hookScriptFilePath, hookScriptContent);
+ }
+ } catch (IOException e) {
+ throw new KuraIOException(e, "Failed to update dhclient hook script");
+ }
+ }
+
+ private void writeFile(Path path, String content) throws IOException {
+ Files.write(path, content.getBytes(StandardCharsets.UTF_8));
+ }
+
+}
diff --git a/kura/org.eclipse.kura.net.admin/src/main/java/org/eclipse/kura/net/admin/visitor/linux/LinuxWriteVisitor.java b/kura/org.eclipse.kura.net.admin/src/main/java/org/eclipse/kura/net/admin/visitor/linux/LinuxWriteVisitor.java
index 19d0e3da645..2c982aae50b 100644
--- a/kura/org.eclipse.kura.net.admin/src/main/java/org/eclipse/kura/net/admin/visitor/linux/LinuxWriteVisitor.java
+++ b/kura/org.eclipse.kura.net.admin/src/main/java/org/eclipse/kura/net/admin/visitor/linux/LinuxWriteVisitor.java
@@ -33,6 +33,7 @@ private LinuxWriteVisitor() {
this.visitors.add(new WifiConfigWriter());
this.visitors.add(new PppConfigWriter());
this.visitors.add(new DhcpConfigWriter());
+ this.visitors.add(new DhcpClientConfigWriter());
this.visitors.add(new FirewallAutoNatConfigWriter());
}
@@ -51,7 +52,8 @@ public void visit(NetworkConfiguration config) throws KuraException {
visitor.visit(config);
}
- // After every visit, unset the executorService. This must be set before every call.
+ // After every visit, unset the executorService. This must be set before every
+ // call.
this.executorService = null;
}