1 | -- This is a helper script for update-watch |
---|
2 | -- run apt-get and extract packaged that to be installed, |
---|
3 | -- updated, and removed. |
---|
4 | |
---|
5 | basefile = "/var/tmp/update-watch-info." |
---|
6 | filename = basefile.."tmp" |
---|
7 | |
---|
8 | -- Function to extract real package name from allow-duplicated packages. |
---|
9 | function realname(name) |
---|
10 | local s, e, name = string.find(name, "(.+)#") |
---|
11 | return name |
---|
12 | end |
---|
13 | |
---|
14 | -- Open output file that holds list of to-be changed packages, |
---|
15 | file = io.open(filename, "w") |
---|
16 | if not file then |
---|
17 | print("error: can't open output file at "..filename) |
---|
18 | return |
---|
19 | end |
---|
20 | |
---|
21 | -- get list ofmanually held packages and store it to local table. |
---|
22 | -- those packages should be ignored by update-watch. |
---|
23 | |
---|
24 | local holdlist = confgetlist("RPM::Hold") |
---|
25 | |
---|
26 | for i, expr in ipairs(holdlist) do |
---|
27 | holdlist[i] = rex.new(expr) |
---|
28 | end |
---|
29 | |
---|
30 | -- mark whole system for upgrading to enable executing |
---|
31 | -- apt-get upgrade --simulate for non root users. |
---|
32 | |
---|
33 | markupgrade() |
---|
34 | |
---|
35 | -- *NOTE* bellow section are copied from allow-duplicated.lua |
---|
36 | -- to handle allow-duplicated packages properly. |
---|
37 | ----------<start copied block>---------- |
---|
38 | -- Automatically install newer versions of all packages which |
---|
39 | -- are registered in the Allow-Duplicated scheme and are matched |
---|
40 | -- by the regular expressions in RPM::Allow-Duplicated-Upgrade. |
---|
41 | |
---|
42 | -- Compile expressions with package names which should |
---|
43 | -- be considered for upgrade. |
---|
44 | local updatelist = confgetlist("RPM::Allow-Duplicated-Upgrade") |
---|
45 | for i, expr in ipairs(updatelist) do |
---|
46 | updatelist[i] = rex.new(expr) |
---|
47 | end |
---|
48 | |
---|
49 | if table.getn(updatelist) ~= 0 then |
---|
50 | |
---|
51 | -- Gather information about Allow-Duplicated packges. |
---|
52 | local canddups = {} |
---|
53 | local curdups = {} |
---|
54 | for i, pkg in pairs(pkglist()) do |
---|
55 | local name = realname(pkgname(pkg)) |
---|
56 | if name then |
---|
57 | if pkgvercur(pkg) then |
---|
58 | if not curdups[name] then |
---|
59 | curdups[name] = {} |
---|
60 | end |
---|
61 | table.insert(curdups[name], |
---|
62 | verstr(pkgvercur(pkg))) |
---|
63 | elseif pkgvercand(pkg) then |
---|
64 | if not canddups[name] then |
---|
65 | canddups[name] = {} |
---|
66 | end |
---|
67 | table.insert(canddups[name], |
---|
68 | verstr(pkgvercand(pkg))) |
---|
69 | end |
---|
70 | end |
---|
71 | end |
---|
72 | |
---|
73 | -- Compile expressions with package names which should be hold. |
---|
74 | local holdlist = confgetlist("RPM::Hold") |
---|
75 | for i, expr in ipairs(holdlist) do |
---|
76 | holdlist[i] = rex.new(expr) |
---|
77 | end |
---|
78 | |
---|
79 | -- Remove packages without any matches in updatelist, or with |
---|
80 | -- any matches in holdlist. |
---|
81 | for name, _ in pairs(curdups) do |
---|
82 | local found = false |
---|
83 | for i, expr in ipairs(updatelist) do |
---|
84 | if expr:match(name) then |
---|
85 | found = true |
---|
86 | break |
---|
87 | end |
---|
88 | end |
---|
89 | if found then |
---|
90 | for i, expr in ipairs(holdlist) do |
---|
91 | if expr:match(name) then |
---|
92 | found = false |
---|
93 | break |
---|
94 | end |
---|
95 | end |
---|
96 | end |
---|
97 | if not found then |
---|
98 | curdups[name] = nil |
---|
99 | end |
---|
100 | end |
---|
101 | |
---|
102 | -- Mark the newest packages for installation. |
---|
103 | for name, _ in pairs(curdups) do |
---|
104 | if canddups[name] then |
---|
105 | -- Check the best candidate version. |
---|
106 | local bestver = nil |
---|
107 | for i, ver in ipairs(canddups[name]) do |
---|
108 | if not bestver or |
---|
109 | verstrcmp(bestver, ver) == -1 then |
---|
110 | bestver = ver |
---|
111 | end |
---|
112 | end |
---|
113 | |
---|
114 | -- Now check if it's newer than all installed |
---|
115 | -- versions. |
---|
116 | for i, ver in ipairs(curdups[name]) do |
---|
117 | if verstrcmp(ver, bestver) == 1 then |
---|
118 | bestver = nil |
---|
119 | break |
---|
120 | end |
---|
121 | end |
---|
122 | |
---|
123 | -- Finally, mark it for installation. |
---|
124 | if bestver then |
---|
125 | markinstall(name.."#"..bestver) |
---|
126 | end |
---|
127 | end |
---|
128 | end |
---|
129 | end |
---|
130 | ----------<end copied block>---------- |
---|
131 | |
---|
132 | -- print upgrade/new install/remove/hold package name if exist. |
---|
133 | -- *NOTE: newinstall package appeares as upgrade one too. naze... |
---|
134 | |
---|
135 | local new = {} |
---|
136 | local upgrade = {} |
---|
137 | local remove = {} |
---|
138 | local hold = {} |
---|
139 | |
---|
140 | for i, pkg in pairs(pkglist()) do |
---|
141 | if statnewinstall(pkg) then |
---|
142 | table.insert(new,string.format("new:%s\n",pkgname(pkg))) |
---|
143 | elseif statupgrade(pkg) then |
---|
144 | table.insert(upgrade,string.format("upgrade:%s\n",pkgname(pkg))) |
---|
145 | end |
---|
146 | |
---|
147 | if statremove(pkg) then |
---|
148 | table.insert(remove,string.format("remove:%s\n",pkgname(pkg))) |
---|
149 | end |
---|
150 | |
---|
151 | if pkgvercur(pkg) ~= nil and pkgvercand(pkg) ~= nil and statupgrade(pkg) == nil then |
---|
152 | local found = false |
---|
153 | for i, expr in ipairs(holdlist) do |
---|
154 | if expr:match(pkgname(pkg)) then |
---|
155 | found = true |
---|
156 | end |
---|
157 | end |
---|
158 | if not found then |
---|
159 | table.insert(hold,string.format("hold:%s\n",pkgname(pkg))) |
---|
160 | end |
---|
161 | end |
---|
162 | end |
---|
163 | |
---|
164 | local function write(index, str) |
---|
165 | file:write(str) |
---|
166 | end |
---|
167 | table.foreach(new, write) |
---|
168 | table.foreach(upgrade, write) |
---|
169 | table.foreach(remove, write) |
---|
170 | table.foreach(hold, write) |
---|
171 | file:close() |
---|
172 | |
---|
173 | os.execute("mv "..filename.." "..basefile.."`id -u`") |
---|