summaryrefslogtreecommitdiff
path: root/scripts/common.rb.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/common.rb.in')
-rw-r--r--scripts/common.rb.in22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/common.rb.in b/scripts/common.rb.in
new file mode 100644
index 0000000..c7dc261
--- /dev/null
+++ b/scripts/common.rb.in
@@ -0,0 +1,22 @@
+require 'yaml'
+
+def cfg
+ @cfg ||= YAML::load(open("@conf_file@"))
+end
+
+def load_user_yaml(filename)
+ user = YAML::load(open(filename))
+ groups = user["groups"] || []
+ user["groups"] = groups.concat((groups & cfg["groupgroups"].keys).map{|g|cfg["groupgroups"][g]}.flatten)
+ return user
+end
+
+def load_all_users
+ users = {}
+ Dir.glob("#{cfg["yamldir"]}/*.yml").map{|filename|
+ uid = File.basename(filename).sub(/^([0-9]*)\.yml$/, "\\1").to_i
+ user = load_user_yaml(filename)
+ users[uid] = user
+ }
+ return users
+end