Commit bf9fda1c authored by mcmodder's avatar mcmodder
Browse files

Будем переписывать нашего пакмана...

parent 4a1c140c
Pipeline #174 passed with stage
in 11 seconds
--pacman v2.0
local component = require("component")
local fs = require("filesystem")
local seri = require("serialization")
local shell = require("shell")
if not component.isAvailable("internet") then
error("This program requires an internet card to run.")
return
end
local args, ops = shell.parse(...)
-----------------------------------
local function internetRequest(url)
local success, response = pcall(component.internet.request, url)
if success then
local responseData = ""
while true do
local data, responseChunk = response.read()
if data then
responseData = responseData .. data
else
if responseChunk then
return false, responseChunk
else
return true, responseData
end
end
end
else
return false, reason
end
end
local function fetchRepos()
local repoData = {}
local defaultRepo
local repoFile = io.open("/etc/pacman/repos", "r")
if repoFile then
local fetchedRepos = 0
for line in repoFile:lines() do
local err
local name,url = line:match("^([^;]+)%|(.+)")
if url then
local success, response = internetRequest(url)
if success then
defaultRepo = defaultRepo or name
repoData[name]=seri.unserialize(response)
print(name.." fetched")
else
err = response
end
else
err = "Can't fetch repo "..(name or "nil")..", invalid string "..line
end
if err then print(err) else fetchedRepos = fetchedRepos + 1 end
end
repoFile:close()
print("Fetched "..fetchedRepos.." repos")
return repoData, defaultRepo
else
print("No /etc/pacman/repos file!")
fs.makeDirectory("/etc/pacman")
repoFile = io.open("/etc/pacman/repos", "w")
if repoFile then
repoFile:write("Default|https://api.mcmodder.ru/repo.txt")
repoFile:close()
fetchRepos()
else
error("Can't write default repos list!")
end
end
end
local function getInstalledPackages()
local file = io.open("/etc/pacman/installed","r")
if file then
local answer = seri.unserialize(file:read("*all"))
file:close()
return answer
else
print("It's first pacman run... OKAY :(")
file = io.open("etc/pacman/installed", "w")
if file then
file:write('{pacman={version=""}}')
file:close()
getInstalledPackages()
else
error("Can't write /etc/pacman/installed file!")
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment