dust-deploy 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/changelog.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =============
3
3
 
4
+ 0.8.1
5
+ ------------
6
+
7
+ - introduces @node.cp and @node.mv
8
+ - adds cjdroute recipe: https://github.com/kechagia/dust-deploy/wiki/cjdroute/
9
+
10
+
4
11
  0.8.0
5
12
  ------------
6
13
 
@@ -0,0 +1,230 @@
1
+ require 'json'
2
+
3
+ class Cjdroute< Recipe
4
+ desc 'cjdroute:deploy', 'installs / updates cjdns'
5
+ def deploy
6
+ # apply default configuration
7
+ @config = default_config.merge @config
8
+
9
+ return unless install_dependencies
10
+ return unless get_latest_version
11
+ return unless @node.mkdir "#{@config['build_dir']}/build"
12
+
13
+ # clean up building directory, if --restart is given
14
+ # using --restart, since there's no --cleanup
15
+ return unless make_clean if @options.restart?
16
+
17
+ # compiling action
18
+ return unless run_cmake
19
+ return unless run_make
20
+
21
+ stop_cjdroute
22
+
23
+ # copy binary
24
+ return unless @node.mkdir @config['bin_dir']
25
+ return unless @node.cp "#{@config['build_dir']}/build/cjdroute", "#{@config['bin_dir']}/cjdroute"
26
+
27
+ # create the config file and place it into etc_dir
28
+ return unless generate_config
29
+
30
+ # create the tuntap interface
31
+ return unless create_tuntap
32
+
33
+ # add route for cjdns network
34
+ return unless add_route
35
+
36
+ start_cjdroute
37
+ end
38
+
39
+
40
+ private
41
+ def default_config
42
+ {
43
+ 'git_repo' => 'git://github.com/cjdelisle/cjdns.git',
44
+ 'build_dir' => '/tmp/cjdns-tmp',
45
+ 'bin_dir' => '/usr/local/bin',
46
+ 'etc_dir' => '/etc/cjdns/',
47
+ 'tun' => 'cjdroute0',
48
+ }
49
+ end
50
+
51
+ def public_peers
52
+ # list of public peers, taken from https://wiki.projectmeshnet.org/Public_peers
53
+ {
54
+ # derps nodes
55
+ '173.255.219.67:10000' => {
56
+ 'password' => 'null',
57
+ 'publicKey' => 'lj52930v1vmg3jqyb399us501svntt499bvgk0c1fud4pmy42gj0.k',
58
+ 'trust' => 5000,
59
+ 'authType' => 1
60
+ },
61
+
62
+ '96.126.112.124:10000' => {
63
+ 'password' => 'null',
64
+ 'publicKey' => '7zy1gb9bw4xp82kjvh66w01jdgh6y3lk7cfnl0pgb0xnn26b2jn0.k',
65
+ 'trust' => 5000,
66
+ 'authType' => 1
67
+ },
68
+
69
+ # rainfly x
70
+ '76.105.229.241:13982' => {
71
+ 'password' => 'general_public_1985',
72
+ 'publicKey' => '7pu8nlqphgd1bux9sdpjg0c104217r3b3m1bvmdtbn7uwcj5cky0.k',
73
+ 'trust' => 5000,
74
+ 'authType' => 1
75
+ },
76
+
77
+ # grey
78
+ '199.180.252.227:19081' => {
79
+ 'password' => 'public_7h4yTNEnRSEUvfFLtsM3',
80
+ 'publicKey' => 'z5htnv9jsj85b64cf61lbnl3dmqk5lpv3vxtz9g1jqlvb3b30b90.k',
81
+ 'trust' => 5000,
82
+ 'authType' => 1
83
+ },
84
+
85
+ # waaghals, expires 01.05.2012
86
+ '37.34.49.56:61530' => {
87
+ 'password' => 'public-expires-may-ghsfYATSvjh65SFgd',
88
+ 'publicKey' => 'jcvn5bvvfkxt3pmhj8bqzm6y20unc7cd5vuyhg01tmbh7bvswqq0.k',
89
+ 'trust' => 5000,
90
+ 'authType' => 1
91
+ }
92
+ }
93
+ end
94
+
95
+ # installs cmake, git and other building tools needed
96
+ def install_dependencies
97
+ ::Dust.print_msg "installing build dependencies\n"
98
+
99
+ return false unless @node.install_package 'cmake', :indent => 2
100
+
101
+ if @node.uses_apt?
102
+ return false unless @node.install_package 'git-core', :indent => 2
103
+ return false unless @node.install_package 'build-essential', :indent => 2
104
+ return false unless @node.install_package 'coreutils', :indent => 2
105
+ elsif @node.uses_rpm?
106
+ return false unless @node.install_package 'git', :indent => 2
107
+ return false unless @node.install_package 'make', :indent => 2
108
+ else
109
+ return ::Dust.print_failed 'sorry, your os is not supported by this script'
110
+ end
111
+
112
+ puts
113
+ true
114
+ end
115
+
116
+ # gets/updates latest version from cjdns git repository
117
+ def get_latest_version
118
+ if @node.dir_exists? @config['build_dir'], :quiet => true
119
+
120
+ # check if build directory is maintained by git
121
+ unless @node.dir_exists? "#{@config['build_dir']}/.git", :quiet => true
122
+ return ::Dust.print_failed "#{@config['build_dir']} doesn't appear to be a git repository"
123
+ end
124
+
125
+ # git pull latest changes
126
+ ::Dust.print_msg "pulling latest changes from repository\n"
127
+ ret = @node.exec "cd #{@config['build_dir']}; git pull", :live => true
128
+ return ::Dust.print_failed 'error pulling from git repository' unless ret[:exit_code] == 0
129
+
130
+ else
131
+ # create build directory
132
+ unless @node.mkdir @config['build_dir']
133
+ return ::Dust.print_failed "couldn't create build directory #{@config['build_dir']}"
134
+ end
135
+
136
+ # git clone cjdns repository
137
+ ::Dust.print_msg "cloning cjdns repository into #{@config['build_dir']}\n"
138
+ ret = @node.exec "git clone #{@config['git_repo']} #{@config['build_dir']}", :live => true
139
+ return ::Dust.print_failed 'error cloning git repository' unless ret[:exit_code] == 0
140
+ end
141
+
142
+ puts
143
+ true
144
+ end
145
+
146
+ # remove and recreate building directory
147
+ def make_clean
148
+ ::Dust.print_msg 'cleaning build directory'
149
+ return false unless ::Dust.print_result @node.exec("rm -rf #{@config['build_dir']}/build")[:exit_code]
150
+ true
151
+ end
152
+
153
+
154
+ def run_cmake
155
+ ::Dust.print_msg "running cmake\n"
156
+ ret = @node.exec "cd #{@config['build_dir']}/build; cmake ..", :live => true
157
+ return ::Dust.print_failed 'error running cmake' unless ret[:exit_code] == 0
158
+ true
159
+ end
160
+
161
+ def run_make
162
+ ::Dust.print_msg "compiling cjdns\n"
163
+ ret = @node.exec "cd #{@config['build_dir']}/build; make", :live => true
164
+ return ::Dust.print_failed 'error compiling cjdroute' unless ret[:exit_code] == 0
165
+ true
166
+ end
167
+
168
+ # generate cjdroute.conf
169
+ def generate_config
170
+ if @node.file_exists? "#{@config['etc_dir']}/cjdroute.conf", :quiet => true
171
+ ::Dust.print_warning 'found a cjdroute.conf, not overwriting'
172
+ return true
173
+ end
174
+
175
+ ::Dust.print_msg 'generating config file'
176
+ ret = @node.exec("#{@config['bin_dir']}/cjdroute --genconf")
177
+ return false unless ::Dust.print_result ret[:exit_code]
178
+
179
+ # parse generated json
180
+ cjdroute_conf = JSON.parse ret[:stdout]
181
+
182
+ # add some public peers, so we can get started directly
183
+ ::Dust.print_msg 'adding public peers', :indent => 2
184
+ cjdroute_conf['interfaces']['UDPInterface']['connectTo'] = public_peers
185
+ ::Dust.print_ok
186
+
187
+ # exchange tun0 with configured tun device
188
+ cjdroute_conf['router']['interface']['tunDevice'] = @config['tun']
189
+
190
+ return false unless @node.mkdir @config['etc_dir']
191
+ return @node.write "#{@config['etc_dir']}/cjdroute.conf", JSON.pretty_generate(cjdroute_conf)
192
+ end
193
+
194
+ # creates the cjdroute tuntap device
195
+ def create_tuntap
196
+ unless @node.exec("/sbin/ip tuntap list |grep #{@config['tun']}")[:exit_code] == 0
197
+ ::Dust.print_msg "creating tun interface #{@config['tun']}"
198
+ return false unless ::Dust.print_result @node.exec("/sbin/ip tuntap add mode tun dev #{@config['tun']}")[:exit_code]
199
+ else
200
+ ::Dust.print_msg "tun interface #{@config['tun']} already exists, flushing ip addresses"
201
+ ::Dust.print_result @node.exec("ip addr flush dev #{@config['tun']}")[:exit_code]
202
+ end
203
+
204
+ true
205
+ end
206
+
207
+ # set the route for the cjdns network
208
+ def add_route
209
+ ::Dust.print_msg 'getting routing information'
210
+ ret = @node.exec "#{@config['bin_dir']}/cjdroute --getcmds < #{@config['etc_dir']}/cjdroute.conf"
211
+ return false unless ::Dust.print_result ret[:exit_code]
212
+
213
+ ::Dust.print_msg 'applying cjdns routes'
214
+ ::Dust.print_result @node.exec(ret[:stdout])[:exit_code]
215
+ end
216
+
217
+ # kill any cjdroute processes that might be running
218
+ def stop_cjdroute
219
+ ::Dust.print_msg 'stopping cjdroute'
220
+ pids = @node.exec("ps ax |grep cjdroute |grep -v grep |awk '{print $1}'")[:stdout]
221
+ pids.each_line { |pid| @node.exec "kill #{pid}" }
222
+ ::Dust.print_ok
223
+ end
224
+
225
+ # fire up cjdroute
226
+ def start_cjdroute
227
+ ::Dust.print_msg 'fireing up cjdroute'
228
+ ::Dust.print_result @node.exec("nohup #{@config['bin_dir']}/cjdroute < #{@config['etc_dir']}/cjdroute.conf &> /dev/null &")[:exit_code]
229
+ end
230
+ end
data/lib/dust/server.rb CHANGED
@@ -190,6 +190,26 @@ module Dust
190
190
  Dust.print_result exec("rm -rf #{file}")[:exit_code], options
