summaryrefslogtreecommitdiff
path: root/dotdot
diff options
context:
space:
mode:
Diffstat (limited to 'dotdot')
-rwxr-xr-xdotdot75
1 files changed, 75 insertions, 0 deletions
diff --git a/dotdot b/dotdot
new file mode 100755
index 0000000..7b9dffb
--- /dev/null
+++ b/dotdot
@@ -0,0 +1,75 @@
+#!/usr/bin/ruby
+%w[socket fileutils yaml]
+ .map { require _1 }
+
+HOME = ENV["HOME"] or File.expand_path "~/"
+HOSTNAME = Socket.gethostname
+
+class Binding
+ def eval_file(path)
+ self.eval (File.read path)
+ end
+end
+
+def eval_file(file)
+ file = File.expand_path file
+ dir = File.dirname file
+ binding.eval_file file
+end
+
+def ls(dir)
+ Dir.entries(dir).reject {|d| [".", ".."].include? d }
+end
+
+def ln(from, to)
+ FileUtils.ln_s from, to
+end
+
+def write(file, contents)
+ File.write file, contents
+end
+
+def rm(file)
+ FileUtils.rm file
+end
+
+def mkdir(dir)
+ FileUtils.mkdir_p dir
+end
+
+def rmdir(dir)
+ FileUtils.rmdir dir
+end
+
+require_relative "core"
+require_relative "stdlib"
+
+$cmds = {
+ show: lambda {|op|
+ if op.is_a? Deploy
+ puts op.ops
+ else
+ puts op
+ end
+ },
+ debug: lambda {|op|
+ puts op.to_yaml
+ },
+ check: lambda {|op|
+ if op.check
+ puts "nothing left to do"
+ else
+ puts "not fully deployed"
+ end
+ },
+ do: lambda {|op| op.do },
+ undo: lambda {|op| op.undo },
+}
+def main
+ command = ARGV.shift.to_sym
+ file = ARGV.shift || "#{HOSTNAME}.rb"
+ op = eval_file file
+ $cmds[command][op]
+end
+
+main if __FILE__ == $0