1 | #ifndef SYSTEM_UPDATE_H |
---|
2 | #define SYSTEM_UPDATE_H |
---|
3 | |
---|
4 | void screensystem_update(int mode) |
---|
5 | { |
---|
6 | debug(50, "(start) mode=%d", mode); |
---|
7 | int rcret = 0, ret = 0; |
---|
8 | |
---|
9 | status.hangtime = 99999; |
---|
10 | struct skin* load = getscreen("loading"); |
---|
11 | drawscreen(load, 0, 0); |
---|
12 | |
---|
13 | char* tmpstr = NULL; |
---|
14 | char* cmd = NULL; |
---|
15 | |
---|
16 | struct update* node = createupdatelist(mode); |
---|
17 | |
---|
18 | struct skin* systemupdate = getscreen(node->skinname); |
---|
19 | struct skin* filelistpath = getscreennode(systemupdate, "filelistpath"); |
---|
20 | struct skin* filelist = getscreennode(systemupdate, "filelist"); |
---|
21 | struct skin* device = getscreennode(systemupdate, "device"); |
---|
22 | struct skin* b6 = getscreennode(systemupdate, "b6"); |
---|
23 | |
---|
24 | if(node->imgtype == 1) |
---|
25 | changetext(b6, _("stable")); |
---|
26 | else |
---|
27 | changetext(b6, _("unstable")); |
---|
28 | |
---|
29 | if(!file_exist("/etc/.beta")) b6->hidden = YES; |
---|
30 | |
---|
31 | if(mode == 2 || mode == 3) |
---|
32 | { |
---|
33 | char* devicelist = command("cat /proc/diskstats | awk {'print $3'} | grep 'sd[a-z][0-9]'"); |
---|
34 | char* rootpart = command("cat /proc/cmdline | sed 's/^.*root=//;s/ .*$//' | sed 's!/dev/!!'"); |
---|
35 | |
---|
36 | if(devicelist != NULL && strlen(devicelist) != 0) |
---|
37 | { |
---|
38 | char* pch; |
---|
39 | char* label = NULL; |
---|
40 | char* showname = NULL; |
---|
41 | char* version = NULL; |
---|
42 | pch = strtok (devicelist, "\n"); |
---|
43 | int count = 0; |
---|
44 | while(pch != NULL) |
---|
45 | { |
---|
46 | count += 1; |
---|
47 | label = get_label(pch); |
---|
48 | |
---|
49 | if(ostrstr(label, "MINI") != NULL) |
---|
50 | { |
---|
51 | cmd = ostrcat("cat /autofs/", pch, 0, 0); |
---|
52 | cmd = ostrcat(cmd, "/etc/version", 1, 0); |
---|
53 | version = command(cmd); |
---|
54 | |
---|
55 | showname = ostrcat(label, "-", 0, 0); |
---|
56 | showname = ostrcat(showname, pch, 1, 0); |
---|
57 | showname = ostrcat(showname, "-", 1, 0); |
---|
58 | |
---|
59 | if(version == NULL) |
---|
60 | showname = ostrcat(showname, _("non-version"), 1, 0); |
---|
61 | else |
---|
62 | showname = ostrcat(showname, strstrip(version), 1, 0); |
---|
63 | |
---|
64 | if(ostrcmp(pch, rootpart) == 0) |
---|
65 | showname = ostrcat(showname, " (active)", 1, 0); |
---|
66 | |
---|
67 | debug(40, "addchoicebox: device=%s, label=%s showname=%s", pch, label, showname); |
---|
68 | addchoicebox(device, label, _(showname)); |
---|
69 | |
---|
70 | free(cmd), cmd = NULL; |
---|
71 | free(showname), showname = NULL; |
---|
72 | free(version), version = NULL; |
---|
73 | } |
---|
74 | |
---|
75 | pch = strtok (NULL, "\n"); |
---|
76 | free(label), label = NULL; |
---|
77 | } |
---|
78 | free(pch), pch = NULL; |
---|
79 | |
---|
80 | } |
---|
81 | else |
---|
82 | addchoicebox(device, "no device found", "no device found"); |
---|
83 | |
---|
84 | free(devicelist), devicelist = NULL; |
---|
85 | free(rootpart), rootpart = NULL; |
---|
86 | } |
---|
87 | |
---|
88 | setchoiceboxselection(device, getconfig("device", NULL)); |
---|
89 | |
---|
90 | clearscreen(load); |
---|
91 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
92 | addscreenrc(systemupdate, filelist); |
---|
93 | |
---|
94 | |
---|
95 | if(mode == 2 || mode == 3) |
---|
96 | { |
---|
97 | delrc(getrcconfigint("rcright", NULL), systemupdate, filelist); |
---|
98 | delrc(getrcconfigint("rcleft", NULL), systemupdate, filelist); |
---|
99 | addscreenrc(systemupdate, device); |
---|
100 | } |
---|
101 | |
---|
102 | while(1) |
---|
103 | { |
---|
104 | rcret = waitrc(systemupdate, 0, 0); |
---|
105 | debug(40, "while status"); |
---|
106 | |
---|
107 | |
---|
108 | if(rcret == getrcconfigint("rcexit", NULL) || rcret == getrcconfigint("rcred", NULL)) |
---|
109 | break; |
---|
110 | else if(rcret == getrcconfigint("rcyellow", NULL)) |
---|
111 | { |
---|
112 | if(mode == 0 || mode == 2) |
---|
113 | { |
---|
114 | char* cmd = NULL; |
---|
115 | |
---|
116 | drawscreen(load, 0, 0); |
---|
117 | cmd = ostrcat(cmd, "/sbin/update.sh getfilelist", 1, 0); |
---|
118 | cmd = ostrcat(cmd, node->auth, 1, 0); |
---|
119 | if(node->imgtype == 1) |
---|
120 | cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0); |
---|
121 | else |
---|
122 | cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); |
---|
123 | system(cmd); |
---|
124 | free(cmd),cmd = NULL; |
---|
125 | clearscreen(load); |
---|
126 | } |
---|
127 | |
---|
128 | drawscreen(systemupdate, 0, 0); |
---|
129 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
130 | addscreenrc(systemupdate, filelist); |
---|
131 | continue; |
---|
132 | } |
---|
133 | else if(rcret == getrcconfigint("rcblue", NULL)) |
---|
134 | { |
---|
135 | if(mode == 0 || mode == 2) |
---|
136 | { |
---|
137 | if(node->imgtype == 0) |
---|
138 | { |
---|
139 | int pinret = 0; |
---|
140 | |
---|
141 | if(!file_exist("/etc/.beta")) |
---|
142 | pinret = screenpincheck(3, NULL); |
---|
143 | |
---|
144 | if(pinret == 0) |
---|
145 | { |
---|
146 | node->imgtype = 1; |
---|
147 | changetext(b6, _("stable")); |
---|
148 | } |
---|
149 | } |
---|
150 | else |
---|
151 | { |
---|
152 | node->imgtype = 0; |
---|
153 | changetext(b6, _("unstable")); |
---|
154 | } |
---|
155 | |
---|
156 | char* cmd = NULL; |
---|
157 | |
---|
158 | drawscreen(load, 0, 0); |
---|
159 | cmd = ostrcat(cmd, "/sbin/update.sh getfilelist", 1, 0); |
---|
160 | cmd = ostrcat(cmd, node->auth, 1, 0); |
---|
161 | if(node->imgtype == 1) |
---|
162 | cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0); |
---|
163 | else |
---|
164 | cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); |
---|
165 | system(cmd); |
---|
166 | free(cmd),cmd = NULL; |
---|
167 | clearscreen(load); |
---|
168 | } |
---|
169 | |
---|
170 | drawscreen(systemupdate, 0, 0); |
---|
171 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
172 | addscreenrc(systemupdate, filelist); |
---|
173 | continue; |
---|
174 | } |
---|
175 | else if(rcret == getrcconfigint("rcok", NULL) || rcret == getrcconfigint("rcgreen", NULL)) |
---|
176 | { |
---|
177 | if(filelist->select != NULL && filelist->select->input != NULL) |
---|
178 | continue; |
---|
179 | else if(filelist->select != NULL && filelist->select->input == NULL) |
---|
180 | { |
---|
181 | tmpstr = createpath(filelistpath->text, filelist->select->text); |
---|
182 | debug(40, "tmpstr: %s", tmpstr); |
---|
183 | |
---|
184 | char* cmd = NULL; |
---|
185 | if(checkrealbox("DM900") == 1 || checkrealbox("HD51") == 1) |
---|
186 | cmd = ostrcat(cmd, "/sbin/update2.sh ", 1, 0); |
---|
187 | else |
---|
188 | cmd = ostrcat(cmd, "/sbin/update.sh ", 1, 0); |
---|
189 | cmd = ostrcat(cmd, node->type, 1, 0); |
---|
190 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
191 | |
---|
192 | char* msgtxt = NULL; |
---|
193 | writeallconfig(1); |
---|
194 | |
---|
195 | debug(40, "Update: update with log"); |
---|
196 | if(ostrstr(filelist->select->text, "_USB_") != NULL || ostrstr(filelist->select->text, "_FULL_") != NULL || ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL || ostrstr(filelist->select->text, "_UPDATENFI_") != NULL || ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL) |
---|
197 | { |
---|
198 | if(ostrstr(filelist->select->text, "_FULL_") != NULL) |
---|
199 | cmd = ostrcat(cmd, "full ", 1, 0); |
---|
200 | else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL) |
---|
201 | cmd = ostrcat(cmd, "fullbackup ", 1, 0); |
---|
202 | else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL) |
---|
203 | cmd = ostrcat(cmd, "updatenfi ", 1, 0); |
---|
204 | else if(ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL) |
---|
205 | cmd = ostrcat(cmd, "updateusb ", 1, 0); |
---|
206 | else if(ostrstr(filelist->select->text, ".tar.gz") != NULL) |
---|
207 | { |
---|
208 | cmd = ostrcat(cmd, device->ret, 1, 0); |
---|
209 | cmd = ostrcat(cmd, " ", 1, 0); |
---|
210 | } |
---|
211 | else if(ostrstr(filelist->select->text, ".zip") != NULL) |
---|
212 | cmd = ostrcat(cmd, "full ", 1, 0); |
---|
213 | |
---|
214 | cmd = ostrcat(cmd, tmpstr, 1, 0); |
---|
215 | cmd = ostrcat(cmd, node->auth, 1, 0); |
---|
216 | if(node->imgtype == 1) |
---|
217 | cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0); |
---|
218 | else |
---|
219 | cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); |
---|
220 | |
---|
221 | if(file_exist("/var/swap")) |
---|
222 | { |
---|
223 | if(!file_exist("/var/swap/logs")) |
---|
224 | mkdir("/var/swap/logs", 777); |
---|
225 | |
---|
226 | if(file_exist("/etc/.beta") && file_exist("/var/swap/logs")) |
---|
227 | cmd = ostrcat(cmd, " > /var/swap/logs/update_debug.log 2>&1", 1, 0); |
---|
228 | } |
---|
229 | else if(checkbox("ATEMIO510") != 1 && checkbox("UFS910") != 1 && checkbox("UFS922") != 1 && checkbox("ATEVIO700") != 1 && checkbox("ATEVIO7000") != 1 && checkbox("IPBOX91") != 1 && checkbox("IPBOX900") != 1 && checkbox("IPBOX910") != 1 && checkbox("IPBOX9000") != 1 && checkrealbox("DM520") != 1) |
---|
230 | { |
---|
231 | if(!file_exist("/mnt/logs")) |
---|
232 | mkdir("/mnt/logs", 777); |
---|
233 | |
---|
234 | if(file_exist("/etc/.beta") && file_exist("/mnt/logs")) |
---|
235 | cmd = ostrcat(cmd, " > /mnt/logs/update_debug.log 2>&1", 1, 0); |
---|
236 | } |
---|
237 | |
---|
238 | if(ostrstr(filelist->select->text, "_FULL_") != NULL) |
---|
239 | msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0); |
---|
240 | else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL) |
---|
241 | msgtxt = ostrcat(msgtxt, _("starting Full Update (from backup) ?"), 1, 0); |
---|
242 | else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL) |
---|
243 | msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0); |
---|
244 | else if(ostrstr(filelist->select->text, ".tar.gz") != NULL) |
---|
245 | msgtxt = ostrcat(msgtxt, _("starting Usb Update ?"), 1, 0); |
---|
246 | else if(ostrstr(filelist->select->text, ".zip") != NULL) |
---|
247 | msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0); |
---|
248 | } |
---|
249 | |
---|
250 | clearscreen(systemupdate); |
---|
251 | resettvpic(); |
---|
252 | if(msgtxt == NULL) |
---|
253 | { |
---|
254 | textbox(_("Message"), _("Error file not supported"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0); |
---|
255 | drawscreen(systemupdate, 0, 0); |
---|
256 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
257 | addscreenrc(systemupdate, filelist); |
---|
258 | } |
---|
259 | |
---|
260 | if(textbox(_("Message"), msgtxt, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1) |
---|
261 | { |
---|
262 | debug(40, "update started cmd: %s", cmd); |
---|
263 | status.sec = 0; //deactivate spinner |
---|
264 | |
---|
265 | ret = checkshutdown(6); |
---|
266 | if(ret == 0) |
---|
267 | { |
---|
268 | system(cmd); |
---|
269 | //should only reached if system fails |
---|
270 | textbox(_("Message"), _("Can't start system update\nSyntax Error on updatefile"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0); |
---|
271 | debug(40, "update error cmd: %s", cmd); |
---|
272 | } |
---|
273 | drawscreen(systemupdate, 0, 0); |
---|
274 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
275 | addscreenrc(systemupdate, filelist); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | debug(40, "update canceled cmd: %s", cmd); |
---|
280 | drawscreen(systemupdate, 0, 0); |
---|
281 | getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL); |
---|
282 | addscreenrc(systemupdate, filelist); |
---|
283 | } |
---|
284 | |
---|
285 | free(cmd); cmd = NULL; |
---|
286 | free(msgtxt); msgtxt = NULL; |
---|
287 | free(tmpstr); tmpstr = NULL; |
---|
288 | continue; |
---|
289 | } |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | freeupdatelist(node); |
---|
294 | // free(auth); auth = NULL; |
---|
295 | delownerrc(systemupdate); |
---|
296 | clearscreen(systemupdate); |
---|
297 | |
---|
298 | delownerrc(systemupdate); |
---|
299 | clearscreen(systemupdate); |
---|
300 | |
---|
301 | status.hangtime = getconfigint("hangtime", NULL); |
---|
302 | debug(40, "end"); |
---|
303 | } |
---|
304 | |
---|
305 | |
---|
306 | #endif |
---|