diff --git a/scripts/mapleconf b/scripts/mapleconf new file mode 100755 index 0000000..68f6843 --- /dev/null +++ b/scripts/mapleconf @@ -0,0 +1,48 @@ +#!/bin/ruby + +# Copyright (c) 2026 Alexander Hill + +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. + +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +require "liquid" +require "psych" + +# TODO: Tie these variables to command line arguments. ~ahill +$config = Psych.safe_load_file "/etc/maple.yml" +$sysroot = "/" +$templates = "/usr/share/mapleconf" + +def render_directory(stack) + path = stack.empty? ? "/" : "/#{stack.join "/"}/" + + Dir.foreach $templates + path do |entry| + next if entry =~ /^\.+$/ + fullpath = path + entry + + if File.directory? $templates + fullpath + Dir.mkdir $sysroot + fullpath unless File.exist? $sysroot + fullpath + render_directory stack + [entry] + + elsif File.file? $templates + fullpath + puts fullpath + template = Liquid::Template.parse(File.read $templates + fullpath) + File.write $sysroot + fullpath, template.render($config) + + else + puts "What even is #{fullpath}? If you know, yell at Alex." + + end + end +end + +render_directory []