Merge with trunk
[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
10 local fatal;
11
12 local function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
13
14 local function missingdep(name, sources, msg)
15         print("");
16         print("**************************");
17         print("Prosody was unable to find "..tostring(name));
18         print("This package can be obtained in the following ways:");
19         print("");
20         local longest_platform = 0;
21         for platform in pairs(sources) do
22                 longest_platform = math.max(longest_platform, #platform);
23         end
24         for platform, source in pairs(sources) do
25                 print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source);
26         end
27         print("");
28         print(msg or (name.." is required for Prosody to run, so we will now exit."));
29         print("More help can be found on our website, at http://prosody.im/doc/depends");
30         print("**************************");
31         print("");
32 end
33
34 local lxp = softreq "lxp"
35
36 if not lxp then
37         missingdep("luaexpat", {
38                         ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-expat0";
39                         ["luarocks"] = "luarocks install luaexpat";
40                         ["Source"] = "http://www.keplerproject.org/luaexpat/";
41                 });
42         fatal = true;
43 end
44
45 local socket = softreq "socket"
46
47 if not socket then
48         missingdep("luasocket", {
49                         ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-socket2";
50                         ["luarocks"] = "luarocks install luasocket";
51                         ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/";
52                 });
53         fatal = true;
54 end
55         
56 local lfs, err = softreq "lfs"
57 if not lfs then
58         missingdep("luafilesystem", {
59                         ["luarocks"] = "luarocks install luafilesystem";
60                         ["Debian/Ubuntu"] = "sudo apt-get install liblua5.1-luafilesystem0";
61                         ["Source"] = "http://www.keplerproject.org/luafilesystem/";
62                 });
63         fatal = true;
64 end
65
66 local ssl = softreq "ssl"
67
68 if not ssl then
69         if config.get("*", "core", "run_without_ssl") then
70                 log("warn", "Running without SSL support because run_without_ssl is defined in the config");
71         else
72                 missingdep("LuaSec", {
73                                 ["Debian/Ubuntu"] = "http://prosody.im/download/start#debian_and_ubuntu";
74                                 ["luarocks"] = "luarocks install luasec";
75                                 ["Source"] = "http://www.inf.puc-rio.br/~brunoos/luasec/";
76                         }, "SSL/TLS support will not be available");
77         end
78 end
79
80 local encodings, err = softreq "util.encodings"
81 if not encodings then
82         if err:match("not found") then
83                 missingdep("util.encodings", { ["Windows"] = "Make sure you have encodings.dll from the Prosody distribution in util/";
84                                         ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so";
85                                 });
86         else
87                 print "***********************************"
88                 print("util/encodings couldn't be loaded. Check that you have a recent version of libidn");
89                 print ""
90                 print("The full error was:");
91                 print(err)
92                 print "***********************************"
93         end
94         fatal = true;
95 end
96
97 local hashes, err = softreq "util.hashes"
98 if not hashes then
99         if err:match("not found") then
100                 missingdep("util.hashes", { ["Windows"] = "Make sure you have hashes.dll from the Prosody distribution in util/";
101                                         ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so";
102                                 });
103         else
104                 print "***********************************"
105                 print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)");
106                 print ""
107                 print("The full error was:");
108                 print(err)
109                 print "***********************************"
110         end
111         fatal = true;
112 end
113
114 if fatal then os.exit(1); end