1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | my $gb = $ENV{ "GENAPP" }; |
---|
4 | if ( !$gb ) { |
---|
5 | use Cwd 'abs_path'; |
---|
6 | $gb = abs_path($0); |
---|
7 | $gb =~ s/\/sbin\/setconfig\.pl$//; |
---|
8 | } |
---|
9 | |
---|
10 | if ( $] < 5.018 ) { |
---|
11 | if ( -e "$gb/perl/bin/perl" ) { |
---|
12 | $pv =`$gb/perl/bin/perl -e 'print \$];'`; |
---|
13 | if ( $pv >= 5.018 ) { |
---|
14 | print "will run new version\n" if $debug; |
---|
15 | unshift @ARGV, $0; |
---|
16 | exec( "$gb/perl/bin/perl", @ARGV ); |
---|
17 | } else { |
---|
18 | die "$gb/perl/bin/perl exists, but not a correct version of perl (needs a minimum of 5.18)\n"; |
---|
19 | } |
---|
20 | } else { |
---|
21 | die "you need to install a version of perl >= 5.18 in $gb/perl\n |
---|
22 | there is a script $gb/sbin/install-perl-stable to do this"; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | my $rc = eval { |
---|
27 | require JSON; JSON->import( -support_by_pp ); |
---|
28 | }; |
---|
29 | |
---|
30 | my $notes = " |
---|
31 | usage: $0 |
---|
32 | |
---|
33 | sets up $gb/config.json |
---|
34 | |
---|
35 | options |
---|
36 | -f force overwrite of identified values to those previously stored |
---|
37 | -h show help |
---|
38 | -hostip hostip use specified host ip address |
---|
39 | -hostname hostname use specified host name |
---|
40 | -if network-interface-id find and set hostip from that of specified interface (e.g. eth0, eth1, lo, etc) |
---|
41 | -pj print resulting config.json |
---|
42 | -https use https and wss |
---|
43 | -webroot webroot specify the webroot directory |
---|
44 | -mongossl hostname cafile specify the hostname and certificate file for mongod |
---|
45 | "; |
---|
46 | |
---|
47 | my $pj; |
---|
48 | my $fo; |
---|
49 | my $hostip; |
---|
50 | my $hostname; |
---|
51 | my $https = 0; |
---|
52 | my $webroot; |
---|
53 | |
---|
54 | while ( @ARGV ) { |
---|
55 | my $option = shift @ARGV; |
---|
56 | if ( $option =~ /^-f$/ ) { |
---|
57 | $fo = 1; |
---|
58 | next; |
---|
59 | } |
---|
60 | if ( $option =~ /^-if$/ ) { |
---|
61 | die "$0: option $option requries an argument\n" . $notes if !@ARGV; |
---|
62 | my $if = shift @ARGV; |
---|
63 | my $cmd = "/sbin/ip -4 addr show $if | grep inet | awk '{ print \$2 }' | sed 's/\\\/.*\$//'"; |
---|
64 | $hostip = `$cmd`; |
---|
65 | chomp $hostip; |
---|
66 | die "$0: could not get hostip of interface $if\n" if !$hostip; |
---|
67 | next; |
---|
68 | } |
---|
69 | if ( $option =~ /^-hostip$/ ) { |
---|
70 | die "$0: option $option requries an argument\n" . $notes if !@ARGV; |
---|
71 | $hostip = shift @ARGV; |
---|
72 | next; |
---|
73 | } |
---|
74 | if ( $option =~ /^-hostname$/ ) { |
---|
75 | die "$0: option $option requries an argument\n" . $notes if !@ARGV; |
---|
76 | $hostname = shift @ARGV; |
---|
77 | next; |
---|
78 | } |
---|
79 | if ( $option =~ /^-webroot$/ ) { |
---|
80 | die "$0: option $option requries an argument\n" . $notes if !@ARGV; |
---|
81 | $webroot = shift @ARGV;; |
---|
82 | next; |
---|
83 | } |
---|
84 | if ( $option =~ /^-h$/ ) { |
---|
85 | print $notes; |
---|
86 | exit; |
---|
87 | } |
---|
88 | if ( $option =~ /^-pj$/ ) { |
---|
89 | $pj++; |
---|
90 | next; |
---|
91 | } |
---|
92 | if ( $option =~ /^-https$/ ) { |
---|
93 | $https++; |
---|
94 | next; |
---|
95 | } |
---|
96 | if ( $option =~ /^-mongossl$/ ) { |
---|
97 | $mongosslhost = shift @ARGV; |
---|
98 | $mongourl = "mongodb://${mongosslhost}:27017/?ssl=true"; |
---|
99 | die "$0: option $option requries two arguments\n" . $notes if !@ARGV; |
---|
100 | $mongocafile = shift @ARGV; |
---|
101 | next; |
---|
102 | } |
---|
103 | |
---|
104 | die "Unknown command line option specified '$option'\n" . $notes; |
---|
105 | } |
---|
106 | |
---|
107 | my $f = "$gb/etc/config.json"; |
---|
108 | |
---|
109 | my $json = {}; |
---|
110 | |
---|
111 | if ( -e $f ) { |
---|
112 | print "reading $f\n"; |
---|
113 | open my $fh, $f || die "$0: can not open $f\n"; |
---|
114 | my @ol = <$fh>; |
---|
115 | close $fh; |
---|
116 | my @l = grep !/^\s*#/ , @ol; |
---|
117 | my $l = join '', @l; |
---|
118 | eval { |
---|
119 | $json = decode_json( $l ); |
---|
120 | 1; |
---|
121 | } || do { |
---|
122 | my $e = $@; |
---|
123 | |
---|
124 | # figure out line # |
---|
125 | |
---|
126 | my ( $cp ) = $e =~ /at character offset (\d+) /; |
---|
127 | my $i; |
---|
128 | my $cpos = $cp; |
---|
129 | for ( $i = 0; $i < @ol; ++$i ) { |
---|
130 | next if $ol[ $i ] =~ /^\s*#/; |
---|
131 | $cpos -= length( $ol[ $i ] ); |
---|
132 | last if $cpos < 0; |
---|
133 | } |
---|
134 | |
---|
135 | my $sline = $i - 2; |
---|
136 | my $eline = $i + 2; |
---|
137 | $sline = 0 if $sline < 0; |
---|
138 | $eline = @ol - 1 if $eline >= @ol; |
---|
139 | |
---|
140 | print "JSON Error in file $f near these lines:\n"; |
---|
141 | for ( my $j = $sline; $j <= $eline; ++$j ) { |
---|
142 | my $uj = $j + 1; |
---|
143 | print "$uj: $ol[$j]"; |
---|
144 | print "$uj: " .'^'x(length($ol[$j])) . "\n" if $j == $i; |
---|
145 | } |
---|
146 | die; |
---|
147 | }; |
---|
148 | } |
---|
149 | |
---|
150 | # determine os |
---|
151 | |
---|
152 | my $tos = `uname -v`; |
---|
153 | my $os; |
---|
154 | my $os_release; |
---|
155 | |
---|
156 | $os = 'ubuntu' if $tos =~ /Ubuntu/; |
---|
157 | |
---|
158 | if ( $os eq 'ubuntu' ) { |
---|
159 | $os_release = `lsb_release -r | awk '{ print \$2 }'`; |
---|
160 | chomp $os_release; |
---|
161 | } |
---|
162 | |
---|
163 | if ( !$os && -e "/etc/redhat-release" ) { |
---|
164 | # check for centos/redhat |
---|
165 | my $check = `cat /etc/redhat-release`; |
---|
166 | chomp $check; |
---|
167 | if ( $check =~ /^CentOS .* release/ ) { |
---|
168 | $os = "centos"; |
---|
169 | ( $os_release ) = $check =~ /^CentOS .* release (\S+)/; |
---|
170 | |
---|
171 | } else { |
---|
172 | if ( $check =~ /^CentOS release/ ) { |
---|
173 | $os = "centos"; |
---|
174 | ( $os_release ) = $check =~ /^CentOS release (\S+)/; |
---|
175 | } |
---|
176 | } |
---|
177 | if ( $check =~ /^Red Hat Enterprise Linux Server release/ ) { |
---|
178 | $os = "redhat"; |
---|
179 | ( $os_release ) = $check =~ /^Red Hat Enterprise Linux Server release (\S+)/; |
---|
180 | } |
---|
181 | if ( $check =~ /^Scientific Linux release/ ) { |
---|
182 | $os = "scientific"; |
---|
183 | ( $os_release ) = $check =~ /^Scientific Linux release (\S+)/; |
---|
184 | if ( -e "/etc/cernvm-release" ) { |
---|
185 | $os_release .= "-cernvm"; |
---|
186 | } |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | if ( !$os && -e "/etc/slackware-version" ) { |
---|
191 | my $check = `cat /etc/slackware-version`; |
---|
192 | $os = "slackware"; |
---|
193 | ( $os_release ) = $check =~ /^Slackware (\S+)/; |
---|
194 | } |
---|
195 | |
---|
196 | if ( !os ) { |
---|
197 | warn "$0: operating system not recognized\n"; |
---|
198 | } |
---|
199 | |
---|
200 | print "Operating system is identified as '$os' release '$os_release'\n"; |
---|
201 | |
---|
202 | my $notice; |
---|
203 | |
---|
204 | if ( $$json{'os'} ) { |
---|
205 | if ( $$json{'os'} ne $os ) { |
---|
206 | $notice .= "The identified operating system [$os] is different than that stored [$$json{'os'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
207 | } else { |
---|
208 | if ( $$json{'os_release'} ne $os_release ) { |
---|
209 | $notice .= "The identified $os release [$os_release] is different than that stored [$$json{'os_release'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
210 | } |
---|
211 | } |
---|
212 | if ( $fo ) { |
---|
213 | $$json{ 'os' } = $os; |
---|
214 | $$json{ 'os_release' } = $os_release; |
---|
215 | } |
---|
216 | } else { |
---|
217 | $$json{ 'os' } = $os; |
---|
218 | $$json{ 'os_release' } = $os_release; |
---|
219 | } |
---|
220 | |
---|
221 | if ( !$hostip ) { |
---|
222 | my $foundwgetorcurl; |
---|
223 | if ( `which wget 2> /dev/null` ) { |
---|
224 | $hostip = `wget http://ipinfo.io/ip -qO -`; |
---|
225 | chomp $hostip; |
---|
226 | $foundwgetorcurl++; |
---|
227 | } else { |
---|
228 | if ( `which curl 2> /dev/null` ) { |
---|
229 | $cmd = 'curl -q ipinfo.io 2> /dev/null | grep \'"ip":\' | awk \'{ print $2 }\' | sed s/,// | sed s/\"//g'; |
---|
230 | $hostip = `$cmd`; |
---|
231 | chomp $hostip; |
---|
232 | $foundwgetorcurl++; |
---|
233 | } |
---|
234 | } |
---|
235 | die "$0: please install wget or curl so that your public ip address can be determined" if !$foundwgetorcurl; |
---|
236 | } |
---|
237 | |
---|
238 | if ( $$json{'hostip'} ) { |
---|
239 | if ( $$json{'hostip'} ne $hostip ) { |
---|
240 | $notice .= "The identified hostip for this server [$hostip] is different than that stored [$$json{'hostip'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
241 | } |
---|
242 | if ( $fo ) { |
---|
243 | $$json{ 'hostip' } = $hostip; |
---|
244 | } |
---|
245 | } else { |
---|
246 | $$json{ 'hostip' } = $hostip; |
---|
247 | } |
---|
248 | |
---|
249 | if ( !$hostname ) { |
---|
250 | $hostname = `host $hostip` if !$hostname; |
---|
251 | chomp $hostname; |
---|
252 | if ( $hostname =~ /(not found|no PTR record)/ ) { |
---|
253 | $hostname = $hostip; |
---|
254 | } else { |
---|
255 | ( $hostname ) = $hostname =~ /\s+(\S+)\.$/; |
---|
256 | } |
---|
257 | } |
---|
258 | |
---|
259 | if ( $$json{'hostname'} ) { |
---|
260 | if ( $$json{'hostname'} ne $hostname ) { |
---|
261 | $notice .= "The identified hostname for this server [$hostname] is different than that stored [$$json{'hostname'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
262 | } |
---|
263 | if ( $fo ) { |
---|
264 | $$json{ 'hostname' } = $hostname; |
---|
265 | } |
---|
266 | } else { |
---|
267 | $$json{ 'hostname' } = $hostname; |
---|
268 | } |
---|
269 | |
---|
270 | $hostname = $$json{ 'hostname' }; |
---|
271 | # verify hostname matches ip address |
---|
272 | { |
---|
273 | my $nametoip; |
---|
274 | if ( `which dig 2> /dev/null` ) { |
---|
275 | $nametoip = `dig \@8.8.8.8 +short $hostname`; |
---|
276 | } else { |
---|
277 | $nametoip = `host $hostname | awk '/has address/ { print \$4 }'`; |
---|
278 | } |
---|
279 | chomp $nametoip; |
---|
280 | if ( $nametoip ne $hostip ) { |
---|
281 | $notice .= "WARNING: the ip address from a DNS lookup [$nametoip] of the hostname [$hostname] does not match the hostip [$hostip]. This will create issues unless you really understand what you are doing!\n"; |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | |
---|
286 | my $wssport = $https ? 443 : 80; |
---|
287 | my $wsport = 30777; |
---|
288 | my $zmqport = 30778; |
---|
289 | my $zmqhostip = "127.0.0.1"; |
---|
290 | my $udpport = 30779; |
---|
291 | my $udphostip = "127.0.0.1"; |
---|
292 | my $tcpport = 30780; |
---|
293 | my $tcphostip = "127.0.0.1"; |
---|
294 | my $tcprport = 30781; |
---|
295 | my $tcptimeout = 300; |
---|
296 | |
---|
297 | if ( $$json{ "messaging" }{ "wssport" } ) { |
---|
298 | if ( $$json{'messaging'}{'wssport'} != $wssport ) { |
---|
299 | $notice .= "The identified wssport for this server [$wssport] is different than that stored [$$json{'messaging'}{'wssport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
300 | } |
---|
301 | if ( $fo ) { |
---|
302 | $$json{ 'messaging'}{'wssport' } = $wssport; |
---|
303 | } |
---|
304 | } else { |
---|
305 | $$json{ 'messaging'}{'wssport' } = $wssport; |
---|
306 | } |
---|
307 | |
---|
308 | if ( $$json{ "messaging" }{ "wsport" } ) { |
---|
309 | if ( $$json{'messaging'}{'wsport'} != $wsport ) { |
---|
310 | $notice .= "The identified wsport for this server [$wsport] is different than that stored [$$json{'messaging'}{'wsport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
311 | } |
---|
312 | if ( $fo ) { |
---|
313 | $$json{ 'messaging'}{'wsport' } = $wsport; |
---|
314 | } |
---|
315 | } else { |
---|
316 | $$json{ 'messaging'}{'wsport' } = $wsport; |
---|
317 | } |
---|
318 | |
---|
319 | if ( $$json{ "messaging" }{ "zmqport" } ) { |
---|
320 | if ( $$json{'messaging'}{'zmqport'} != $zmqport ) { |
---|
321 | $notice .= "The identified zmqport for this server [$zmqport] is different than that stored [$$json{'messaging'}{'zmqport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
322 | } |
---|
323 | if ( $fo ) { |
---|
324 | $$json{ 'messaging'}{'zmqport' } = $zmqport; |
---|
325 | } |
---|
326 | } else { |
---|
327 | $$json{ 'messaging'}{'zmqport' } = $zmqport; |
---|
328 | } |
---|
329 | |
---|
330 | if ( $$json{ "messaging" }{ "zmqhostip" } ) { |
---|
331 | if ( $$json{'messaging'}{'zmqhostip'} ne $zmqhostip ) { |
---|
332 | $notice .= "The identified zmqhostip for this server [$zmqhostip] is different than that stored [$$json{'messaging'}{'zmqhostip'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
333 | } |
---|
334 | if ( $fo ) { |
---|
335 | $$json{ 'messaging'}{'zmqhostip' } = $zmqhostip; |
---|
336 | } |
---|
337 | } else { |
---|
338 | $$json{ 'messaging'}{'zmqhostip' } = $zmqhostip; |
---|
339 | } |
---|
340 | |
---|
341 | if ( $$json{ "messaging" }{ "udpport" } ) { |
---|
342 | if ( $$json{'messaging'}{'udpport'} != $udpport ) { |
---|
343 | $notice .= "The identified udpport for this server [$udpport] is different than that stored [$$json{'messaging'}{'udpport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
344 | } |
---|
345 | if ( $fo ) { |
---|
346 | $$json{ 'messaging'}{'udpport' } = $udpport; |
---|
347 | } |
---|
348 | } else { |
---|
349 | $$json{ 'messaging'}{'udpport' } = $udpport; |
---|
350 | } |
---|
351 | |
---|
352 | if ( $$json{ "messaging" }{ "udphostip" } ) { |
---|
353 | if ( $$json{'messaging'}{'udphostip'} ne $udphostip ) { |
---|
354 | $notice .= "The identified udphostip for this server [$udphostip] is different than that stored [$$json{'messaging'}{'udphostip'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
355 | } |
---|
356 | if ( $fo ) { |
---|
357 | $$json{ 'messaging'}{'udphostip' } = $udphostip; |
---|
358 | } |
---|
359 | } else { |
---|
360 | $$json{ 'messaging'}{'udphostip' } = $udphostip; |
---|
361 | } |
---|
362 | |
---|
363 | if ( $$json{ "messaging" }{ "tcpport" } ) { |
---|
364 | if ( $$json{'messaging'}{'tcpport'} != $tcpport ) { |
---|
365 | $notice .= "The identified tcpport for this server [$tcpport] is different than that stored [$$json{'messaging'}{'tcpport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
366 | } |
---|
367 | if ( $fo ) { |
---|
368 | $$json{ 'messaging'}{'tcpport' } = $tcpport; |
---|
369 | } |
---|
370 | } else { |
---|
371 | $$json{ 'messaging'}{'tcpport' } = $tcpport; |
---|
372 | } |
---|
373 | |
---|
374 | if ( $$json{ "messaging" }{ "tcphostip" } ) { |
---|
375 | if ( $$json{'messaging'}{'tcphostip'} ne $tcphostip ) { |
---|
376 | $notice .= "The identified tcphostip for this server [$tcphostip] is different than that stored [$$json{'messaging'}{'tcphostip'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
377 | } |
---|
378 | if ( $fo ) { |
---|
379 | $$json{ 'messaging'}{'tcphostip' } = $tcphostip; |
---|
380 | } |
---|
381 | } else { |
---|
382 | $$json{ 'messaging'}{'tcphostip' } = $tcphostip; |
---|
383 | } |
---|
384 | |
---|
385 | if ( $$json{ "messaging" }{ "tcprport" } ) { |
---|
386 | if ( $$json{'messaging'}{'tcprport'} ne $tcprport ) { |
---|
387 | $notice .= "The identified tcprport for this server [$tcprport] is different than that stored [$$json{'messaging'}{'tcprport'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
388 | } |
---|
389 | if ( $fo ) { |
---|
390 | $$json{ 'messaging'}{'tcprport' } = $tcprport; |
---|
391 | } |
---|
392 | } else { |
---|
393 | $$json{ 'messaging'}{'tcprport' } = $tcprport; |
---|
394 | } |
---|
395 | |
---|
396 | if ( $$json{ "messaging" }{ "tcptimeout" } ) { |
---|
397 | if ( $$json{'messaging'}{'tcptimeout'} ne $tcptimeout ) { |
---|
398 | $notice .= "The identified tcptimeout for this server [$tcptimeout] is different than that stored [$$json{'messaging'}{'tcptimeout'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
399 | } |
---|
400 | if ( $fo ) { |
---|
401 | $$json{ 'messaging'}{'tcptimeout' } = $tcptimeout; |
---|
402 | } |
---|
403 | } else { |
---|
404 | $$json{ 'messaging'}{'tcptimeout' } = $tcptimeout; |
---|
405 | } |
---|
406 | |
---|
407 | if ( $$json{ "https" } ) { |
---|
408 | if ( $$json{'https'} != $https ) { |
---|
409 | $notice .= "The identified https flag for this server [$https] is different than that stored [$$json{'https'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
410 | } |
---|
411 | if ( $fo ) { |
---|
412 | $$json{'https'} = int($https); |
---|
413 | } |
---|
414 | } else { |
---|
415 | $$json{'https'} = int($https); |
---|
416 | } |
---|
417 | |
---|
418 | if ( !$webroot ) { |
---|
419 | $webroot = "/var/www/html" if $os =~ /^(ubuntu|centos|redhat|scientific)$/; |
---|
420 | $webroot = "/var/www/htdocs" if $os =~ /^slackware$/; |
---|
421 | } |
---|
422 | |
---|
423 | if ( $$json{ "webroot" } ) { |
---|
424 | if ( $$json{'webroot'} != $webroot ) { |
---|
425 | $notice .= "The identified webroot for this server [$webroot] is different than that stored [$$json{'webroot'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
426 | } |
---|
427 | if ( $fo ) { |
---|
428 | $$json{'webroot'} = $webroot; |
---|
429 | } |
---|
430 | } else { |
---|
431 | $$json{'webroot'} = $webroot; |
---|
432 | } |
---|
433 | |
---|
434 | if ( $$json{ "mongo" }{ "url" } ) { |
---|
435 | if ( $$json{'mongo'}{'url'} ne $mongourl ) { |
---|
436 | $notice .= "The identified mongod url for this server [$mongourl] is different than that stored [$$json{'mongo'}{'url'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
437 | } |
---|
438 | if ( $fo ) { |
---|
439 | $$json{'mongo'}{'url'} = $mongourl; |
---|
440 | } |
---|
441 | } else { |
---|
442 | $$json{'mongo'}{'url'} = $mongourl; |
---|
443 | } |
---|
444 | |
---|
445 | if ( $$json{ "mongo" }{ "cafile" } ) { |
---|
446 | if ( $$json{'mongo'}{'cafile'} ne $mongocafile ) { |
---|
447 | $notice .= "The identified mongod certificate file for this server [$mongocafile] is different than that stored [$$json{'mongo'}{'cafile'}] in $f. " . ( $fo ? "Overwriting with identified value." : "Leaving stored value untouched (use -f to overwrite)." ) . "\n"; |
---|
448 | } |
---|
449 | if ( $fo ) { |
---|
450 | $$json{'mongo'}{'cafile'} = $mongocafile; |
---|
451 | } |
---|
452 | } else { |
---|
453 | $$json{'mongo'}{'cafile'} = $mongocafile; |
---|
454 | } |
---|
455 | |
---|
456 | open my $fh, ">$f" || die "$0: can not open $f for writing, check permissions\n"; |
---|
457 | print $fh to_json( $json, { utf8 => 1, pretty => 1 } ); |
---|
458 | close $fh; |
---|
459 | |
---|
460 | if ( $pj ) { |
---|
461 | print "-"x80 . "\n"; |
---|
462 | print "Final config.json:\n"; |
---|
463 | print "-"x80 . "\n"; |
---|
464 | { |
---|
465 | my $js = JSON->new; |
---|
466 | print $js->pretty->encode( $json ); |
---|
467 | } |
---|
468 | print "-"x80 . "\n"; |
---|
469 | } |
---|
470 | |
---|
471 | print "-"x80 . "\n" . "Notices:\n" . "-"x80 . "\n" . $notice . "-"x80 . "\n" if $notice; |
---|