util/dependencies.lua
author Kim Alvefur <zash@zash.se>
Wed, 27 Mar 2024 19:33:11 +0100
changeset 13471 c2a476f4712a
parent 13118 025c38ee885d
permissions -rw-r--r--
util.startup: Fix exiting on pidfile trouble prosody.shutdown() relies on prosody.main_thread, which has not been set yet at this point. Doing a clean shutdown might actually be harmful in case it tears down things set up by the conflicting Prosody, such as the very pidfile we were looking at. Thanks again SigmaTel71 for noticing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 896
diff changeset
     1
-- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2815
diff changeset
     2
-- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2815
diff changeset
     3
-- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
     4
--
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 743
diff changeset
     5
-- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 743
diff changeset
     6
-- COPYING file in the source package for more information.
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     7
--
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 449
diff changeset
     8
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
     9
local function softreq(...) local ok, lib =  pcall(require, ...); if ok then return lib; else return nil, lib; end end
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
2513
a8aa7616b154 util.dependencies: Load luarocks.loader/luarocks.require
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
    11
-- Required to be able to find packages installed with luarocks
a8aa7616b154 util.dependencies: Load luarocks.loader/luarocks.require
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
    12
if not softreq "luarocks.loader" then -- LuaRocks 2.x
a8aa7616b154 util.dependencies: Load luarocks.loader/luarocks.require
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
    13
	softreq "luarocks.require"; -- LuaRocks <1.x
a8aa7616b154 util.dependencies: Load luarocks.loader/luarocks.require
Matthew Wild <mwild1@gmail.com>
parents: 2510
diff changeset
    14
end
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    15
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    16
local function missingdep(name, sources, msg, err) -- luacheck: ignore err
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    17
	-- TODO print something about the underlying error, useful for debugging
409
2269e9cbe153 Add MD5 to the list of checked dependencies
Matthew Wild <mwild1@gmail.com>
parents: 408
diff changeset
    18
	print("");
2269e9cbe153 Add MD5 to the list of checked dependencies
Matthew Wild <mwild1@gmail.com>
parents: 408
diff changeset
    19
	print("**************************");
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
	print("Prosody was unable to find "..tostring(name));
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
	print("This package can be obtained in the following ways:");
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    22
	print("");
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    23
	for _, row in ipairs(sources) do
13118
025c38ee885d util.dependencies: Print tables itself to reduce number of imports
Kim Alvefur <zash@zash.se>
parents: 12979
diff changeset
    24
		print(string.format("%15s | %s", table.unpack(row)));
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    25
	end
410
5ce6801ad2e4 Trivial whitespace fix in the missing dependency message
Matthew Wild <mwild1@gmail.com>
parents: 409
diff changeset
    26
	print("");
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
	print(msg or (name.." is required for Prosody to run, so we will now exit."));
7362
a5a080c12c96 Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7267
diff changeset
    28
	print("More help can be found on our website, at https://prosody.im/doc/depends");
409
2269e9cbe153 Add MD5 to the list of checked dependencies
Matthew Wild <mwild1@gmail.com>
parents: 408
diff changeset
    29
	print("**************************");
2269e9cbe153 Add MD5 to the list of checked dependencies
Matthew Wild <mwild1@gmail.com>
parents: 408
diff changeset
    30
	print("");
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
end
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
    33
