source: titan/titan/system_update.h @ 41495

Last change on this file since 41495 was 41495, checked in by obi, 6 years ago

dm900 switch to update.sh step 1

File size: 9.7 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", 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                                if(checkrealbox("HD51") == 1)
187                                        cmd = ostrcat(cmd, "/sbin/update2.sh ", 1, 0);
188                                else
189                                        cmd = ostrcat(cmd, "/sbin/update.sh ", 1, 0);
190                                cmd = ostrcat(cmd, node->type, 1, 0);
191                                cmd = ostrcat(cmd, " ", 1, 0);
192                       
193                                char* msgtxt = NULL;
194                                writeallconfig(1);
195
196                                debug(40, "Update: update with log");
197                                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)
198                                {
199                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
200                                                cmd = ostrcat(cmd, "full ", 1, 0);
201                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
202                                                cmd = ostrcat(cmd, "fullbackup ", 1, 0);
203                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
204                                                cmd = ostrcat(cmd, "updatenfi ", 1, 0);
205                                        else if(ostrstr(filelist->select->text, "_UPDATEUSB_") != NULL)
206                                                cmd = ostrcat(cmd, "updateusb ", 1, 0);
207                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
208                                        {
209                                                cmd = ostrcat(cmd, device->ret, 1, 0);
210                                                cmd = ostrcat(cmd, " ", 1, 0);
211                                        }
212                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
213                                                cmd = ostrcat(cmd, "full ", 1, 0);
214                                       
215                                        cmd = ostrcat(cmd, tmpstr, 1, 0);
216                                        cmd = ostrcat(cmd, node->auth, 1, 0);
217                                        if(node->imgtype == 1)
218                                                cmd = ostrcat(cmd, " dev beta.dyndns.tv", 1, 0);
219                                        else
220                                                cmd = ostrcat(cmd, " release atemio.dyndns.tv", 1, 0);
221
222                                        if(file_exist("/var/swap"))
223                                        {
224                                                if(!file_exist("/var/swap/logs"))
225                                                         mkdir("/var/swap/logs", 777);
226                                       
227                                                if(file_exist("/etc/.beta") && file_exist("/var/swap/logs"))
228                                                        cmd = ostrcat(cmd, " > /var/swap/logs/update_debug.log 2>&1", 1, 0);           
229                                        }
230                                        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)
231                                        {
232                                                if(!file_exist("/mnt/logs"))
233                                                         mkdir("/mnt/logs", 777);
234                                       
235                                                if(file_exist("/etc/.beta") && file_exist("/mnt/logs"))
236                                                        cmd = ostrcat(cmd, " > /mnt/logs/update_debug.log 2>&1", 1, 0);
237                                        }
238
239                                        if(ostrstr(filelist->select->text, "_FULL_") != NULL)
240                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
241                                        else if(ostrstr(filelist->select->text, "_FULLBACKUP.") != NULL)
242                                                msgtxt = ostrcat(msgtxt, _("starting Full Update (from backup) ?"), 1, 0);
243                                        else if(ostrstr(filelist->select->text, "_UPDATENFI_") != NULL)
244                                                msgtxt = ostrcat(msgtxt, _("starting Nfi Update ?"), 1, 0);
245                                        else if(ostrstr(filelist->select->text, ".tar.gz") != NULL)
246                                                msgtxt = ostrcat(msgtxt, _("starting Usb Update ?"), 1, 0);
247                                        else if(ostrstr(filelist->select->text, ".zip") != NULL)
248                                                msgtxt = ostrcat(msgtxt, _("starting Full Update ?"), 1, 0);
249                                }
250
251                                clearscreen(systemupdate);
252                                resettvpic();
253                                if(msgtxt == NULL)
254                                {
255                                        textbox(_("Message"), _("Error file not supported"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
256                                        drawscreen(systemupdate, 0, 0);
257                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
258                                        addscreenrc(systemupdate, filelist);
259                                }
260
261                                if(textbox(_("Message"), msgtxt, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 800, 200, 0, 0) == 1)
262                                {
263                                        debug(40, "update started cmd: %s", cmd);
264                                        status.sec = 0; //deactivate spinner
265
266                                        ret = checkshutdown(6);
267                                        if(ret == 0)
268                                        {
269                                                system(cmd);
270                                                //should only reached if system fails
271                                                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);
272                                                debug(40, "update error cmd: %s", cmd);
273                                        }
274                                        drawscreen(systemupdate, 0, 0);
275                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
276                                        addscreenrc(systemupdate, filelist);
277                                }
278                                else
279                                {
280                                        debug(40, "update canceled cmd: %s", cmd);
281                                        drawscreen(systemupdate, 0, 0);
282                                        getfilelist(systemupdate, filelistpath, filelist, node->filepath, node->filemask, 0, NULL);
283                                        addscreenrc(systemupdate, filelist);
284                                }
285
286                                free(cmd); cmd = NULL;
287                                free(msgtxt); msgtxt = NULL;
288                                free(tmpstr); tmpstr = NULL;
289                                continue;
290                        }
291                }
292        }
293       
294        freeupdatelist(node);
295//      free(auth); auth = NULL;
296        delownerrc(systemupdate);
297        clearscreen(systemupdate);
298
299        delownerrc(systemupdate);
300        clearscreen(systemupdate);
301
302        status.hangtime = getconfigint("hangtime", NULL);
303        debug(40, "end");
304}
305
306
307#endif
Note: See TracBrowser for help on using the repository browser.