installer: refactor install

This commit is contained in:
rkiel
2017-11-09 09:43:22 -05:00
parent 6c83679f45
commit 8ab709a43e
4 changed files with 104 additions and 32 deletions

13
install
View File

@@ -1,13 +0,0 @@
echo 'export GIT_UTILITIES_BIN="~/GitHub/rkiel/git-utilities/bin"' >> ~/.bash_profile
echo 'export PATH=${GIT_UTILITIES_BIN}:$PATH' >> ~/.bash_profile
echo 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-completion.bash' >> ~/.bash_profile
echo 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-prompt.sh' >> ~/.bash_profile
echo "export FEATURE_USER=$1" >> ~/.bash_profile
echo 'source ~/GitHub/rkiel/git-utilities/dotfiles/bashrc' >> ~/.bashrc

10
install/bin/setup Executable file
View File

@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
require_relative '../lib/setup/commander'
commander = Setup::Commander.new(ARGV)
if commander.valid?
commander.execute
else
commander.help
end

View File

@@ -0,0 +1,91 @@
require 'ostruct'
require 'optparse'
require 'json'
module Setup
class Commander
attr_accessor :options
def initialize (argv)
@options = OpenStruct.new
@option_parser = OptionParser.new do |op|
op.banner = "Usage: setup options"
op.on('-u','--user USER') do |argument|
options.user = argument
end
op.on_tail('-h','--help') do |argument|
puts op
exit
end
end
@option_parser.parse!(argv)
options.terms = argv # must be after parse!
end
def valid?
options.user
end
def help
puts @option_parser
exit
end
def execute
action = options.action
File.open("#{ENV['HOME']}/.bash_profile", "a") do |f|
f.puts
f.puts '#############################################################'
f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup"
f.puts '#############################################################'
f.puts 'export GIT_UTILITIES_BIN="~/GitHub/rkiel/git-utilities/bin"'
f.puts 'export PATH=${GIT_UTILITIES_BIN}:$PATH'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-completion.bash'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/git-prompt.sh'
f.puts "export FEATURE_USER=#{options.user}" if options.user
f.puts '#############################################################'
f.puts
end
File.open("#{ENV['HOME']}/.bashrc", "a") do |f|
f.puts
f.puts '#############################################################'
f.puts "# added by ~/GitHub/rkiel/git-utilities/install/bin/setup"
f.puts '#############################################################'
f.puts 'source ~/GitHub/rkiel/git-utilities/dotfiles/bashrc'
f.puts '#############################################################'
f.puts
end
end
private
def run_cmd ( cmd )
puts
puts cmd
success = system cmd
unless success
error "(see above)"
end
puts
end
def error ( msg )
puts
puts "ERROR: #{msg}"
puts
exit
end
end
end