source: titan/titan/system_update.h @ 25317

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

fix autofs umounting

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