util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies...
[prosody.git] / util / dependencies.lua
1 -- Prosody IM
2 -- Copyright (C) 2008-2009 Matthew Wild
3 -- Copyright (C) 2008-2009 Waqas Hussain
4 -- 
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
8
9 module("dependencies", package.seeall)
10
11 function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
12
13 function missingdep(name, sources, msg)
14         print("");
15         print("**************************");
16         print("Prosody was unable to find "..tostring(name));
17         print("This package can be obtained in the following ways:");
18         print("");
19         local longest_platform = 0;
20         for platform in pairs(sources) do
21                 longest_platform = math.max(longest_platform, #platform);
22         end
23         for platform, source in pairs(sources) do
24                 print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source);
25         end
26         print("");
27         print(msg or (name.." is required for Prosody to run, so we will now exit."));
28         print("More help can be found on our website, at http://prosody.im/doc/depends");
29         print("**************************");
30         print("");
31 end
32
33 function check_dependencies()
34         local fatal;
35         
36         local lxp = softreq "lxp"
37         
38         if not lxp then
39                 missingdep("luaexpat", {
40                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-expat0";
41                                 ["luarocks"] = "luarocks install luaexpat";
42                                 ["Source"] = "http://www.keplerproject.org/luaexpat/";
43                         });
44                 fatal = true;
45         end
46         
47         local socket = softreq "socket"
48         
49         if not socket then
50                 missingdep("luasocket", {
51                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-socket2";
52                                 ["luarocks"] = "luarocks install luasocket";
53                                 ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/";
54                         });
55                 fatal = true;
56         end
57         
58         local lfs, err = softreq "lfs"
59         if not lfs then
60                 missingdep("luafilesystem", {
61                                 ["luarocks"] = "luarocks install luafilesystem";
62                                 ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-filesystem0";
63                                 ["Source"] = "http://www.keplerproject.org/luafilesystem/";
64                         });
65                 fatal = true;
66         end
67         
68         local ssl = softreq "ssl"
69         
70         if not ssl then
71                 if config.get("*", "core", "run_without_ssl") then
72                         log("warn", "Running without SSL support because run_without_ssl is defined in the config");
73                 else
74                         missingdep("LuaSec", {
75                                         ["Debian/Ubuntu"] = "http://prosody.im/download/start#debian_and_ubuntu";
76                                         ["luarocks"] = "luarocks install luasec";
77                                         ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/";
78                                 }, "SSL/TLS support will not be available");
79                 end
80         else
81                 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
82                 if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
83                         log("error", "This version of LuaSec contains a known bug that causes disconnects, see http://prosody.im/doc/depends");
84                 end
85         end
86         
87         local encodings, err = softreq "util.encodings"
88         if not encodings then
89                 if err:match("not found") then
90                         missingdep("util.encodings", { ["Windows"] = "Make sure you have encodings.dll from the Prosody distribution in util/";
91                                                 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so";
92                                         });
93                 else
94                         print "***********************************"
95                         print("util/encodings couldn't be loaded. Check that you have a recent version of libidn");
96                         print ""
97                         print("The full error was:");
98                         print(err)
99                         print "***********************************"
100                 end
101                 fatal = true;
102         end
103
104         local hashes, err = softreq "util.hashes"
105         if not hashes then
106                 if err:match("not found") then
107                         missingdep("util.hashes", { ["Windows"] = "Make sure you have hashes.dll from the Prosody distribution in util/";
108                                                 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so";
109                                         });
110                 else
111                         print "***********************************"
112                         print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)");
113                         print ""
114                         print("The full error was:");
115                         print(err)
116                         print "***********************************"
117                 end
118                 fatal = true;
119         end
120         return not fatal;
121 end
122
123
124 return _M;