Simplified installation: no more questions. It overwrites stuff and leaves backups by default. [Fix #197, #175]

This commit is contained in:
Yan Pritzker
2012-10-25 10:09:24 -05:00
parent 59ff83a0a3
commit 5f55470c6c
2 changed files with 34 additions and 37 deletions

View File

@@ -47,7 +47,8 @@ git clone https://github.com/skwp/dotfiles ~/.yadr
cd ~/.yadr && rake install cd ~/.yadr && rake install
``` ```
Note: YADR will not destroy any of your files unless you tell it to. **Note:** YADR will automatically install all of its subcomponents. If you want to be asked
about each one, use `ASK=true rake install`
### Upgrading ### Upgrading

View File

@@ -4,9 +4,7 @@ desc "Hook our dotfiles into system-standard positions."
task :install => [:submodule_init, :submodules] do task :install => [:submodule_init, :submodules] do
puts puts
puts "======================================================" puts "======================================================"
puts "Welcome to YADR Installation. I'll ask you a few" puts "Welcome to YADR Installation."
puts "questions about which files to install. Nothing will"
puts "be overwritten without your consent."
puts "======================================================" puts "======================================================"
puts puts
@@ -40,11 +38,14 @@ task :update => [:install] do
end end
task :submodule_init do task :submodule_init do
unless ENV["SKIP_SUBMODULES"]
run %{ git submodule update --init --recursive } run %{ git submodule update --init --recursive }
end
end end
desc "Init and update submodules." desc "Init and update submodules."
task :submodules do task :submodules do
unless ENV["SKIP_SUBMODULES"]
puts "======================================================" puts "======================================================"
puts "Downloading YADR submodules...please wait" puts "Downloading YADR submodules...please wait"
puts "======================================================" puts "======================================================"
@@ -55,6 +56,7 @@ task :submodules do
git clean -dfx git clean -dfx
} }
puts puts
end
end end
task :default => 'install' task :default => 'install'
@@ -62,7 +64,6 @@ task :default => 'install'
private private
def run(cmd) def run(cmd)
puts
puts "[Running] #{cmd}" puts "[Running] #{cmd}"
`#{cmd}` unless ENV['DEBUG'] `#{cmd}` unless ENV['DEBUG']
end end
@@ -102,6 +103,7 @@ def install_fonts
end end
def install_prezto def install_prezto
puts
puts "Installing Prezto (ZSH Enhancements)..." puts "Installing Prezto (ZSH Enhancements)..."
unless File.exists?(File.join(ENV['ZDOTDIR'] || ENV['HOME'], ".zprezto")) unless File.exists?(File.join(ENV['ZDOTDIR'] || ENV['HOME'], ".zprezto"))
@@ -111,9 +113,11 @@ def install_prezto
file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy) file_operation(Dir.glob('zsh/prezto/runcoms/z*'), :copy)
end end
puts
puts "Overriding prezto ~/.zpreztorc with YADR's zpreztorc to enable additional modules..." puts "Overriding prezto ~/.zpreztorc with YADR's zpreztorc to enable additional modules..."
run %{ ln -nfs "$HOME/.yadr/zsh/prezto-override/zpreztorc" "${ZDOTDIR:-$HOME}/.zpreztorc" } run %{ ln -nfs "$HOME/.yadr/zsh/prezto-override/zpreztorc" "${ZDOTDIR:-$HOME}/.zpreztorc" }
puts
puts "Creating directories for your customizations" puts "Creating directories for your customizations"
run %{ mkdir -p $HOME/.zsh.before } run %{ mkdir -p $HOME/.zsh.before }
run %{ mkdir -p $HOME/.zsh.after } run %{ mkdir -p $HOME/.zsh.after }
@@ -121,41 +125,31 @@ def install_prezto
end end
def want_to_install? (section) def want_to_install? (section)
if ENV["ask"]=="true"
puts "Would you like to install configuration files for: #{section}? [y]es, [n]o" puts "Would you like to install configuration files for: #{section}? [y]es, [n]o"
STDIN.gets.chomp == 'y' STDIN.gets.chomp == 'y'
else
true
end
end end
def file_operation(files, method = :symlink) def file_operation(files, method = :symlink)
skip_all = false
overwrite_all = false
backup_all = false
files.each do |f| files.each do |f|
file = f.split('/').last file = f.split('/').last
source = "#{ENV["PWD"]}/#{f}" source = "#{ENV["PWD"]}/#{f}"
target = "#{ENV["HOME"]}/.#{file}" target = "#{ENV["HOME"]}/.#{file}"
puts "--------" puts "======================#{file}=============================="
puts "file: #{file}" puts "Source: #{source}"
puts "source: #{source}" puts "Target: #{target}"
puts "target: #{target}"
if File.exists?(target) || File.symlink?(target) if File.exists?(target) || File.symlink?(target)
unless skip_all || overwrite_all || backup_all puts "[Overwriting] #{target}...leaving original at #{target}.backup..."
puts "File already exists: #{target}, what do you want to do? [s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all" run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" }
case STDIN.gets.chomp
when 'o' then overwrite = true when 'b' then backup = true
when 'O' then overwrite_all = true
when 'B' then backup_all = true
when 'S' then skip_all = true
end
end
FileUtils.rm_rf(target) if overwrite || overwrite_all
run %{ mv "$HOME/.#{file}" "$HOME/.#{file}.backup" } if backup || backup_all
end end
if method == :symlink if method == :symlink
run %{ ln -s "#{source}" "#{target}" } run %{ ln -nfs "#{source}" "#{target}" }
else else
run %{ cp -f "#{source}" "#{target}" } run %{ cp -f "#{source}" "#{target}" }
end end
@@ -169,6 +163,8 @@ def file_operation(files, method = :symlink)
end end
end end
puts "=========================================================="
puts
end end
end end