diff options
Diffstat (limited to 'custom/tinc/generate_hostfile.hs')
-rwxr-xr-x | custom/tinc/generate_hostfile.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/custom/tinc/generate_hostfile.hs b/custom/tinc/generate_hostfile.hs new file mode 100755 index 00000000..a8420780 --- /dev/null +++ b/custom/tinc/generate_hostfile.hs | |||
@@ -0,0 +1,19 @@ | |||
1 | #!/usr/bin/env runhaskell | ||
2 | |||
3 | import System.Directory.Tree | ||
4 | import Data.List | ||
5 | |||
6 | main :: IO () | ||
7 | main = readDirectory "." >>= putStrLn . genHostFile | ||
8 | |||
9 | genHostFile :: AnchoredDirTree String -> String | ||
10 | genHostFile (_ :/ (Dir _ contents)) = "{\n" ++ entries ++ "\n}\n" | ||
11 | where | ||
12 | entries = concat [ genEntry name content | (File name content) <- contents, name `notElem` hidden ] | ||
13 | genEntry fileName fileContent = unlines . indent $ [ "\"" ++ fileName ++ "\" = ''" ] ++ indent (lines fileContent) ++ [ "'';" ] | ||
14 | hidden = [ "to_nix.sh" | ||
15 | , "signup.sh" | ||
16 | ] | ||
17 | |||
18 | indent :: [String] -> [String] | ||
19 | indent = map (" " ++) | ||