Compare commits
2 Commits
19212b1eeb
...
3f4dbfcfd3
Author | SHA1 | Date |
---|---|---|
|
3f4dbfcfd3 | 4 months ago |
|
d82173133c | 4 months ago |
@ -0,0 +1,70 @@
|
||||
|
||||
(local inotify (require :inotify))
|
||||
|
||||
(fn watch-fsevents [directory-name]
|
||||
(let [handle (inotify.init)]
|
||||
(handle:addwatch directory-name
|
||||
inotify.IN_CREATE
|
||||
inotify.IN_MOVE
|
||||
inotify.IN_DELETE
|
||||
inotify.IN_DELETE_SELF
|
||||
inotify.IN_MOVED_FROM
|
||||
inotify.IN_MOVED_TO
|
||||
inotify.IN_CLOSE_WRITE)
|
||||
handle))
|
||||
|
||||
|
||||
(fn merge [table1 table2]
|
||||
(collect [k v (pairs table2) &into table1]
|
||||
k v))
|
||||
|
||||
(fn parse-extra [s]
|
||||
(let [out {}]
|
||||
(each [name val (string.gmatch s ",(.-)=([^,]+)")]
|
||||
(tset out name val))
|
||||
out))
|
||||
|
||||
(fn parse-prefixes [prefixes]
|
||||
(icollect [val (string.gmatch prefixes "([^ ]+)")]
|
||||
(let [(prefix len preferred valid extra)
|
||||
(string.match val "(.-)::/(%d+),(%d+),(%d+)(.*)$")]
|
||||
(merge {: prefix : len : preferred : valid} (parse-extra extra))
|
||||
)))
|
||||
|
||||
;; Format: <prefix>/<length>,preferred,valid[,excluded=<excluded-prefix>/<length>][,class=<prefix class #>]
|
||||
|
||||
;; (parse-prefixes "2001:8b0:de3a:40dc::/64,7198,7198 2001:8b0:de3a:1001::/64,7198,7188,excluded=1/2,thi=10")
|
||||
|
||||
|
||||
(fn file-exists? [name]
|
||||
(let [f (io.open name :r)]
|
||||
(match f
|
||||
non-nil (or (f:close) true)
|
||||
(nil err) false)))
|
||||
|
||||
(fn read-line [name]
|
||||
(with-open [f (assert (io.open name :r) (.. "can't open file " name))]
|
||||
(f:read "*l")))
|
||||
|
||||
(var last-update 0)
|
||||
(fn event-time [directory]
|
||||
(if (file-exists? (.. directory "/state"))
|
||||
(tonumber (read-line (.. directory "/last-update")))
|
||||
nil))
|
||||
|
||||
(fn wait-for-update [directory fsevents]
|
||||
(while (<= (or (event-time directory) 0) last-update)
|
||||
(fsevents:read))
|
||||
(set last-update (event-time directory))
|
||||
true)
|
||||
|
||||
(let [[state-directory lan-device] arg
|
||||
fsevents (watch-fsevents state-directory)]
|
||||
(while (wait-for-update state-directory fsevents)
|
||||
(match (read-line (.. state-directory "/state"))
|
||||
(where (or :bound :rebound :informed :updated :ra-updated))
|
||||
(let [[{ : prefix : len : preferred : valid }]
|
||||
(parse-prefixes (read-line (.. state-directory "/prefixes")))]
|
||||
(os.execute (.. "ip address add " prefix "::1/" len
|
||||
" dev " lan-device)))
|
||||
_ (os.exit 1))))
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
writeFennelScript
|
||||
, luaSmall
|
||||
, linotify
|
||||
}:
|
||||
writeFennelScript "acquire-delegated-prefix"
|
||||
[
|
||||
(linotify.override { lua = luaSmall; })
|
||||
]
|
||||
./acquire-delegated-prefix.fnl
|
@ -0,0 +1,19 @@
|
||||
{ lua, lib, fetchFromGitHub }:
|
||||
let pname = "linotify";
|
||||
in lua.pkgs.buildLuaPackage {
|
||||
inherit pname;
|
||||
version = "0.5";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
repo = "linotify";
|
||||
owner = "hoelzro";
|
||||
rev = "a56913e9c0922befb65227a00cf69c2e8052de1a";
|
||||
hash = "sha256-IlOJbGx1zbOR3vgNMsNTPsarhPANpzl7jsu33LEbIqY=";
|
||||
};
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p "$out/lib/lua/${lua.luaversion}"
|
||||
cp inotify.so "$out/lib/lua/${lua.luaversion}/"
|
||||
'';
|
||||
|
||||
}
|
Loading…
Reference in New Issue