191
191
  end
192
192
 
193
+ def cp source, destination, options = {}
194
+ options = default_options.merge options
195
+
196
+ # get rid of overly careful aliases
197
+ exec 'unalias -a'
198
+
199
+ Dust.print_msg "copying #{source} to #{destination}", options
200
+ Dust.print_result exec("cp -a #{source} #{destination}")[:exit_code], options
201
+ end
202
+
203
+ def mv source, destination, options = {}
204
+ options = default_options.merge options
205
+
206
+ # get rid of overly careful aliases
207
+ exec 'unalias -a'
208
+
209
+ Dust.print_msg "moving #{source} to #{destination}", options
210
+ Dust.print_result exec("mv #{source} #{destination}")[:exit_code], options
211
+ end
212
+
193
213
  def mkdir dir, options = {}
194
214
  options = default_options.merge options
195
215
 
data/lib/dust/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dust
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 8
8
- - 0
9
- version: 0.8.0
8
+ - 1
9
+ version: 0.8.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - kris kechagia
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2012-03-07 00:00:00 +01:00
17
+ date: 2012-03-12 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -123,6 +123,7 @@ files:
123
123
  - lib/dust/recipe.rb
124
124
  - lib/dust/recipes/aliases.rb
125
125
  - lib/dust/recipes/basic_setup.rb
126
+ - lib/dust/recipes/cjdroute.rb
126
127
  - lib/dust/recipes/cups_client.rb
127
128
  - lib/dust/recipes/debsecan.rb
128
129
  - lib/dust/recipes/duplicity.rb