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