Package filesystem: Scripts

Pre trans

migrate = false
if posix.stat("/usr") then
  -- See if we need to migrate to merged-usr.
  for i, d in pairs({
"/bin",
"/sbin",
"/lib",
"/lib64",
}) do
    local dt = posix.stat(d, "type")
    if dt == "directory" then
      migrate = true
    end
  end
end

if migrate then
  -- We cannot use built-in print in case standard output
  -- is not line-buffered, e. g. points to a file.
  -- We know the shell is available at this point, so use it
  -- to print log lines.
  function print_l(s)
    os.execute('printf "%s: %s\n" "filesystem-3.1-alt1" "' .. s .. '"')
  end
  print_l("Migration is needed before the package can be installed.")
  hier_convert_prog = "/usr/libexec/usrmerge/hier-convert"
  if not posix.stat(hier_convert_prog) then
    error("Looks like usrmerge-hier-convert is not installed. Aborting.")
  end
  print_l("Starting usrmerge-hier-convert...")
  assert(os.execute(hier_convert_prog))
end