summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-12-06 22:26:38 +0200
committerPaul Buetow <paul@buetow.org>2024-12-06 22:26:38 +0200
commit4a3629e42cb3e1fbca4356cf789a8e79043cdc51 (patch)
treee4f6b1099ee3319bcc2f018fdb8937b2eb362ce4
parent9abea6c57e018f6033dfa8ffc6cdcdfc86ece969 (diff)
initial config support
-rw-r--r--Gemfile3
-rw-r--r--Gemfile.lock16
-rw-r--r--Rakefile1
-rw-r--r--config.toml3
-rw-r--r--rcm/config.rb18
-rw-r--r--rcm/rcm.rb2
6 files changed, 43 insertions, 0 deletions
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..f41482e
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem 'toml'
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..540a42c
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,16 @@
+GEM
+ remote: https://rubygems.org/
+ specs:
+ parslet (2.0.0)
+ toml (0.3.0)
+ parslet (>= 1.8.0, < 3.0.0)
+
+PLATFORMS
+ ruby
+ x86_64-linux
+
+DEPENDENCIES
+ toml
+
+BUNDLED WITH
+ 2.5.22
diff --git a/Rakefile b/Rakefile
index 5b2ec0e..2935920 100644
--- a/Rakefile
+++ b/Rakefile
@@ -4,6 +4,7 @@ desc 'Set up wireguard mesh'
task :wireguard do
make_it_so do
p option :verbose
+ dump_config
only_when { hostname is :earth }
file '/etc/wg/wg0.conf' do
diff --git a/config.toml b/config.toml
new file mode 100644
index 0000000..9aea7f2
--- /dev/null
+++ b/config.toml
@@ -0,0 +1,3 @@
+[hostgroups]
+
+frontends = ["blowfish.buetow.org", "fishfinger.buetow.org"]
diff --git a/rcm/config.rb b/rcm/config.rb
new file mode 100644
index 0000000..b9dc5ac
--- /dev/null
+++ b/rcm/config.rb
@@ -0,0 +1,18 @@
+require 'toml'
+
+module RCM
+ # Configuration
+ module Config
+ @@config = File.exist?('config.toml') ? TOML.load_file('config.toml') : {}
+
+ def config(key)
+ raise "No such config key: #{key}" unless @@config.key?(key)
+
+ @@config[key]
+ end
+
+ def dump_config
+ p @@config
+ end
+ end
+end
diff --git a/rcm/rcm.rb b/rcm/rcm.rb
index 3724a88..43c016b 100644
--- a/rcm/rcm.rb
+++ b/rcm/rcm.rb
@@ -1,3 +1,4 @@
+require_relative 'config'
require_relative 'options'
require_relative 'only_when'
require_relative 'file'
@@ -6,6 +7,7 @@ require_relative 'file'
module RCM
# Here all starts
class RCM
+ include Config
include Options
def initialize