From d82173133cb0fd10b54a1eb4ae81f610b5f98804 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 30 May 2023 21:00:20 +0100 Subject: [PATCH] odhcpc script: mkdir --- examples/odhcp6-script.fnl | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/odhcp6-script.fnl b/examples/odhcp6-script.fnl index d72c678..1629203 100644 --- a/examples/odhcp6-script.fnl +++ b/examples/odhcp6-script.fnl @@ -1,12 +1,11 @@ -(os.chdir (os.getenv "SERVICE_STATE")) +(local state-directory (assert (os.getenv "SERVICE_STATE"))) +(os.execute (.. "mkdir -p " state-directory)) (fn write-value [name value] - (with-open [fout (io.open name :w)] - (when value (fout:write value)))) - -(write-value "state" (. arg 2)) -(write-value "ifname" (. arg 1)) + (let [path (.. state-directory "/" name)] + (with-open [fout (io.open path :w)] + (when value (fout:write value))))) (fn write-value-from-env [name] (write-value name (os.getenv (string.upper name)))) @@ -47,10 +46,13 @@ (each [_ n (ipairs wanted)] (write-value-from-env n))) -(let [ready (match state +(let [[ifname state] arg + ready (match state "started" false "unbound" false "stopped" false _ true)] - (and ready - (with-open [fd (io.open "/proc/self/fd/10" :w)] (fd:write "\n")))) + (write-value "state" state) + (write-value "ifname" ifname) + (when ready + (with-open [fd (io.open "/proc/self/fd/10" :w)] (fd:write "\n"))))