-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRakefile
136 lines (110 loc) · 3.7 KB
/
Rakefile
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'cucumber'
require 'cucumber/rake/task'
require 'colorize'
require 'pathname'
$: << Pathname.new(__FILE__).join('lib').expand_path.to_s
require 'ript/version'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end
desc "Build packages for various platforms"
#task :build => [ 'build:gem', 'build:deb' ]
task :build => [ :verify, 'build:gem', 'build:deb' ]
namespace :build do
desc "Build RubyGem"
task :gem do
build_output = `gem build ript.gemspec`
puts build_output
gem_filename = build_output[/File: (.*)/,1]
pkg_path = "pkg"
FileUtils.mkdir_p(pkg_path)
FileUtils.mv(gem_filename, pkg_path)
puts "Gem built at #{pkg_path}/#{gem_filename}".green
end
desc "Build a deb for Ubuntu"
task :deb => :gem do
gem_filename = "pkg/ript-#{Ript::VERSION}.gem"
deb_filename = "pkg/ript-#{Ript::VERSION}.deb"
system("rm -f #{deb_filename}")
build_output = `fpm -s gem -t deb -p #{deb_filename} #{gem_filename}`
require 'json'
json = build_output[/({.+})$/, 1]
data = JSON.parse(json)
if path = data["path"]
puts "Deb built at #{path}".green
end
end
end
namespace :verify do
desc "Verify the CHANGELOG is in order for a release"
task :changelog do
changelog_filename = "CHANGELOG.md"
version = Ript::VERSION
command = "grep '^# #{version}' #{changelog_filename} 2>&1 >/dev/null"
if not system(command)
puts "#{changelog_filename} doesn't have an entry for the version (#{version}) you are about to build.".red
exit 1
end
end
desc "Verify there are no uncommitted files"
task :uncommitted do
uncommitted = `git ls-files -m`.split("\n")
if uncommitted.size > 0
puts "The following files are uncommitted:".red
uncommitted.each do |filename|
puts " - #{filename}".red
end
exit 1
end
end
desc "Verify no requires of RubyGems have snuck in"
task :no_rubygems do
requires = `grep rubygems lib/ bin/ -rn |grep require`.split("\n")
if requires.size > 0
puts "The following files use RubyGems:".red
requires.each do |filename|
puts " - #{filename}".red
end
exit 1
end
end
task :all => [ :changelog, :uncommitted, :no_rubygems ]
end
task :verify => 'verify:all'
desc "Clean out the state of iptables"
task :clean_slate do
# Clean filter
system("sudo iptables --flush --table filter")
system("sudo iptables --delete-chain --table filter")
system("sudo iptables --table filter --policy INPUT ACCEPT")
system("sudo iptables --table filter --policy FORWARD ACCEPT")
system("sudo iptables --table filter --policy OUTPUT ACCEPT")
# Clean NAT
system("sudo iptables --flush --table nat")
system("sudo iptables --delete-chain --table nat")
system("sudo iptables --table nat --policy PREROUTING ACCEPT")
system("sudo iptables --table nat --policy POSTROUTING ACCEPT")
system("sudo iptables --table nat --policy OUTPUT ACCEPT")
# Clean mangle
system("sudo iptables --flush --table mangle")
system("sudo iptables --delete-chain --table mangle")
system("sudo iptables --table mangle --policy PREROUTING ACCEPT")
system("sudo iptables --table mangle --policy POSTROUTING ACCEPT")
system("sudo iptables --table mangle --policy INPUT ACCEPT")
system("sudo iptables --table mangle --policy FORWARD ACCEPT")
system("sudo iptables --table mangle --policy OUTPUT ACCEPT")
# Verify
puts "### FILTER ###"
system("sudo iptables --list --table filter")
puts
puts "### NAT ###"
system("sudo iptables --list --table nat")
puts
puts "### MANGLE ###"
system("sudo iptables --list --table mangle")
puts
end