source: titan/titan/system_update.h @ 34379

Last change on this file since 34379 was 30340, checked in by obi, 10 years ago

webif add tpk install

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