Software /
code /
prosody
Comparison
util/dependencies.lua @ 11120:b2331f3dfeea
Merge 0.11->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 30 Sep 2020 09:50:33 +0100 |
parent | 10975:f997e3e8bc23 |
child | 11141:a5acd6354845 |
comparison
equal
deleted
inserted
replaced
11119:68df52bf08d5 | 11120:b2331f3dfeea |
---|---|
5 -- This project is MIT/X11 licensed. Please see the | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | 6 -- COPYING file in the source package for more information. |
7 -- | 7 -- |
8 | 8 |
9 local function softreq(...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil, lib; end end | 9 local function softreq(...) local ok, lib = pcall(require, ...); if ok then return lib; else return nil, lib; end end |
10 local platform_table = require "util.human.io".table({ { width = 15, align = "right" }, { width = "100%" } }); | |
10 | 11 |
11 -- Required to be able to find packages installed with luarocks | 12 -- Required to be able to find packages installed with luarocks |
12 if not softreq "luarocks.loader" then -- LuaRocks 2.x | 13 if not softreq "luarocks.loader" then -- LuaRocks 2.x |
13 softreq "luarocks.require"; -- LuaRocks <1.x | 14 softreq "luarocks.require"; -- LuaRocks <1.x |
14 end | 15 end |
15 | 16 |
16 local function missingdep(name, sources, msg) | 17 local function missingdep(name, sources, msg, err) -- luacheck: ignore err |
18 -- TODO print something about the underlying error, useful for debugging | |
17 print(""); | 19 print(""); |
18 print("**************************"); | 20 print("**************************"); |
19 print("Prosody was unable to find "..tostring(name)); | 21 print("Prosody was unable to find "..tostring(name)); |
20 print("This package can be obtained in the following ways:"); | 22 print("This package can be obtained in the following ways:"); |
21 print(""); | 23 print(""); |
22 local longest_platform = 0; | 24 for _, row in ipairs(sources) do |
23 for platform in pairs(sources) do | 25 print(platform_table(row)); |
24 longest_platform = math.max(longest_platform, #platform); | |
25 end | |
26 for platform, source in pairs(sources) do | |
27 print("", platform..":"..(" "):rep(4+longest_platform-#platform)..source); | |
28 end | 26 end |
29 print(""); | 27 print(""); |
30 print(msg or (name.." is required for Prosody to run, so we will now exit.")); | 28 print(msg or (name.." is required for Prosody to run, so we will now exit.")); |
31 print("More help can be found on our website, at https://prosody.im/doc/depends"); | 29 print("More help can be found on our website, at https://prosody.im/doc/depends"); |
32 print("**************************"); | 30 print("**************************"); |
42 return false; | 40 return false; |
43 end | 41 end |
44 | 42 |
45 local fatal; | 43 local fatal; |
46 | 44 |
47 local lxp = softreq "lxp" | 45 local lxp, err = softreq "lxp" |
48 | 46 |
49 if not lxp then | 47 if not lxp then |
50 missingdep("luaexpat", { | 48 missingdep("luaexpat", { |
51 ["Debian/Ubuntu"] = "sudo apt-get install lua-expat"; | 49 { "Debian/Ubuntu", "sudo apt-get install lua-expat" }; |
52 ["luarocks"] = "luarocks install luaexpat"; | 50 { "luarocks", "luarocks install luaexpat" }; |
53 ["Source"] = "http://matthewwild.co.uk/projects/luaexpat/"; | 51 { "Source", "http://matthewwild.co.uk/projects/luaexpat/" }; |
54 }); | 52 }, nil, err); |
55 fatal = true; | 53 fatal = true; |
56 end | 54 end |
57 | 55 |
58 local socket = softreq "socket" | 56 local socket, err = softreq "socket" |
59 | 57 |
60 if not socket then | 58 if not socket then |
61 missingdep("luasocket", { | 59 missingdep("luasocket", { |
62 ["Debian/Ubuntu"] = "sudo apt-get install lua-socket"; | 60 { "Debian/Ubuntu", "sudo apt-get install lua-socket" }; |
63 ["luarocks"] = "luarocks install luasocket"; | 61 { "luarocks", "luarocks install luasocket" }; |
64 ["Source"] = "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/"; | 62 { "Source", "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/" }; |
65 }); | 63 }, nil, err); |
66 fatal = true; | 64 fatal = true; |
67 elseif not socket.tcp4 then | 65 elseif not socket.tcp4 then |
68 -- COMPAT LuaSocket before being IP-version agnostic | 66 -- COMPAT LuaSocket before being IP-version agnostic |
69 socket.tcp4 = socket.tcp; | 67 socket.tcp4 = socket.tcp; |
70 socket.udp4 = socket.udp; | 68 socket.udp4 = socket.udp; |
71 end | 69 end |
72 | 70 |
73 local lfs, err = softreq "lfs" | 71 local lfs, err = softreq "lfs" |
74 if not lfs then | 72 if not lfs then |
75 missingdep("luafilesystem", { | 73 missingdep("luafilesystem", { |
76 ["luarocks"] = "luarocks install luafilesystem"; | 74 { "luarocks", "luarocks install luafilesystem" }; |
77 ["Debian/Ubuntu"] = "sudo apt-get install lua-filesystem"; | 75 { "Debian/Ubuntu", "sudo apt-get install lua-filesystem" }; |
78 ["Source"] = "http://www.keplerproject.org/luafilesystem/"; | 76 { "Source", "http://www.keplerproject.org/luafilesystem/" }; |
79 }); | 77 }, nil, err); |
80 fatal = true; | 78 fatal = true; |
81 end | 79 end |
82 | 80 |
83 local ssl = softreq "ssl" | 81 local ssl, err = softreq "ssl" |
84 | 82 |
85 if not ssl then | 83 if not ssl then |
86 missingdep("LuaSec", { | 84 missingdep("LuaSec", { |
87 ["Debian/Ubuntu"] = "sudo apt-get install lua-sec"; | 85 { "Debian/Ubuntu", "sudo apt-get install lua-sec" }; |
88 ["luarocks"] = "luarocks install luasec"; | 86 { "luarocks", "luarocks install luasec" }; |
89 ["Source"] = "https://github.com/brunoos/luasec"; | 87 { "Source", "https://github.com/brunoos/luasec" }; |
90 }, "SSL/TLS support will not be available"); | 88 }, "SSL/TLS support will not be available", err); |
91 end | 89 end |
92 | 90 |
93 local bit = _G.bit32 or softreq"bit"; | 91 local bit, err = softreq"util.bitcompat"; |
94 | 92 |
95 if not bit then | 93 if not bit then |
96 missingdep("lua-bitops", { | 94 missingdep("lua-bitops", { |
97 ["Debian/Ubuntu"] = "sudo apt-get install lua-bitop"; | 95 { "Debian/Ubuntu", "sudo apt-get install lua-bitop" }; |
98 ["luarocks"] = "luarocks install luabitop"; | 96 { "luarocks", "luarocks install luabitop" }; |
99 ["Source"] = "http://bitop.luajit.org/"; | 97 { "Source", "http://bitop.luajit.org/" }; |
100 }, "WebSocket support will not be available"); | 98 }, "WebSocket support will not be available", err); |
99 end | |
100 | |
101 local unbound, err = softreq"lunbound"; -- luacheck: ignore 211/err | |
102 if not unbound then -- luacheck: ignore 542 | |
103 --[[ TODO Re-enable once packages are available | |
104 missingdep("lua-unbound", { | |
105 { "luarocks", "luarocks install luaunbound" }; | |
106 { "Source", "https://www.zash.se/luaunbound.html" }; | |
107 }, "Old DNS resolver library will be used", err); | |
108 --]] | |
109 else | |
110 package.preload["net.adns"] = function () | |
111 local ub = require "net.unbound"; | |
112 return ub; | |
113 end | |
101 end | 114 end |
102 | 115 |
103 local encodings, err = softreq "util.encodings" | 116 local encodings, err = softreq "util.encodings" |
104 if not encodings then | 117 if not encodings then |
105 if err:match("module '[^']*' not found") then | 118 if err:match("module '[^']*' not found") then |
106 missingdep("util.encodings", { | 119 missingdep("util.encodings", { |
107 ["Windows"] = "Make sure you have encodings.dll from the Prosody distribution in util/"; | 120 { "Windows", "Make sure you have encodings.dll from the Prosody distribution in util/" }; |
108 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so"; | 121 { "GNU/Linux", "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so" }; |
109 }); | 122 }); |
110 else | 123 else |
111 print "***********************************" | 124 print "***********************************" |
112 print("util/encodings couldn't be loaded. Check that you have a recent version of libidn"); | 125 print("util/encodings couldn't be loaded. Check that you have a recent version of libidn"); |
113 print "" | 126 print "" |
120 | 133 |
121 local hashes, err = softreq "util.hashes" | 134 local hashes, err = softreq "util.hashes" |
122 if not hashes then | 135 if not hashes then |
123 if err:match("module '[^']*' not found") then | 136 if err:match("module '[^']*' not found") then |
124 missingdep("util.hashes", { | 137 missingdep("util.hashes", { |
125 ["Windows"] = "Make sure you have hashes.dll from the Prosody distribution in util/"; | 138 { "Windows", "Make sure you have hashes.dll from the Prosody distribution in util/" }; |
126 ["GNU/Linux"] = "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so"; | 139 { "GNU/Linux", "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so" }; |
127 }); | 140 }); |
128 else | 141 else |
129 print "***********************************" | 142 print "***********************************" |
130 print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)"); | 143 print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)"); |
131 print "" | 144 print "" |
138 | 151 |
139 return not fatal; | 152 return not fatal; |
140 end | 153 end |
141 | 154 |
142 local function log_warnings() | 155 local function log_warnings() |
143 if _VERSION > "Lua 5.2" then | 156 if _VERSION > "Lua 5.3" then |
144 prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION); | 157 prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION); |
145 end | 158 end |
146 local ssl = softreq"ssl"; | 159 local ssl = softreq"ssl"; |
147 if ssl then | 160 if ssl then |
148 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)"); | 161 local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)"); |