source: titan/titan/system_update.h @ 23920

Last change on this file since 23920 was 23920, checked in by obi, 11 years ago

activate restor backup full image

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