summaryrefslogtreecommitdiff
path: root/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn
diff options
context:
space:
mode:
Diffstat (limited to 'doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn')
-rw-r--r--doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn39
1 files changed, 39 insertions, 0 deletions
diff --git a/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn b/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn
new file mode 100644
index 00000000..d3c77a17
--- /dev/null
+++ b/doc/forum/Script_to_convert_config_files_for_inclusion_in_Propellor_config.mdwn
@@ -0,0 +1,39 @@
+This script turns
+
+ Section "Monitor"
+ Identifier "Configured Monitor"
+ EndSection
+
+into this:
+
+ [ "Section \"Monitor\""
+ , "\tIdentifier \"Configured Monitor\""
+ , "EndSection"
+ ]
+
+for the inclusion of short config files in your Propellor config using `File.hasContent`.
+
+[[!format haskell """
+#!/usr/bin/runhaskell
+
+main = interact $ unlines . propellorLines . lines
+
+propellorLines :: [String] -> [String]
+propellorLines (x:xs) = ("[ " ++ wrapEscapeLine x) : propellorLines' xs
+
+propellorLines' :: [String] -> [String]
+propellorLines' = foldr step ["]"]
+ where
+ step x xs = (", " ++ wrapEscapeLine x) : xs
+
+wrapEscapeLine :: String -> String
+wrapEscapeLine line = "\"" ++ (foldr step "" line) ++ "\""
+ where
+ step x xs
+ | x == '\t' = "\\t" ++ xs
+ | x == '\\' = x : x : xs
+ | x == '"' = '\\' : x : xs
+ | otherwise = x : xs
+"""]]
+
+Usage: `cat config_file | propellor_lines` (or in Emacs, dump the config file into your propellor config, select the region and use `C-u M-|` to pipe it through).