From 4a3629e42cb3e1fbca4356cf789a8e79043cdc51 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 6 Dec 2024 22:26:38 +0200 Subject: initial config support --- Gemfile | 3 +++ Gemfile.lock | 16 ++++++++++++++++ Rakefile | 1 + config.toml | 3 +++ rcm/config.rb | 18 ++++++++++++++++++ rcm/rcm.rb | 2 ++ 6 files changed, 43 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 config.toml create mode 100644 rcm/config.rb 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 -- cgit v1.2.3