Comparison

prosodyctl @ 7922:2fd20f372cb1

prosodyctl: Trim trailing whitespace
author Kim Alvefur <zash@zash.se>
date Mon, 27 Feb 2017 15:55:22 +0100
parent 7920:1db51061342b
child 7923:81f3068fc30c
child 8010:49feb0da29e1
comparison
equal deleted inserted replaced
7921:1821a7cabaa5 7922:2fd20f372cb1
1 #!/usr/bin/env lua 1 #!/usr/bin/env lua
2 -- Prosody IM 2 -- Prosody IM
3 -- Copyright (C) 2008-2010 Matthew Wild 3 -- Copyright (C) 2008-2010 Matthew Wild
4 -- Copyright (C) 2008-2010 Waqas Hussain 4 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- 5 --
6 -- This project is MIT/X11 licensed. Please see the 6 -- This project is MIT/X11 licensed. Please see the
7 -- COPYING file in the source package for more information. 7 -- COPYING file in the source package for more information.
8 -- 8 --
9 9
10 -- prosodyctl - command-line controller for Prosody XMPP server 10 -- prosodyctl - command-line controller for Prosody XMPP server
63 config = require "core.configmanager" 63 config = require "core.configmanager"
64 64
65 local ENV_CONFIG; 65 local ENV_CONFIG;
66 do 66 do
67 local filenames = {}; 67 local filenames = {};
68 68
69 local filename; 69 local filename;
70 if arg[1] == "--config" and arg[2] then 70 if arg[1] == "--config" and arg[2] then
71 table.insert(filenames, arg[2]); 71 table.insert(filenames, arg[2]);
72 if CFG_CONFIGDIR then 72 if CFG_CONFIGDIR then
73 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); 73 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]);
118 if custom_plugin_paths then 118 if custom_plugin_paths then
119 local path_sep = package.config:sub(3,3); 119 local path_sep = package.config:sub(3,3);
120 -- path1;path2;path3;defaultpath... 120 -- path1;path2;path3;defaultpath...
121 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); 121 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins");
122 end 122 end
123 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, 123 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR,
124 plugins = CFG_PLUGINDIR or "plugins", data = data_path }; 124 plugins = CFG_PLUGINDIR or "plugins", data = data_path };
125 125
126 if prosody.installed then 126 if prosody.installed then
127 -- Change working directory to data path. 127 -- Change working directory to data path.
128 require "lfs".chdir(data_path); 128 require "lfs".chdir(data_path);
159 if not switched_user then 159 if not switched_user then
160 -- Boo! 160 -- Boo!
161 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); 161 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err));
162 end 162 end
163 end 163 end
164 164
165 -- Set our umask to protect data files 165 -- Set our umask to protect data files
166 pposix.umask(config.get("*", "umask") or "027"); 166 pposix.umask(config.get("*", "umask") or "027");
167 pposix.setenv("HOME", data_path); 167 pposix.setenv("HOME", data_path);
168 pposix.setenv("PROSODY_CONFIG", ENV_CONFIG); 168 pposix.setenv("PROSODY_CONFIG", ENV_CONFIG);
169 else 169 else
210 print(""); 210 print("");
211 os.exit(1); 211 os.exit(1);
212 end 212 end
213 213
214 214
215 local error_messages = setmetatable({ 215 local error_messages = setmetatable({
216 ["invalid-username"] = "The given username is invalid in a Jabber ID"; 216 ["invalid-username"] = "The given username is invalid in a Jabber ID";
217 ["invalid-hostname"] = "The given hostname is invalid"; 217 ["invalid-hostname"] = "The given hostname is invalid";
218 ["no-password"] = "No password was supplied"; 218 ["no-password"] = "No password was supplied";
219 ["no-such-user"] = "The given user does not exist on the server"; 219 ["no-such-user"] = "The given user does not exist on the server";
220 ["no-such-host"] = "The given hostname does not exist in the config"; 220 ["no-such-host"] = "The given hostname does not exist in the config";
239 end 239 end
240 240
241 for hostname, config in pairs(config.getconfig()) do 241 for hostname, config in pairs(config.getconfig()) do
242 hosts[hostname] = make_host(hostname); 242 hosts[hostname] = make_host(hostname);
243 end 243 end
244 244
245 local modulemanager = require "core.modulemanager" 245 local modulemanager = require "core.modulemanager"
246 246
247 local prosodyctl = require "util.prosodyctl" 247 local prosodyctl = require "util.prosodyctl"
248 local socket = require "socket" 248 local socket = require "socket"
249 ----------------------- 249 -----------------------
288 if not user and host then 288 if not user and host then
289 show_message [[Failed to understand JID, please supply the JID you want to create]] 289 show_message [[Failed to understand JID, please supply the JID you want to create]]
290 show_usage [[adduser user@host]] 290 show_usage [[adduser user@host]]
291 return 1; 291 return 1;
292 end 292 end
293 293
294 if not host then 294 if not host then
295 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; 295 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
296 return 1; 296 return 1;
297 end 297 end
298 298
299 if not hosts[host] then 299 if not hosts[host] then
300 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) 300 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
301 show_warning("The user will not be able to log in until this is changed."); 301 show_warning("The user will not be able to log in until this is changed.");
302 hosts[host] = make_host(host); 302 hosts[host] = make_host(host);
303 end 303 end
304 304
305 if prosodyctl.user_exists{ user = user, host = host } then 305 if prosodyctl.user_exists{ user = user, host = host } then
306 show_message [[That user already exists]]; 306 show_message [[That user already exists]];
307 return 1; 307 return 1;
308 end 308 end
309 309
310 local password = read_password(); 310 local password = read_password();
311 if not password then return 1; end 311 if not password then return 1; end
312 312
313 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; 313 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
314 314
315 if ok then return 0; end 315 if ok then return 0; end
316 316
317 show_message(msg) 317 show_message(msg)
318 return 1; 318 return 1;
319 end 319 end
320 320
321 function commands.passwd(arg) 321 function commands.passwd(arg)
327 if not user and host then 327 if not user and host then
328 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] 328 show_message [[Failed to understand JID, please supply the JID you want to set the password for]]
329 show_usage [[passwd user@host]] 329 show_usage [[passwd user@host]]
330 return 1; 330 return 1;
331 end 331 end
332 332
333 if not host then 333 if not host then
334 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; 334 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
335 return 1; 335 return 1;
336 end 336 end
337 337
338 if not hosts[host] then 338 if not hosts[host] then
339 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) 339 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
340 show_warning("The user will not be able to log in until this is changed."); 340 show_warning("The user will not be able to log in until this is changed.");
341 hosts[host] = make_host(host); 341 hosts[host] = make_host(host);
342 end 342 end
343 343
344 if not prosodyctl.user_exists { user = user, host = host } then 344 if not prosodyctl.user_exists { user = user, host = host } then
345 show_message [[That user does not exist, use prosodyctl adduser to create a new user]] 345 show_message [[That user does not exist, use prosodyctl adduser to create a new user]]
346 return 1; 346 return 1;
347 end 347 end
348 348
349 local password = read_password(); 349 local password = read_password();
350 if not password then return 1; end 350 if not password then return 1; end
351 351
352 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; 352 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password };
353 353
354 if ok then return 0; end 354 if ok then return 0; end
355 355
356 show_message(error_messages[msg]) 356 show_message(error_messages[msg])
357 return 1; 357 return 1;
358 end 358 end
359 359
360 function commands.deluser(arg) 360 function commands.deluser(arg)
366 if not user and host then 366 if not user and host then
367 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] 367 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]]
368 show_usage [[deluser user@host]] 368 show_usage [[deluser user@host]]
369 return 1; 369 return 1;
370 end 370 end
371 371
372 if not host then 372 if not host then
373 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; 373 show_message [[Please specify a JID, including a host. e.g. alice@example.com]];
374 return 1; 374 return 1;
375 end 375 end
376 376
377 if not hosts[host] then 377 if not hosts[host] then
378 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) 378 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host)
379 hosts[host] = make_host(host); 379 hosts[host] = make_host(host);
380 end 380 end
381 381
382 if not prosodyctl.user_exists { user = user, host = host } then 382 if not prosodyctl.user_exists { user = user, host = host } then
383 show_message [[That user does not exist on this server]] 383 show_message [[That user does not exist on this server]]
384 return 1; 384 return 1;
385 end 385 end
386 386
387 local ok, msg = prosodyctl.deluser { user = user, host = host }; 387 local ok, msg = prosodyctl.deluser { user = user, host = host };
388 388
389 if ok then return 0; end 389 if ok then return 0; end
390 390
391 show_message(error_messages[msg]) 391 show_message(error_messages[msg])
392 return 1; 392 return 1;
393 end 393 end
394 394
395 function commands.start(arg) 395 function commands.start(arg)
400 local ok, ret = prosodyctl.isrunning(); 400 local ok, ret = prosodyctl.isrunning();
401 if not ok then 401 if not ok then
402 show_message(error_messages[ret]); 402 show_message(error_messages[ret]);
403 return 1; 403 return 1;
404 end 404 end
405 405
406 if ret then 406 if ret then
407 local ok, ret = prosodyctl.getpid(); 407 local ok, ret = prosodyctl.getpid();
408 if not ok then 408 if not ok then
409 show_message("Couldn't get running Prosody's PID"); 409 show_message("Couldn't get running Prosody's PID");
410 show_message(error_messages[ret]); 410 show_message(error_messages[ret]);
411 return 1; 411 return 1;
412 end 412 end
413 show_message("Prosody is already running with PID %s", ret or "(unknown)"); 413 show_message("Prosody is already running with PID %s", ret or "(unknown)");
414 return 1; 414 return 1;
415 end 415 end
416 416
417 local ok, ret = prosodyctl.start(); 417 local ok, ret = prosodyctl.start();
418 if ok then 418 if ok then
419 local daemonize = config.get("*", "daemonize"); 419 local daemonize = config.get("*", "daemonize");
420 if daemonize == nil then 420 if daemonize == nil then
421 daemonize = prosody.installed; 421 daemonize = prosody.installed;
439 end 439 end
440 return 0; 440 return 0;
441 end 441 end
442 442
443 show_message("Failed to start Prosody"); 443 show_message("Failed to start Prosody");
444 show_message(error_messages[ret]) 444 show_message(error_messages[ret])
445 return 1; 445 return 1;
446 end 446 end
447 447
448 function commands.status(arg) 448 function commands.status(arg)
449 if arg[1] == "--help" then 449 if arg[1] == "--help" then
450 show_usage([[status]], [[Reports the running status of Prosody]]); 450 show_usage([[status]], [[Reports the running status of Prosody]]);
454 local ok, ret = prosodyctl.isrunning(); 454 local ok, ret = prosodyctl.isrunning();
455 if not ok then 455 if not ok then
456 show_message(error_messages[ret]); 456 show_message(error_messages[ret]);
457 return 1; 457 return 1;
458 end 458 end
459 459
460 if ret then 460 if ret then
461 local ok, ret = prosodyctl.getpid(); 461 local ok, ret = prosodyctl.getpid();
462 if not ok then 462 if not ok then
463 show_message("Couldn't get running Prosody's PID"); 463 show_message("Couldn't get running Prosody's PID");
464 show_message(error_messages[ret]); 464 show_message(error_messages[ret]);
487 487
488 if not prosodyctl.isrunning() then 488 if not prosodyctl.isrunning() then
489 show_message("Prosody is not running"); 489 show_message("Prosody is not running");
490 return 1; 490 return 1;
491 end 491 end
492 492
493 local ok, ret = prosodyctl.stop(); 493 local ok, ret = prosodyctl.stop();
494 if ok then 494 if ok then
495 local i=1; 495 local i=1;
496 while true do 496 while true do
497 local ok, running = prosodyctl.isrunning(); 497 local ok, running = prosodyctl.isrunning();
517 function commands.restart(arg) 517 function commands.restart(arg)
518 if arg[1] == "--help" then 518 if arg[1] == "--help" then
519 show_usage([[restart]], [[Restart a running Prosody server]]); 519 show_usage([[restart]], [[Restart a running Prosody server]]);
520 return 1; 520 return 1;
521 end 521 end
522 522
523 commands.stop(arg); 523 commands.stop(arg);
524 return commands.start(arg); 524 return commands.start(arg);
525 end 525 end
526 526
527 function commands.about(arg) 527 function commands.about(arg)
528 read_version(); 528 read_version();
529 if arg[1] == "--help" then 529 if arg[1] == "--help" then
530 show_usage([[about]], [[Show information about this Prosody installation]]); 530 show_usage([[about]], [[Show information about this Prosody installation]]);
531 return 1; 531 return 1;
532 end 532 end
533 533
534 local pwd = "."; 534 local pwd = ".";
535 local lfs = require "lfs"; 535 local lfs = require "lfs";
536 local array = require "util.array"; 536 local array = require "util.array";
537 local keys = require "util.iterators".keys; 537 local keys = require "util.iterators".keys;
538 local hg = require"util.mercurial"; 538 local hg = require"util.mercurial";
539 local relpath = config.resolve_relative_path; 539 local relpath = config.resolve_relative_path;
540 540
541 print("Prosody "..(prosody.version or "(unknown version)")); 541 print("Prosody "..(prosody.version or "(unknown version)"));
542 print(""); 542 print("");
543 print("# Prosody directories"); 543 print("# Prosody directories");
544 print("Data directory: "..relpath(pwd, data_path)); 544 print("Data directory: "..relpath(pwd, data_path));
545 print("Config directory: "..relpath(pwd, CFG_CONFIGDIR or ".")); 545 print("Config directory: "..relpath(pwd, CFG_CONFIGDIR or "."));
606 606
607 if not prosodyctl.isrunning() then 607 if not prosodyctl.isrunning() then
608 show_message("Prosody is not running"); 608 show_message("Prosody is not running");
609 return 1; 609 return 1;
610 end 610 end
611 611
612 local ok, ret = prosodyctl.reload(); 612 local ok, ret = prosodyctl.reload();
613 if ok then 613 if ok then
614 614
615 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); 615 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect.");
616 return 0; 616 return 0;
617 end 617 end
618 618
619 show_message(error_messages[ret]); 619 show_message(error_messages[ret]);
641 if not password then 641 if not password then
642 show_message [[Unable to register user with no password]]; 642 show_message [[Unable to register user with no password]];
643 return 1; 643 return 1;
644 end 644 end
645 end 645 end
646 646
647 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; 647 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password };
648 648
649 if ok then return 0; end 649 if ok then return 0; end
650 650
651 show_message(error_messages[msg]) 651 show_message(error_messages[msg])
652 return 1; 652 return 1;
653 end 653 end
654 654
655 function commands.unregister(arg) 655 function commands.unregister(arg)
665 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server"); 665 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server");
666 return 1; 666 return 1;
667 end 667 end
668 668
669 local ok, msg = prosodyctl.deluser { user = user, host = host }; 669 local ok, msg = prosodyctl.deluser { user = user, host = host };
670 670
671 if ok then return 0; end 671 if ok then return 0; end
672 672
673 show_message(error_messages[msg]) 673 show_message(error_messages[msg])
674 return 1; 674 return 1;
675 end 675 end
676 676
677 local openssl; 677 local openssl;
1010 print(""); 1010 print("");
1011 print(" You require encryption but mod_tls is not enabled."); 1011 print(" You require encryption but mod_tls is not enabled.");
1012 print(" Connections will fail."); 1012 print(" Connections will fail.");
1013 ok = false; 1013 ok = false;
1014 end 1014 end
1015 1015
1016 print("Done.\n"); 1016 print("Done.\n");
1017 end 1017 end
1018 if not what or what == "dns" then 1018 if not what or what == "dns" then
1019 local dns = require "net.dns"; 1019 local dns = require "net.dns";
1020 local idna = require "util.encodings".idna; 1020 local idna = require "util.encodings".idna;
1021 local ip = require "util.ip"; 1021 local ip = require "util.ip";
1022 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); 1022 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222});
1023 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); 1023 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269});
1024 1024
1025 local c2s_srv_required, s2s_srv_required; 1025 local c2s_srv_required, s2s_srv_required;
1026 if not c2s_ports:contains(5222) then 1026 if not c2s_ports:contains(5222) then
1027 c2s_srv_required = true; 1027 c2s_srv_required = true;
1028 end 1028 end
1029 if not s2s_ports:contains(5269) then 1029 if not s2s_ports:contains(5269) then
1030 s2s_srv_required = true; 1030 s2s_srv_required = true;
1031 end 1031 end
1032 1032
1033 local problem_hosts = set.new(); 1033 local problem_hosts = set.new();
1034 1034
1035 local external_addresses, internal_addresses = set.new(), set.new(); 1035 local external_addresses, internal_addresses = set.new(), set.new();
1036 1036
1037 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); 1037 local fqdn = socket.dns.tohostname(socket.dns.gethostname());
1038 if fqdn then 1038 if fqdn then
1039 local res = dns.lookup(idna.to_ascii(fqdn), "A"); 1039 local res = dns.lookup(idna.to_ascii(fqdn), "A");
1040 if res then 1040 if res then
1041 for _, record in ipairs(res) do 1041 for _, record in ipairs(res) do
1047 for _, record in ipairs(res) do 1047 for _, record in ipairs(res) do
1048 external_addresses:add(record.aaaa); 1048 external_addresses:add(record.aaaa);
1049 end 1049 end
1050 end 1050 end
1051 end 1051 end
1052 1052
1053 local local_addresses = require"util.net".local_addresses() or {}; 1053 local local_addresses = require"util.net".local_addresses() or {};
1054 1054
1055 for addr in it.values(local_addresses) do 1055 for addr in it.values(local_addresses) do
1056 if not ip.new_ip(addr).private then 1056 if not ip.new_ip(addr).private then
1057 external_addresses:add(addr); 1057 external_addresses:add(addr);
1058 else 1058 else
1059 internal_addresses:add(addr); 1059 internal_addresses:add(addr);
1060 end 1060 end
1061 end 1061 end
1062 1062
1063 if external_addresses:empty() then 1063 if external_addresses:empty() then
1064 print(""); 1064 print("");
1065 print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); 1065 print(" Failed to determine the external addresses of this server. Checks may be inaccurate.");
1066 c2s_srv_required, s2s_srv_required = true, true; 1066 c2s_srv_required, s2s_srv_required = true, true;
1067 end 1067 end
1068 1068
1069 local v6_supported = not not socket.tcp6; 1069 local v6_supported = not not socket.tcp6;
1070 1070
1071 for jid, host_options in enabled_hosts() do 1071 for jid, host_options in enabled_hosts() do
1072 local all_targets_ok, some_targets_ok = true, false; 1072 local all_targets_ok, some_targets_ok = true, false;
1073 local node, host = jid_split(jid); 1073 local node, host = jid_split(jid);
1074 1074
1075 local is_component = not not host_options.component_module; 1075 local is_component = not not host_options.component_module;
1076 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."..."); 1076 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."...");
1077 if node then 1077 if node then
1078 print("Only the domain part ("..host..") is used in DNS.") 1078 print("Only the domain part ("..host..") is used in DNS.")
1079 end 1079 end
1113 end 1113 end
1114 end 1114 end
1115 if target_hosts:empty() then 1115 if target_hosts:empty() then
1116 target_hosts:add(host); 1116 target_hosts:add(host);
1117 end 1117 end
1118 1118
1119 if target_hosts:contains("localhost") then 1119 if target_hosts:contains("localhost") then
1120 print(" Target 'localhost' cannot be accessed from other servers"); 1120 print(" Target 'localhost' cannot be accessed from other servers");
1121 target_hosts:remove("localhost"); 1121 target_hosts:remove("localhost");
1122 end 1122 end
1123 1123
1124 local modules = set.new(it.to_array(it.values(host_options.modules_enabled or {}))) 1124 local modules = set.new(it.to_array(it.values(host_options.modules_enabled or {})))
1125 + set.new(it.to_array(it.values(config.get("*", "modules_enabled") or {}))) 1125 + set.new(it.to_array(it.values(config.get("*", "modules_enabled") or {})))
1126 + set.new({ config.get(host, "component_module") }); 1126 + set.new({ config.get(host, "component_module") });
1127 1127
1128 if modules:contains("proxy65") then 1128 if modules:contains("proxy65") then
1137 end 1137 end
1138 if #prob > 0 then 1138 if #prob > 0 then
1139 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/").." record. Create one or set 'proxy65_address' to the correct host/IP."); 1139 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/").." record. Create one or set 'proxy65_address' to the correct host/IP.");
1140 end 1140 end
1141 end 1141 end
1142 1142
1143 for host in target_hosts do 1143 for host in target_hosts do
1144 local host_ok_v4, host_ok_v6; 1144 local host_ok_v4, host_ok_v6;
1145 local res = dns.lookup(idna.to_ascii(host), "A"); 1145 local res = dns.lookup(idna.to_ascii(host), "A");
1146 if res then 1146 if res then
1147 for _, record in ipairs(res) do 1147 for _, record in ipairs(res) do
1172 print(" "..host.." AAAA record points to unknown address "..record.aaaa); 1172 print(" "..host.." AAAA record points to unknown address "..record.aaaa);
1173 all_targets_ok = false; 1173 all_targets_ok = false;
1174 end 1174 end
1175 end 1175 end
1176 end 1176 end
1177 1177
1178 local bad_protos = {} 1178 local bad_protos = {}
1179 if not host_ok_v4 then 1179 if not host_ok_v4 then
1180 table.insert(bad_protos, "IPv4"); 1180 table.insert(bad_protos, "IPv4");
1181 end 1181 end
1182 if not host_ok_v6 then 1182 if not host_ok_v6 then
1301 local ret, err = modulemanager.load("*", module_name); 1301 local ret, err = modulemanager.load("*", module_name);
1302 if not ret then 1302 if not ret then
1303 show_message("Failed to load module '"..module_name.."': "..err); 1303 show_message("Failed to load module '"..module_name.."': "..err);
1304 os.exit(1); 1304 os.exit(1);
1305 end 1305 end
1306 1306
1307 table.remove(arg, 1); 1307 table.remove(arg, 1);
1308 1308
1309 local module = modulemanager.get_module("*", module_name); 1309 local module = modulemanager.get_module("*", module_name);
1310 if not module then 1310 if not module then
1311 show_message("Failed to load module '"..module_name.."': Unknown error"); 1311 show_message("Failed to load module '"..module_name.."': Unknown error");
1312 os.exit(1); 1312 os.exit(1);
1313 end 1313 end
1314 1314
1315 if not modulemanager.module_has_method(module, "command") then 1315 if not modulemanager.module_has_method(module, "command") then
1316 show_message("Fail: mod_"..module_name.." does not support any commands"); 1316 show_message("Fail: mod_"..module_name.." does not support any commands");
1317 os.exit(1); 1317 os.exit(1);
1318 end 1318 end
1319 1319
1320 local ok, ret = modulemanager.call_module_method(module, "command", arg); 1320 local ok, ret = modulemanager.call_module_method(module, "command", arg);
1321 if ok then 1321 if ok then
1322 if type(ret) == "number" then 1322 if type(ret) == "number" then
1323 os.exit(ret); 1323 os.exit(ret);
1324 elseif type(ret) == "string" then 1324 elseif type(ret) == "string" then
1362 command{ "--help" }; 1362 command{ "--help" };
1363 print"" 1363 print""
1364 done[command_name] = true; 1364 done[command_name] = true;
1365 end 1365 end
1366 end 1366 end
1367 1367
1368 1368
1369 os.exit(0); 1369 os.exit(0);
1370 end 1370 end
1371 1371
1372 os.exit(commands[command]({ select(2, unpack(arg)) })); 1372 os.exit(commands[command]({ select(2, unpack(arg)) }));