From 2073fe5d88215dddd9a9e6421afaea7ab7db955a Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sun, 26 Sep 2021 17:35:54 +0200 Subject: 2021-09-26 16:50:00 --- scripts/context/lua/mtx-install.lua | 44 +++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/context/lua/mtx-install.lua b/scripts/context/lua/mtx-install.lua index 9087a6524..826098cc7 100644 --- a/scripts/context/lua/mtx-install.lua +++ b/scripts/context/lua/mtx-install.lua @@ -14,7 +14,7 @@ local helpinfo = [[ mtx-install ConTeXt Installer - 2.00 + 2.01 @@ -28,27 +28,55 @@ local helpinfo = [[ update context wipe the cache create list of files + use curl for https ]] +local type, tonumber = type, tonumber local gsub, find, escapedpattern = string.gsub, string.find, string.escapedpattern local round = math.round local savetable, loadtable, sortedhash = table.save, table.load, table.sortedhash local copyfile, joinfile, filesize, dirname, addsuffix, basename = file.copy, file.join, file.size, file.dirname, file.addsuffix, file.basename local isdir, isfile, walkdir, pushdir, popdir, currentdir = lfs.isdir, lfs.isfile, lfs.dir, lfs.chdir, dir.push, dir.pop, currentdir local mkdirs, globdir = dir.mkdirs, dir.glob -local osremove, osexecute, ostype = os.remove, os.execute, os.type +local osremove, osexecute, ostype, resultof = os.remove, os.execute, os.type, os.resultof local savedata = io.savedata local formatters = string.formatters +local httprequest = socket.http.request -local fetch = socket.http.request +local usecurl = false + +local function checkcurl() + local s = resultof("curl --version") + return type(s) == "string" and find(s,"libcurl") and find(s,"rotocols") +end + +local function fetch(url) + local data = nil + local detail = nil + if usecurl and find(url,"^https") then + data = resultof("curl " .. url) + else + data, detail = httprequest(url) + end + if type(data) ~= "string" then + data = false + elseif #data < 2048 then + local n, t = find(data,"%s*%s*(%d+)%s(.-)") + if tonumber(n) then + data = false + detail = n .. " " .. t + end + end + return data, detail +end local application = logs.application { name = "mtx-install", - banner = "ConTeXt Installer 2.00", + banner = "ConTeXt Installer 2.01", helpinfo = helpinfo, } @@ -603,6 +631,14 @@ function install.update() report("update, done") end +if environment.argument("secure") then + usecurl = checkcurl() + if not usecurl then + report("no curl installed, quitting") + os.exit() + end +end + if environment.argument("identify") then install.identify() elseif environment.argument("install") then -- cgit v1.2.3