local function check_dependencies()
12576
35a9ed6b7896 util.dependencies: Reject Lua 5.1, Lua 5.2 or later is now required (see #1600)
Kim Alvefur <zash@zash.se>
parents: 12573
diff changeset
    34
	if _VERSION < "Lua 5.2" then
6065
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    35
		print "***********************************"
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    36
		print("Unsupported Lua version: ".._VERSION);
12576
35a9ed6b7896 util.dependencies: Reject Lua 5.1, Lua 5.2 or later is now required (see #1600)
Kim Alvefur <zash@zash.se>
parents: 12573
diff changeset
    37
		print("At least Lua 5.2 is required.");
6065
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    38
		print "***********************************"
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    39
		return false;
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    40
	end
9ab23488a17c util.dependencies: Check for Lua 5.1. We don't currently support any other versions. LuaJIT identifies as 5.1.
Waqas Hussain <waqas20@gmail.com>
parents: 6043
diff changeset
    41
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    42
	local fatal;
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    43
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    44
	local lxp, err = softreq "lxp"
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    45
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    46
	if not lxp then
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    47
		missingdep("luaexpat", {
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
    48
				{ "Debian/Ubuntu", "sudo apt install lua-expat" };
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    49
				{ "luarocks", "luarocks install luaexpat" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    50
				{ "Source", "http://matthewwild.co.uk/projects/luaexpat/" };
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    51
			}, nil, err);
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    52
		fatal = true;
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    53
	end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    54
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    55
	local socket, err = softreq "socket"
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    56
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    57
	if not socket then
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    58
		missingdep("luasocket", {
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
    59
				{ "Debian/Ubuntu", "sudo apt install lua-socket" };
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    60
				{ "luarocks", "luarocks install luasocket" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    61
				{ "Source", "http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/" };
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    62
			}, nil, err);
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    63
		fatal = true;
9497
b19f676203fd util.dependencies: Add compat code for normalization of socket constructors
Kim Alvefur <zash@zash.se>
parents: 8238
diff changeset
    64
	elseif not socket.tcp4 then
b19f676203fd util.dependencies: Add compat code for normalization of socket constructors
Kim Alvefur <zash@zash.se>
parents: 8238
diff changeset
    65
		-- COMPAT LuaSocket before being IP-version agnostic
b19f676203fd util.dependencies: Add compat code for normalization of socket constructors
Kim Alvefur <zash@zash.se>
parents: 8238
diff changeset
    66
		socket.tcp4 = socket.tcp;
b19f676203fd util.dependencies: Add compat code for normalization of socket constructors
Kim Alvefur <zash@zash.se>
parents: 8238
diff changeset
    67
		socket.udp4 = socket.udp;
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    68
	end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    69
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    70
	local lfs, err = softreq "lfs"
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    71
	if not lfs then
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    72
		missingdep("luafilesystem", {
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    73
			{ "luarocks", "luarocks install luafilesystem" };
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
    74
			{ "Debian/Ubuntu", "sudo apt install lua-filesystem" };
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    75
			{ "Source", "http://www.keplerproject.org/luafilesystem/" };
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    76
		}, nil, err);
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    77
		fatal = true;
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    78
	end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    79
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    80
	local ssl, err = softreq "ssl"
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    81
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
    82
	if not ssl then
2157
7cb0aa497326 util.dependencies: Clearer message, add homepages, etc.
Matthew Wild <mwild1@gmail.com>
parents: 2156
diff changeset
    83
		missingdep("LuaSec", {
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
    84
				{ "Debian/Ubuntu", "sudo apt install lua-sec" };
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    85
				{ "luarocks", "luarocks install luasec" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    86
				{ "Source", "https://github.com/brunoos/luasec" };
12335
49739369dcad core.certmanager: Turn soft dependency on LuaSec into a hard
Kim Alvefur <zash@zash.se>
parents: 12290
diff changeset
    87
			}, nil, err);
413
4b61529d0884 Refuse to run without SSL/TLS unless run_without_ssl is set in config
Matthew Wild <mwild1@gmail.com>
parents: 410
diff changeset
    88
	end
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 4421
diff changeset
    89
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
    90
	local bit, err = softreq"prosody.util.bitcompat";
7770
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
    91
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
    92
	if not bit then
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
    93
		missingdep("lua-bitops", {
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
    94
			{ "Debian/Ubuntu", "sudo apt install lua-bitop" };
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    95
			{ "luarocks", "luarocks install luabitop" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
    96
			{ "Source", "http://bitop.luajit.org/" };
10539
29c1a3bf1d29 util.dependencies: Pass require error to error formatting function
Kim Alvefur <zash@zash.se>
parents: 10410
diff changeset
    97
		}, "WebSocket support will not be available", err);
7770
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
    98
	end
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
    99
10979
f997e3e8bc23 util.dependencies: Quiet luacheck
Kim Alvefur <zash@zash.se>
parents: 10978
diff changeset
   100
	local unbound, err = softreq"lunbound"; -- luacheck: ignore 211/err
12151
02481502c3dc util.dependencies: Enable warning about missing lua-unbound
Kim Alvefur <zash@zash.se>
parents: 11977
diff changeset
   101
	if not unbound then
10967
80733851be8b util.dependencies: Add awareness of luaunbound
Kim Alvefur <zash@zash.se>
parents: 10910
diff changeset
   102
		missingdep("lua-unbound", {
12290
ad88732eea51 util.dependencies: Refer to 'apt' instead of 'apt-get'
Kim Alvefur <zash@zash.se>
parents: 12151
diff changeset
   103
				{ "Debian/Ubuntu", "sudo apt install lua-unbound" };
10967
80733851be8b util.dependencies: Add awareness of luaunbound
Kim Alvefur <zash@zash.se>
parents: 10910
diff changeset
   104
				{ "luarocks", "luarocks install luaunbound" };
80733851be8b util.dependencies: Add awareness of luaunbound
Kim Alvefur <zash@zash.se>
parents: 10910
diff changeset
   105
				{ "Source", "https://www.zash.se/luaunbound.html" };
80733851be8b util.dependencies: Add awareness of luaunbound
Kim Alvefur <zash@zash.se>
parents: 10910
diff changeset
   106
			}, "Old DNS resolver library will be used", err);
10969
f5d5fc409680 util.dependencies: Prefer net.unbound over net.adns
Kim Alvefur <zash@zash.se>
parents: 10967
diff changeset
   107
	else
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   108
		package.preload["prosody.net.adns"] = function ()
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   109
			local ub = require "prosody.net.unbound";
10969
f5d5fc409680 util.dependencies: Prefer net.unbound over net.adns
Kim Alvefur <zash@zash.se>
parents: 10967
diff changeset
   110
			return ub;
f5d5fc409680 util.dependencies: Prefer net.unbound over net.adns
Kim Alvefur <zash@zash.se>
parents: 10967
diff changeset
   111
		end
7770
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
   112
	end
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
   113
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   114
	local encodings, err = softreq "prosody.util.encodings"
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   115
	if not encodings then
7267
6d97895c2bd7 util.dependencies: Show the full error when a symbol is not found (i.e., when running Prosody with the wrong version of Lua).
Thijs Alkemade <me@thijsalkema.de>
parents: 7010
diff changeset
   116
		if err:match("module '[^']*' not found") then
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   117
			missingdep("prosody.util.encodings", {
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
   118
				{ "Windows", "Make sure you have encodings.dll from the Prosody distribution in util/" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
   119
				{ "GNU/Linux", "Run './configure' and 'make' in the Prosody source directory to build util/encodings.so" };
7878
3fbfd7210d78 util.dependencies: Normalize whitespace
Kim Alvefur <zash@zash.se>
parents: 7816
diff changeset
   120
			});
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   121
		else
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   122
			print "***********************************"
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   123
			print("util/encodings couldn't be loaded. Check that you have a recent version of libidn");
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   124
			print ""
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   125
			print("The full error was:");
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   126
			print(err)
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   127
			print "***********************************"
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   128
		end
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   129
		fatal = true;
2169
c06fdb6b57bd util.dependencies: Log an error if the current version of LuaSec installed contains The Bug (thanks Remko)
Matthew Wild <mwild1@gmail.com>
parents: 2158
diff changeset
   130
	end
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   131
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   132
	local hashes, err = softreq "prosody.util.hashes"
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   133
	if not hashes then
7267
6d97895c2bd7 util.dependencies: Show the full error when a symbol is not found (i.e., when running Prosody with the wrong version of Lua).
Thijs Alkemade <me@thijsalkema.de>
parents: 7010
diff changeset
   134
		if err:match("module '[^']*' not found") then
12979
d10957394a3c util: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents: 12576
diff changeset
   135
			missingdep("prosody.util.hashes", {
10910
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
   136
				{ "Windows", "Make sure you have hashes.dll from the Prosody distribution in util/" };
a1fed82c44b9 util.dependencies: Use util.human.io.table to replace custom layout code
Matthew Wild <mwild1@gmail.com>
parents: 10539
diff changeset
   137
				{ "GNU/Linux", "Run './configure' and 'make' in the Prosody source directory to build util/hashes.so" };
7878
3fbfd7210d78 util.dependencies: Normalize whitespace
Kim Alvefur <zash@zash.se>
parents: 7816
diff changeset
   138
			});
3fbfd7210d78 util.dependencies: Normalize whitespace
Kim Alvefur <zash@zash.se>
parents: 7816
diff changeset
   139
		else
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   140
			print "***********************************"
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   141
			print("util/hashes couldn't be loaded. Check that you have a recent version of OpenSSL (libcrypto in particular)");
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   142
			print ""
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   143
			print("The full error was:");
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   144
			print(err)
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   145
			print "***********************************"
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   146
		end
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   147
		fatal = true;
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   148
	end
7770
36bf9ed87ae1 util.dependencies: Add check and info about lua-bitops (for mod_websockets)
Kim Alvefur <zash@zash.se>
parents: 7769
diff changeset
   149
2510
97b5ea975cb9 util.dependencies, prosody, prosodyctl: Give util.dependencies a check_dependencies() function so the caller can decide what to do when dependencies aren't met - update prosody/prosodyctl for this change
Matthew Wild <mwild1@gmail.com>
parents: 2299
diff changeset
   150
	return not fatal;
408
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   151
end
eb1a0960cefb Friendlier messages on missing dependencies
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   152
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   153
local function log_warnings()
11962
31f83a645ce6 util.dependencies: Consider Lua 5.4 Supported:tm:
Kim Alvefur <zash@zash.se>
parents: 11145
diff changeset
   154
	if _VERSION > "Lua 5.4" then
7010
e28fbe6dd424 util.dependencies: Use prosody.log() instead of global log()
Matthew Wild <mwild1@gmail.com>
parents: 6781
diff changeset
   155
		prosody.log("warn", "Support for %s is experimental, please report any issues", _VERSION);
11963
814b750aa2d0 util.dependencies: Discourage Lua 5.1
Kim Alvefur <zash@zash.se>
parents: 11962
diff changeset
   156
	elseif _VERSION < "Lua 5.2" then
12573
b5d9f1829b15 util.dependencies: Deprecate support for Lua 5.1, this is your final warning
Kim Alvefur <zash@zash.se>
parents: 12335
diff changeset
   157
		prosody.log("warn", "%s support is deprecated, upgrade as soon as possible", _VERSION);
6781
4009ae66e0f0 util.dependencies: Only abort on Lua versions before 5.1, log a warning about 5.2 and above for now
Kim Alvefur <zash@zash.se>
parents: 6780
diff changeset
   158
	end
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   159
	local ssl = softreq"ssl";
3904
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   160
	if ssl then
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   161
		local major, minor, veryminor, patched = ssl._VERSION:match("(%d+)%.(%d+)%.?(%d*)(M?)");
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   162
		if not major or ((tonumber(major) == 0 and (tonumber(minor) or 0) <= 3 and (tonumber(veryminor) or 0) <= 2) and patched ~= "M") then
7362
a5a080c12c96 Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7267
diff changeset
   163
			prosody.log("error", "This version of LuaSec contains a known bug that causes disconnects, see https://prosody.im/doc/depends");
3904
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   164
		end
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   165
	end
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   166
	local lxp = softreq"lxp";
4421
ee65aa40ef60 util.dependencies, util.xmppstream: Move LuaExpat version checking to util.dependencies.
Waqas Hussain <waqas20@gmail.com>
parents: 4236
diff changeset
   167
	if lxp then
ee65aa40ef60 util.dependencies, util.xmppstream: Move LuaExpat version checking to util.dependencies.
Waqas Hussain <waqas20@gmail.com>
parents: 4236
diff changeset
   168
		if not pcall(lxp.new, { StartDoctypeDecl = false }) then
7010
e28fbe6dd424 util.dependencies: Use prosody.log() instead of global log()
Matthew Wild <mwild1@gmail.com>
parents: 6781
diff changeset
   169
			prosody.log("error", "The version of LuaExpat on your system leaves Prosody "
4421
ee65aa40ef60 util.dependencies, util.xmppstream: Move LuaExpat version checking to util.dependencies.
Waqas Hussain <waqas20@gmail.com>
parents: 4236
diff changeset
   170
				.."vulnerable to denial-of-service attacks. You should upgrade to "
6043
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   171
				.."LuaExpat 1.3.0 or higher as soon as possible. See "
7362
a5a080c12c96 Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7267
diff changeset
   172
				.."https://prosody.im/doc/depends#luaexpat for more information.");
6043
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   173
		end
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   174
		if not lxp.new({}).getcurrentbytecount then
7010
e28fbe6dd424 util.dependencies: Use prosody.log() instead of global log()
Matthew Wild <mwild1@gmail.com>
parents: 6781
diff changeset
   175
			prosody.log("error", "The version of LuaExpat on your system does not support "
6043
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   176
				.."stanza size limits, which may leave servers on untrusted "
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   177
				.."networks (e.g. the internet) vulnerable to denial-of-service "
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   178
				.."attacks. You should upgrade to LuaExpat 1.3.0 or higher as "
29d2dd705148 util.dependencies: Log error when LuaExpat is not capable of enforcing stanza size limits
Matthew Wild <mwild1@gmail.com>
parents: 4421
diff changeset
   179
				.."soon as possible. See "
7362
a5a080c12c96 Update every link to the documentation to use HTTPS
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 7267
diff changeset
   180
				.."https://prosody.im/doc/depends#luaexpat for more information.");
4421
ee65aa40ef60 util.dependencies, util.xmppstream: Move LuaExpat version checking to util.dependencies.
Waqas Hussain <waqas20@gmail.com>
parents: 4236
diff changeset
   181
		end
ee65aa40ef60 util.dependencies, util.xmppstream: Move LuaExpat version checking to util.dependencies.
Waqas Hussain <waqas20@gmail.com>
parents: 4236
diff changeset
   182
	end
3904
f93163081b3c prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents: 2925
diff changeset
   183
end
742
b9f59372eb4e util.dependencies: Show useful messages when our own libraries are not found, too
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
   184
6780
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   185
return {
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   186
	softreq = softreq;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   187
	missingdep = missingdep;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   188
	check_dependencies = check_dependencies;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   189
	log_warnings = log_warnings;
5de6b93d0190 util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents: 6067
diff changeset
   190
};