diff options
| author | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2019-10-30 14:33:05 -0600 |
|---|---|---|
| committer | Carlos Konstanski <carlos.konstanski@verizonwireless.com> | 2019-10-30 14:33:05 -0600 |
| commit | 7cab8996742b8128bed197f9457afd2af160cf5e (patch) | |
| tree | dfd5b40b99e0935ba65b34d973f6e79a6bb39b24 /bootstrap/pillar_config.rb | |
initial commit
Diffstat (limited to 'bootstrap/pillar_config.rb')
| -rwxr-xr-x | bootstrap/pillar_config.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/bootstrap/pillar_config.rb b/bootstrap/pillar_config.rb new file mode 100755 index 0000000..44fa02c --- /dev/null +++ b/bootstrap/pillar_config.rb @@ -0,0 +1,60 @@ +#!/usr/bin/ruby + +require "digest/sha1" +require "digest" +require "getoptlong" +require "json" +require "socket" +require "yaml" + +def sha() + seed = "" + File.open("/dev/urandom", "r") do |f| + seed = "#{f.sysread(24)}" + end + Digest::SHA1.hexdigest(seed) +end + +def process_yaml(build_basedir, local_build) + env_yaml_path = "#{File.dirname($0)}/config.yaml" + if ! File.file?(env_yaml_path) + STDERR.puts "Unable to find config.yaml. Exiting." + exit(1) + end + tag = sha()[0..23] + yml = YAML.load_file(env_yaml_path) + yml["gentoo_baseimage"] = {} + yml["gentoo_baseimage"]["image_name"] = "gentoo_baseimage" + yml["gentoo_baseimage"]["container_name"] = "gentoo_baseimage" + yml["gentoo_baseimage"]["build_dir"] = "#{build_basedir}/gentoo_baseimage" + yml["ansible"] = {} + yml["ansible"]["build_dir"] = "#{build_basedir}/ansible" + yml["ci"] = {} + yml["ci"]["build_dir"] = "#{build_basedir}/ci" + yml["ci"]["tag"] = tag + yml["ci"]["local_build"] = YAML.load(local_build) + yml +end + +def main() + build_basedir = nil + local_build = "false" + opts = GetoptLong.new(["--build-basedir", "-d", GetoptLong::REQUIRED_ARGUMENT], + ["--local-build", "-l", GetoptLong::REQUIRED_ARGUMENT]) + opts.each do |opt, arg| + case opt + when "--build-basedir" + build_basedir = arg + when "--local-build" + local_build = arg + end + end + if ! build_basedir + raise "--build-basedir must be supplied." + end + yml = process_yaml(build_basedir, local_build) + puts yml.to_json +end + +main() +exit(0) |
