#!/usr/bin/env ruby require 'fileutils' require 'dyndoc/init/home' arg=ARGV[0] arg="path" if !arg or arg.empty? share_path=File.expand_path("../../share", __FILE__) case arg when "help" puts <<-DOC Usage: ## get dyndoc home (i.e, ~/dyndoc or read config file ~/.dyndoc_home) dyn-init home ## set dyndoc home (update ~/.dyndoc_home) dyn-init home dyn-init home --init #with init path ## create dyndoc home folder and initialize some sharing dyn-init [path] dyn-init --reset #reset dyndoc home folder ## without creating dyndoc home folder, initialize some sharing dyn-init install [all|etc|demo|html-srv|dyndoc.yml] DOC ## REMOVED from DOC above since maybe it is OBSOLETE #### ## add room folder #### dyn-init sync :@ when "home" if ARGV.length == 2 or (ARGV.length==3 and ["--init"].include? ARGV[2]) Dyndoc.home=ARGV[1] FileUtils.mkdir_p Dyndoc.home FileUtils.cp_r File.join(share_path,"."),Dyndoc.home if ARGV[2]=="--init" end unless File.directory? Dyndoc.home puts "Folder #{Dyndoc.home} does not exist. \nDo you want to initialize (YES|no)?" if STDIN.gets.chomp == "YES" FileUtils.cp_r File.join(share_path,"."),Dyndoc.home end end puts "dyndoc home set to #{Dyndoc.home}"+((ARGV.length==3 and ARGV[2]=="--init") ? " with paths initialization" : "" ) when "path","--reset" dyndoc_path=Dyndoc.home if arg=="--reset" puts "Do you really want to reset the dyndoc home (YES|no)?" if STDIN.gets.chomp=="YES" and File.directory? dyndoc_path FileUtils.rm_rf dyndoc_path end end unless File.exist? dyndoc_path FileUtils.mkdir_p dyndoc_path FileUtils.cp_r File.join(share_path,"."),dyndoc_path puts "Your dyndoc home now contains at least the default settings!" else puts "Warning: #{dyndoc_path} folder already exists!" puts "Try: dyn-init install [all|etc|demo|html-srv|dyndoc.yml]" end when "install" case ARGV[1].strip when "all" FileUtils.cp_r File.join(share_path,"."),Dyndoc.home when "etc","demo","html-srv","dyndoc.yml" FileUtils.cp_r File.join(share_path,ARGV[1].strip),Dyndoc.home end when "sync" ## MAYBE OBSOLETE! require 'fileutils' FileUtils.mkdir_p (etc=File.join(ENV["HOME"],"dyndoc","etc")) room_sync=File.join(etc,".room_sync") room_dirs=(File.exists? room_sync) ? eval(File.read(room_sync)) : {} if ARGV[1] =~ /([^\:@]*)\:([^\:@]*)@([^\:@]*)/ room_id,room_local,room_remote=$1,$2,$3 room_dirs[room_id]={local: room_local, remote: room_remote} File.open(room_sync,"w") {|f| f << room_dirs.inspect } end end