bin/dyn-init in dyndoc-ruby-0.9.2 vs bin/dyn-init in dyndoc-ruby-0.9.3
- old
+ new
@@ -1,29 +1,68 @@
#!/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:
- ## create ~/dyndoc folder and initialize some sharing
- dyn-init path
- ## add room folder
- dyn-init sync <room_id>:<room_folder_full_path>@<room_remote_wordir>
+ ## get dyndoc home (i.e, ~/dyndoc or read config file ~/.dyndoc_home)
+ dyn-init home
+ ## set dyndoc home (update ~/.dyndoc_home)
+ dyn-init home <other dyndoc home path>
+ dyn-init home <other dyndoc home path> --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
-when "path"
- share_path=File.expand_path("../../share", __FILE__)
- dyndoc_path=File.join(ENV["HOME"],"dyndoc")
+## REMOVED from DOC above since maybe it is OBSOLETE
+#### ## add room folder
+#### dyn-init sync <room_id>:<room_folder_full_path>@<room_remote_wordir>
+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 "sync"
+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] =~ /([^\:@]*)\:([^\:@]*)@([^\:@]*)/