2013-01-08 23:03:34 -05:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
require "optparse"
|
|
|
|
|
|
|
|
unless ENV["USER"] == "root"
|
|
|
|
exec "sudo", $0, *ARGV
|
|
|
|
end
|
|
|
|
|
2013-04-22 08:32:11 -04:00
|
|
|
all = false
|
|
|
|
force = false
|
|
|
|
opt = false
|
|
|
|
services = false
|
|
|
|
receipts = false
|
|
|
|
gitconfig = false
|
2013-01-08 23:03:34 -05:00
|
|
|
|
|
|
|
OptionParser.new do |o|
|
|
|
|
o.banner = "Remove most traces of Boxen from your machine."
|
|
|
|
|
2013-02-12 19:41:56 -05:00
|
|
|
o.on("--all", "Remove everything possible.") { all = true }
|
|
|
|
o.on("--force", "Actually do it.") { force = true }
|
|
|
|
o.on("--help", "Show this help.") { abort o.to_s }
|
|
|
|
o.on("--opt", "Remove /opt/boxen.") { opt = true }
|
|
|
|
o.on("--services", "Remove and unload services.") { services = true }
|
|
|
|
o.on("--receipts", "Remove package receipts used by Puppet.") { receipts = true }
|
|
|
|
o.on("--gitconfig", "Remove Boxen-provided git credential helper config.") { gitconfig = true }
|
2013-01-08 23:03:34 -05:00
|
|
|
|
|
|
|
o.parse!
|
|
|
|
|
2013-04-22 08:32:11 -04:00
|
|
|
abort o.to_s unless all || opt || services || receipts || gitconfig
|
2013-01-08 23:03:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
unless force
|
|
|
|
warn "** I won't actually do anything unless you pass --force."
|
|
|
|
end
|
|
|
|
|
|
|
|
if all || services
|
|
|
|
boxen_services = []
|
2013-02-12 19:41:56 -05:00
|
|
|
boxen_services << Dir["/Library/Launch*/dev.*.plist"]
|
2013-01-08 23:03:34 -05:00
|
|
|
|
|
|
|
boxen_services.flatten.each do |plist|
|
|
|
|
warn "-> Removing #{plist}."
|
|
|
|
|
|
|
|
if force
|
|
|
|
system "launchctl", "unload", "-w", plist
|
|
|
|
system "rm", "-f", plist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
system "rm", "-f", "/etc/resolver/dev"
|
|
|
|
end
|
|
|
|
|
|
|
|
if all || opt
|
|
|
|
warn "-> Removing /opt/boxen."
|
|
|
|
system "rm", "-rf", "/opt/boxen" if force
|
|
|
|
end
|
2013-02-12 19:41:56 -05:00
|
|
|
|
|
|
|
if all || receipts
|
|
|
|
warn "-> Removing /var/db/.puppet_*."
|
2013-02-28 22:13:33 -05:00
|
|
|
# can't use a bare system call here, because we need globbing.
|
|
|
|
system 'sh -c "rm -rf /var/db/.puppet_*"' if force
|
2013-02-12 19:41:56 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if all || gitconfig
|
|
|
|
warn "-> Removing git credential helper config."
|
|
|
|
system "/usr/bin/git", "config", "--global", "--unset", "credential.helper"
|
|
|
|
end
|