-
Notifications
You must be signed in to change notification settings - Fork 1
/
destroy-everything.rb
84 lines (60 loc) · 1.58 KB
/
destroy-everything.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require_relative '__init__'
# Change directory to path of __init__.rb
Dir.chdir absolute_root_path
require 'optparse'
# Global variable to not actually delete files.
# True prevents files from being deleted.
DRY_RUN = FALSE
puts "Operating in this path:"
puts Dir.pwd
def destroy_vagrant_boxes
cmd = "vagrant destroy -f"
puts "Executing `#{cmd}`..."
sleep(5)
if not DRY_RUN
system(cmd)
else
puts "Not actually going to run `#{cmd}` as DRY_RUN=#{DRY_RUN}."
end
end
def destroy_packer_output(path)
path = File.absolute_path path
puts "About to DEL '#{File.absolute_path path}'!"
Dir.glob path do |boxfile|
puts "DEL #{boxfile}"
if not DRY_RUN
File.delete boxfile
else
puts "Not actually going to delete as DRY_RUN=#{DRY_RUN}."
end
end
end
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} [options]"
opts.on("-f", "--force", "Destroy everything without prompts.") do |v|
options[:force] = v
end
end.parse!
p options
p ARGV
if options[:force]
puts "Forcefully removing ALL vagrant boxes AND packer artifacts..."
puts "You have 5 seconds to cancel (CTRL-C!)"
sleep(5)
end
if not options[:force]
puts("Hold on! You're about to destroy ALL vagrant boxes and ALL packer artifacts!")
puts("This could take hours to undo!")
puts("Are you sure you want to do this? (yes/no)")
print (" > ")
inp = gets.chomp
if inp == "yes"
puts "Continuing!"
else
puts "Aborting!"
exit(1)
end
end
destroy_vagrant_boxes
destroy_packer_output(File.join absolute_root_path, "packer/output/*.box")