source: titan/titan/system_update.h @ 44550

Last change on this file since 44550 was 43913, checked in by aafsvn, 5 years ago

fix tpk install dont show swap allways

File size: 12.3 KB
Line 
1#ifndef SYSTEM_UPDATE_H
2#define SYSTEM_UPDATE_H
3
4void 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#ifdef OEBUILD
34                char* devicelist = command("cat /boot/STARTUP* | sed -nr 's/.*root=\\/dev\\/([^\\/]+) rootfstype.*/\\1/p' | sort -u");
35#else
36                char* devicelist = command("cat /proc/diskstats | awk {'print $3'} | grep 'sd[a-z][0-9]'");
37#endif
38                char* rootpart = command("cat /proc/cmdline | sed 's/^.*root=//;s/ .*$//' | sed 's!/dev/!!'");
39
40                if(devicelist != NULL && strlen(devicelist) != 0)
41                {
42                        char* pch;
43                        char* label = NULL;
44                        char* showname = NULL;
45                        char* version = NULL;
46                        pch = strtok (devicelist, "\n");
47                        int count = 0;
48                        while(pch != NULL)
49                        {
50                                count += 1;
51#ifdef OEBUILD
52                                label= ostrcat("STARTUP_", oitoa(count), 0, 1);
53#else
54                                label = get_label(pch);
55#endif
56                                if(ostrstr(label, "MINI") != NULL || ostrstr(label, "STARTUP") != NULL)
57                                {
58                                        cmd = ostrcat("cat /autofs/", pch, 0, 0);
59                                        cmd = ostrcat(cmd, "/etc/version-svn", 1, 0);
60                                        version = command(cmd);
61
62                                        showname = ostrcat(label, "-", 0, 0);
63                                        showname = ostrcat(showname, pch, 1, 0);
64                                        showname = ostrcat(showname, "-", 1, 0);
65
66                                        if(version == NULL)
67                                                showname = ostrcat(showname, _("non-version"), 1, 0);
68                                        else
69                                                showname = ostrcat(showname, strstrip(version), 1, 0);
70
71                                        if(ostrcmp(pch, rootpart) == 0)
72                                                showname = ostrcat(showname, " (active)", 1, 0);
73
74                                        debug(40, "addchoicebox: device=%s, label=%s showname=%s", pch, label, showname);
75                                        addchoicebox(device, label, _(showname));
76
77                                        free(cmd), cmd = NULL;
78                                        free(showname), showname = NULL;
79                                        free(version), version = NULL;
80                                }
81
82                                pch = strtok (NULL, "\n");
83                                free(label), label = NULL;
84                        }
85                        free(pch), pch = NULL;
86
87                }
88                else
89                        addchoicebox(device, "no device found", "no device found");
90
91                free(devicelist), devicelist = NULL;
92                free(rootpart), rootpart = NULL;
93        }
94
95        setchoiceboxselection(device, getconfig("device", NULL));
96
97        clearscreen(load);
98        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
99        addscreenrc(systemupdate, filelist);
100
101
102        if(mode == 2 || mode == 3)
103        {
104                delrc(getrcconfigint("rcright", NULL), systemupdate, filelist);
105                delrc(getrcconfigint("rcleft", NULL), systemupdate, filelist);
106                addscreenrc(systemupdate, device);
107        }
108
109        while(1)
110        {
111                rcret = waitrc(systemupdate, 0, 0);
112                debug(40, "while status");
113
114
115                if(rcret == getrcconfigint("rcexit", NULL) || rcret == getrcconfigint("rcred", NULL))
116                        break;
117                else if(rcret == getrcconfigint("rcyellow", NULL))
118                {
119                        if(mode == 0 || mode == 2)
120                        {
121                                char* cmd = NULL;
122
123                                drawscreen(load, 0, 0);
124                                cmd = ostrcat(cmd, "/sbin/update.sh getfilelist", 1, 0);
125                                cmd = ostrcat(cmd, node->auth, 1, 0);
126#ifdef OEBUILD
127                                if(node->imgtype == 1)
128                                        cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
129                                else
130                                        cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);       
131#else
132                                if(node->imgtype == 1)
133                                        cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
134                                else
135                                        cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); 
136#endif
137                                system(cmd);
138                                free(cmd),cmd = NULL;
139                                clearscreen(load);
140                        }
141
142                        drawscreen(systemupdate, 0, 0);
143                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
144                        addscreenrc(systemupdate, filelist);
145                        continue;
146                }
147                else if(rcret == getrcconfigint("rcblue", NULL))
148                {
149                        if(mode == 0 || mode == 2)
150                        {
151                                if(node->imgtype == 0)
152                                {
153                                        int pinret = 0;
154                                       
155                                        if(!file_exist("/etc/.beta"))
156                                                pinret = screenpincheck(3, NULL);
157                                       
158                                        if(pinret == 0)
159                                        {
160                                                node->imgtype = 1;
161                                                changetext(b6, _("stable"));
162                                        }
163                                }
164                                else
165                                {
166                                        node->imgtype = 0;
167                                        changetext(b6, _("unstable"));
168                                }
169                       
170                                char* cmd = NULL;
171
172                                drawscreen(load, 0, 0);
173                                cmd = ostrcat(cmd, "/sbin/update.sh getfilelist", 1, 0);
174                                cmd = ostrcat(cmd, node->auth, 1, 0);
175#ifdef OEBUILD
176                                if(node->imgtype == 1)
177                                        cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
178                                else
179                                        cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);       
180#else
181                                if(node->imgtype == 1)
182                                        cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
183                                else
184                                        cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); 
185#endif
186                                system(cmd);
187                                free(cmd),cmd = NULL;
188                                clearscreen(load);
189                        }
190
191                        drawscreen(systemupdate, 0, 0);
192                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
193                        addscreenrc(systemupdate, filelist);
194                        continue;
195                }
196                else if(rcret == getrcconfigint("rcok", NULL) || rcret == getrcconfigint("rcgreen", NULL))
197                {
198                        if(filelist->select != NULL && filelist->select->input != NULL)
199                                continue;
200                        else if(filelist->select != NULL && filelist->select->input == NULL)
201                        {
202                                tmpstr = createpath(filelistpath->text, filelist->select->text);
203                                debug(40, "tmpstr: %s", tmpstr);
204
205                                char* cmd = NULL;
206//                              if(checkrealbox("DM900") == 1 || checkrealbox("HD51") == 1)
207//                              if(checkrealbox("HD51") == 1)
208//                                      cmd = ostrcat(cmd, "/sbin/update2.sh ", 1, 0);
209//                              else
210                                        cmd = ostrcat(cmd, "/sbin/update.sh ", 1, 0);
211                                cmd = ostrcat(cmd, node->type, 1, 0);
212                                cmd = ostrcat(cmd, " ", 1, 0);
213                       
214                                char* msgtxt = NULL;
215                                writeallconfig(1);
216
217                                debug(40, "Update: update with log");
218                                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 || ostrstr(filelist->select->text, ".zip") != NULL)
219                                {
220                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
221                                                cmd = ostrcat(cmd, "full ", 1, 0);
222                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
223                                                cmd = ostrcat(cmd, "fullbackup ", 1, 0);
224                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
225                                                cmd = ostrcat(cmd, "updatenfi ", 1, 0);
226                                        else if(ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL)
227                                                cmd = ostrcat(cmd, "updateusb ", 1, 0);
228                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
229                                        {
230                                                cmd = ostrcat(cmd, device->ret, 1, 0);
231                                                cmd = ostrcat(cmd, " ", 1, 0);
232                                        }
233                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
234#ifdef OEBUILD
235                                                cmd = ostrcat(cmd, "updateusb ", 1, 0);
236#else
237                                                cmd = ostrcat(cmd, "full ", 1, 0);
238#endif
239
240                                        cmd = ostrcat(cmd, tmpstr, 1, 0);
241                                        cmd = ostrcat(cmd, node->auth, 1, 0);
242#ifdef OEBUILD
243                                        if(node->imgtype == 1)
244                                                cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
245                                        else
246                                                cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);
247
248                                        if(mode == 2 || mode == 3)
249                                        {
250                                                // send multiboot label
251                                                cmd = ostrcat(cmd, " ", 1, 0);
252                                                cmd = ostrcat(cmd, device->ret, 1, 0);
253                                        }
254#else
255                                        if(node->imgtype == 1)
256                                                cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
257                                        else
258                                                cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0);
259#endif
260#ifdef OEBUILD
261                                        if(file_exist("/media/hdd") && isdir("/media/hdd"))
262                                        {
263                                                if(!file_exist("/media/hdd/logs"))
264                                                         mkdir("/media/hdd/logs", 777);
265
266                                                if(file_exist("/media/hdd/logs"))
267                                                {
268                                                        cmd = ostrcat(cmd, " > /media/hdd/logs/update_", 1, 0);         
269                                                        cmd = ostrcat(cmd, getboxtype(), 1, 0);
270                                                        cmd = ostrcat(cmd, "_debug.log 2>&1", 1, 0);           
271                                                }
272                                        }
273                                        else if(file_exist("/var/backup"))
274                                        {
275                                                if(!file_exist("/var/backup/logs"))
276                                                         mkdir("/var/backup/logs", 777);
277                                       
278                                                if(file_exist("/var/backup/logs"))
279                                                {
280                                                        cmd = ostrcat(cmd, " > /var/backup/logs/update_", 1, 0);               
281                                                        cmd = ostrcat(cmd, getboxtype(), 1, 0);
282                                                        cmd = ostrcat(cmd, "_debug.log 2>&1", 1, 0);           
283                                                }
284                                        }
285                                        else if(file_exist("/var/swap") && !isdir("/var/swap"))
286                                        {
287                                                if(!file_exist("/var/swap/logs"))
288                                                         mkdir("/var/swap/logs", 777);
289                                       
290                                                if(file_exist("/var/swap/logs"))
291                                                {
292                                                        cmd = ostrcat(cmd, " > /var/swap/logs/update_", 1, 0);         
293                                                        cmd = ostrcat(cmd, getboxtype(), 1, 0);
294                                                        cmd = ostrcat(cmd, "_debug.log 2>&1", 1, 0);           
295                                                }
296                                        }
297#else
298                                        if(file_exist("/var/swap"))
299                                        {
300                                                if(!file_exist("/var/swap/logs"))
301                                                         mkdir("/var/swap/logs", 777);
302                                       
303                                                if(file_exist("/etc/.beta") && file_exist("/var/swap/logs"))
304                                                        cmd = ostrcat(cmd, " > /var/swap/logs/update_debug.log 2>&1", 1, 0);           
305                                        }
306                                        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 && checkbox("DM520") != 1&& checkbox("DM525") != 1)
307                                        {
308                                                if(!file_exist("/mnt/logs"))
309                                                         mkdir("/mnt/logs", 777);
310                                       
311                                                if(file_exist("/etc/.beta") && file_exist("/mnt/logs"))
312                                                        cmd = ostrcat(cmd, " > /mnt/logs/update_debug.log 2>&1", 1, 0);
313                                        }
314#endif
315                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
316                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
317                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
318                                                msgtxt = ostrcat(msgtxt, _("starting Full Update (from backup) ?"), 1, 0);
319                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
320                                                msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0);
321                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
322                                                msgtxt = ostrcat(msgtxt, _("starting Usb Update ?"), 1, 0);
323                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
324#ifdef OEBUILD 
325                                        msgtxt = ostrcat(msgtxt, _("starting Usb Update ?"), 1, 0);
326#else
327                                        msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
328#endif
329                                        else if(ostrstr(filelist->select->text, ".nfi") != NULL)
330                                                msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0);
331                                        else if(ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL)
332                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
333                                }
334
335                                clearscreen(systemupdate);
336                                resettvpic();
337                                if(msgtxt == NULL)
338                                {
339                                        textbox(_("Message"), _("Error file not supported"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
340                                        drawscreen(systemupdate, 0, 0);
341                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
342                                        addscreenrc(systemupdate, filelist);
343                                }
344
345                                if(textbox(_("Message"), msgtxt, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
346                                {
347                                        debug(40, "update started cmd: %s", cmd);
348                                        status.sec = 0; //deactivate spinner
349
350                                        ret = checkshutdown(6);
351                                        if(ret == 0)
352                                        {
353                                                system(cmd);
354                                                //should only reached if system fails
355                                                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);
356                                                debug(40, "update error cmd: %s", cmd);
357                                        }
358                                        drawscreen(systemupdate, 0, 0);
359                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
360                                        addscreenrc(systemupdate, filelist);
361                                }
362                                else
363                                {
364                                        debug(40, "update canceled cmd: %s", cmd);
365                                        drawscreen(systemupdate, 0, 0);
366                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
367                                        addscreenrc(systemupdate, filelist);
368                                }
369
370                                free(cmd); cmd = NULL;
371                                free(msgtxt); msgtxt = NULL;
372                                free(tmpstr); tmpstr = NULL;
373                                continue;
374                        }
375                }
376        }
377       
378        freeupdatelist(node);
379//      free(auth); auth = NULL;
380        delownerrc(systemupdate);
381        clearscreen(systemupdate);
382
383        delownerrc(systemupdate);
384        clearscreen(systemupdate);
385
386        status.hangtime = getconfigint("hangtime", NULL);
387        debug(40, "end");
388}
389
390
391#endif
Note: See TracBrowser for help on using the repository browser.