Blame view

script/nuke 1.73 KB
fdb27960f   Will Farrington   Update template w...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #!/usr/bin/ruby
  
  require "optparse"
  
  unless ENV["USER"] == "root"
    exec "sudo", $0, *ARGV
  end
  
  all      = false
  force    = false
  opt      = false
  services = false
  
  OptionParser.new do |o|
    o.banner = "Remove most traces of Boxen from your machine."
d4af4bf81   Will Farrington   Update our boxen ...
16
17
18
19
20
21
22
    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 }
fdb27960f   Will Farrington   Update template w...
23
24
25
26
27
28
29
30
31
32
33
34
  
    o.parse!
  
    abort o.to_s unless all || opt || services
  end
  
  unless force
    warn "** I won't actually do anything unless you pass --force."
  end
  
  if all || services
    boxen_services = []
d4af4bf81   Will Farrington   Update our boxen ...
35
    boxen_services << Dir["/Library/Launch*/dev.*.plist"]
fdb27960f   Will Farrington   Update template w...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  
    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
d4af4bf81   Will Farrington   Update our boxen ...
53
54
55
56
57
58
59
60
61
62
  
  if all || receipts
    warn "-> Removing /var/db/.puppet_*."
    system "rm", "-rf", "/var/db/.puppet_*" if force
  end
  
  if all || gitconfig
    warn "-> Removing git credential helper config."
    system "/usr/bin/git", "config", "--global", "--unset", "credential.helper"
  end