source: titan/titan/system_update.h @ 43254

Last change on this file since 43254 was 43254, checked in by obi, 5 years ago

fix

File size: 10.4 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                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-svn", 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#ifdef OEBUILD
120                                if(node->imgtype == 1)
121                                        cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
122                                else
123                                        cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);       
124#else
125                                if(node->imgtype == 1)
126                                        cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
127                                else
128                                        cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); 
129#endif
130                                system(cmd);
131                                free(cmd),cmd = NULL;
132                                clearscreen(load);
133                        }
134
135                        drawscreen(systemupdate, 0, 0);
136                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
137                        addscreenrc(systemupdate, filelist);
138                        continue;
139                }
140                else if(rcret == getrcconfigint("rcblue", NULL))
141                {
142                        if(mode == 0 || mode == 2)
143                        {
144                                if(node->imgtype == 0)
145                                {
146                                        int pinret = 0;
147                                       
148                                        if(!file_exist("/etc/.beta"))
149                                                pinret = screenpincheck(3, NULL);
150                                       
151                                        if(pinret == 0)
152                                        {
153                                                node->imgtype = 1;
154                                                changetext(b6, _("stable"));
155                                        }
156                                }
157                                else
158                                {
159                                        node->imgtype = 0;
160                                        changetext(b6, _("unstable"));
161                                }
162                       
163                                char* cmd = NULL;
164
165                                drawscreen(load, 0, 0);
166                                cmd = ostrcat(cmd, "/sbin/update.sh getfilelist", 1, 0);
167                                cmd = ostrcat(cmd, node->auth, 1, 0);
168#ifdef OEBUILD
169                                if(node->imgtype == 1)
170                                        cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
171                                else
172                                        cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);       
173#else
174                                if(node->imgtype == 1)
175                                        cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
176                                else
177                                        cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0); 
178#endif
179                                system(cmd);
180                                free(cmd),cmd = NULL;
181                                clearscreen(load);
182                        }
183
184                        drawscreen(systemupdate, 0, 0);
185                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
186                        addscreenrc(systemupdate, filelist);
187                        continue;
188                }
189                else if(rcret == getrcconfigint("rcok", NULL) || rcret == getrcconfigint("rcgreen", NULL))
190                {
191                        if(filelist->select != NULL && filelist->select->input != NULL)
192                                continue;
193                        else if(filelist->select != NULL && filelist->select->input == NULL)
194                        {
195                                tmpstr = createpath(filelistpath->text, filelist->select->text);
196                                debug(40, "tmpstr: %s", tmpstr);
197
198                                char* cmd = NULL;
199//                              if(checkrealbox("DM900") == 1 || checkrealbox("HD51") == 1)
200//                              if(checkrealbox("HD51") == 1)
201//                                      cmd = ostrcat(cmd, "/sbin/update2.sh ", 1, 0);
202//                              else
203                                        cmd = ostrcat(cmd, "/sbin/update.sh ", 1, 0);
204                                cmd = ostrcat(cmd, node->type, 1, 0);
205                                cmd = ostrcat(cmd, " ", 1, 0);
206                       
207                                char* msgtxt = NULL;
208                                writeallconfig(1);
209
210                                debug(40, "Update: update with log");
211                                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)
212                                {
213                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
214                                                cmd = ostrcat(cmd, "full ", 1, 0);
215                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
216                                                cmd = ostrcat(cmd, "fullbackup ", 1, 0);
217                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
218                                                cmd = ostrcat(cmd, "updatenfi ", 1, 0);
219                                        else if(ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL)
220                                                cmd = ostrcat(cmd, "updateusb ", 1, 0);
221                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
222                                        {
223                                                cmd = ostrcat(cmd, device->ret, 1, 0);
224                                                cmd = ostrcat(cmd, " ", 1, 0);
225                                        }
226                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
227                                                cmd = ostrcat(cmd, "full ", 1, 0);
228                                       
229                                        cmd = ostrcat(cmd, tmpstr, 1, 0);
230                                        cmd = ostrcat(cmd, node->auth, 1, 0);
231#ifdef OEBUILD
232                                        if(node->imgtype == 1)
233                                                cmd = ostrcat(cmd, " dev titannit.dyndns.tv", 1, 0);
234                                        else
235                                                cmd = ostrcat(cmd, " release titannit.dyndns.tv", 1, 0);
236#else
237                                        if(node->imgtype == 1)
238                                                cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
239                                        else
240                                                cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0);
241#endif
242                                        if(file_exist("/var/swap"))
243                                        {
244                                                if(!file_exist("/var/swap/logs"))
245                                                         mkdir("/var/swap/logs", 777);
246                                       
247                                                if(file_exist("/etc/.beta") && file_exist("/var/swap/logs"))
248                                                        cmd = ostrcat(cmd, " > /var/swap/logs/update_debug.log 2>&1", 1, 0);           
249                                        }
250                                        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)
251                                        {
252                                                if(!file_exist("/mnt/logs"))
253                                                         mkdir("/mnt/logs", 777);
254                                       
255                                                if(file_exist("/etc/.beta") && file_exist("/mnt/logs"))
256                                                        cmd = ostrcat(cmd, " > /mnt/logs/update_debug.log 2>&1", 1, 0);
257                                        }
258
259                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
260                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
261                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
262                                                msgtxt = ostrcat(msgtxt, _("starting Full Update (from backup) ?"), 1, 0);
263                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
264                                                msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0);
265                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
266                                                msgtxt = ostrcat(msgtxt, _("starting Usb Update ?"), 1, 0);
267                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
268                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
269                                        else if(ostrstr(filelist->select->text, ".nfi") != NULL)
270                                                msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0);
271
272                                }
273
274                                clearscreen(systemupdate);
275                                resettvpic();
276                                if(msgtxt == NULL)
277                                {
278                                        textbox(_("Message"), _("Error file not supported"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
279                                        drawscreen(systemupdate, 0, 0);
280                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
281                                        addscreenrc(systemupdate, filelist);
282                                }
283
284                                if(textbox(_("Message"), msgtxt, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
285                                {
286                                        debug(40, "update started cmd: %s", cmd);
287                                        status.sec = 0; //deactivate spinner
288
289                                        ret = checkshutdown(6);
290                                        if(ret == 0)
291                                        {
292                                                system(cmd);
293                                                //should only reached if system fails
294                                                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);
295                                                debug(40, "update error cmd: %s", cmd);
296                                        }
297                                        drawscreen(systemupdate, 0, 0);
298                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
299                                        addscreenrc(systemupdate, filelist);
300                                }
301                                else
302                                {
303                                        debug(40, "update canceled cmd: %s", cmd);
304                                        drawscreen(systemupdate, 0, 0);
305                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
306                                        addscreenrc(systemupdate, filelist);
307                                }
308
309                                free(cmd); cmd = NULL;
310                                free(msgtxt); msgtxt = NULL;
311                                free(tmpstr); tmpstr = NULL;
312                                continue;
313                        }
314                }
315        }
316       
317        freeupdatelist(node);
318//      free(auth); auth = NULL;
319        delownerrc(systemupdate);
320        clearscreen(systemupdate);
321
322        delownerrc(systemupdate);
323        clearscreen(systemupdate);
324
325        status.hangtime = getconfigint("hangtime", NULL);
326        debug(40, "end");
327}
328
329
330#endif
Note: See TracBrowser for help on using the repository browser.