1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
apk = require("apk")
local M = {}
--"http://mirrors.kernel.org/archlinux/"
local url_base="http://ftp.lysator.liu.se/pub/archlinux/"
local upstream_repos = {
"core/os/i686/core.db.tar.gz",
"extra/os/i686/extra.db.tar.gz",
"community/os/i686/community.db.tar.gz",
}
local db = {}
local pkgmap = {
["freetype"] = "freetype2",
["gmp5"] = "gmp",
["gstreamer" ] = "gstreamer0.10",
["gstreamer1"] = "gstreamer",
["gtk+2.0"] = "gtk2",
["mpfr3"] = "mpfr",
["python"] = "python2",
["mpc1" ] = "libmpc",
[ "libmpc" ] = "",
["glib" ] = "glib2",
["libnl3" ] = "libnl",
["libnl" ] = "",
}
local version_regex = {
["%.[pP](%d+)$"] = "_p%1",
["([^_])p(%d+)$"] = "%1_p%2",
["%.([a-z])$"] = "_%1",
["(%d)[Rr][Cc](%d+)"] = "%1_rc%2",
["(%d)b(%d+)$"] = "%1_beta%2",
}
local function fix_version(ver)
local search, replace
local str = ver
for search, replace in pairs(version_regex) do
str = string.gsub(str, search, replace)
end
return str
end
local function add_version(repodb, pkgname, pkgver, pkgrel)
if pkgname == nil then
return
end
local name = pkgmap[pkgname]
if name == nil then
name = pkgname
end
if db[name] == nil then
db[name] = {}
end
table.insert(db[name], {
repo = repodb,
origver=pkgver,
pkgver=fix_version(pkgver),
pkgrel=pkgrel,
pkgname=pkgname,
})
end
local function read_upstream_repodb(repodb)
local f
local url = url_base..repodb
local dbfile = string.gsub(repodb, ".*/", "")
local line
-- os.execute("wget "..url)
-- local f = io.popen("tar -ztf "..dbfile.." 2>/dev/null")
local f = io.popen("curl --silent "..url.." | tar -zt 2>/dev/null")
local pkgdb = {}
for line in f:lines() do
local pkgname, pkgver, pkgrel = string.match(line, "^(.*)-([0-9]+.*)-([0-9]+)/$")
add_version(repodb, pkgname, pkgver, pkgrel)
end
f:close()
end
local function is_newer(arch, pkgver)
if not apk.version_is_less(pkgver, arch) then
return nil
end
return arch
-- print(pkgname.."-"..arch.pkgver.." (current: "..pkgver..")")
end
local function find_newer(self)
local pkgname = self.pkg.pkgname
local pkgver = self.pkg.pkgver
local i, p, newest
if self.db[pkgname] == nil then
return
end
newest = "0"
for i, p in pairs(self.db[pkgname]) do
if apk.version_is_less(newest, p.pkgver) then
newest = p.pkgver
end
end
if is_newer(newest, pkgver) then
return newest
end
return nil
end
local function exists(self, pkgname)
return self.db[pkgname] ~= nil
end
local repos_initialized = false
local function init_repos()
if repos_initialized then
return db
end
for i,repo in pairs(upstream_repos) do
io.stderr:write("Reading upstream "..repo.."\n")
read_upstream_repodb(repo)
end
repos_initialized = true
return db
end
function M.init(pkg)
init_repos()
if db[pkg.pkgname] == nil then
return nil
end
return {
provider_name = "archlinux",
db = db,
find_newer = find_newer,
pkg = pkg
}
end
return M
|