-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.rb
executable file
·64 lines (47 loc) · 1.51 KB
/
setup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
require 'ap'
require 'trollop'
require './lib/packager.rb'
SETUP_VERSION = "0.1-0"
opts = Trollop::options do
version "Dot Files Setup #{SETUP_VERSION}"
banner <<-EOS
This script setups the dot files included in this distribution
Usage:
setup.rb [options]
where [options] are:
EOS
opt :include, "Packages to include", :short => 'i', :multi => true, :type => String, :default => nil
opt :exclude, "Packages to exlude", :short => 'e', :multi => true, :type => String, :default => nil
opt :remove, "Packages to exlude", :short => 'r'
opt :list, "Packages that can be installed", :short => 'l'
end
def print_packages(header, packages)
puts header
packages.each do |package|
puts " |--#{package}"
end
end
def confirm(message = "Are you sure you wish to continue")
print "#{message} (y/N): "
responce = gets.chomp.upcase
return responce =~/^Y$/
end
available = Packager.available_setups
if opts[:list]
print_packages("Available Packages:", available)
exit
end
unless opts[:include].empty? or opts[:exclude].empty?
puts "Options --include (-i) and --exclude (-e) are exclusive"
exit -1
end
available = available & opts[:include] unless opts[:include].empty?
available = available - opts[:exclude] unless opts[:exclude].empty?
if opts[:remove]
print_packages("Removing Packages:", available)
Packager.remove_packages(available) if confirm
exit
end
print_packages("Installing Packages:", available)
Packager.install_packages(available) if confirm