]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-sysinfo.c
discover/paths: Fix wget command with https and !DEBUG
[petitboot] / ui / ncurses / nc-sysinfo.c
1 /*
2  *  Copyright (C) 2013 IBM Corporation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <string.h>
23
24 #include <talloc/talloc.h>
25 #include <types/types.h>
26 #include <log/log.h>
27 #include <util/util.h>
28
29 #include "nc-cui.h"
30 #include "nc-textscreen.h"
31 #include "nc-sysinfo.h"
32
33 struct sysinfo_screen {
34         struct text_screen text_scr;
35 };
36
37 extern const char *sysinfo_help_text;
38
39 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
40 {
41         return text_screen_scr(&screen->text_scr);
42 }
43
44 static void if_info_mac_str(struct interface_info *info,
45                 char *buf, unsigned int buflen)
46 {
47         return mac_str(info->hwaddr, info->hwaddr_size, buf, buflen);
48 }
49
50 static void sysinfo_screen_populate(struct sysinfo_screen *screen,
51                 const struct system_info *sysinfo)
52 {
53         unsigned int i;
54
55         text_screen_clear(&screen->text_scr);
56
57 #define line(...) text_screen_append_line(&screen->text_scr, __VA_ARGS__)
58         if (!sysinfo) {
59                 line("Waiting for system information...");
60                 return;
61         }
62
63         line("%-12s %s", "System type:", sysinfo->type ?: "");
64         line("%-12s %s", "System id:",   sysinfo->identifier ?: "");
65
66         if (sysinfo->n_blockdevs) {
67                 line(NULL);
68                 line("Storage devices");
69         }
70
71         for (i = 0; i < sysinfo->n_blockdevs; i++) {
72                 struct blockdev_info *info = sysinfo->blockdevs[i];
73
74                 line("%s:", info->name);
75                 line(" UUID:       %s", info->uuid);
76                 line(" mounted at: %s", info->mountpoint);
77                 line(NULL);
78         }
79
80         if (sysinfo->n_interfaces) {
81                 line(NULL);
82                 line("Network interfaces");
83         }
84
85         for (i = 0; i < sysinfo->n_interfaces; i++) {
86                 struct interface_info *info = sysinfo->interfaces[i];
87                 char macbuf[32];
88
89                 if_info_mac_str(info, macbuf, sizeof(macbuf));
90
91                 line("%s:", info->name);
92                 line(" MAC:  %s", macbuf);
93                 line(" link: %s", info->link ? "up" : "down");
94                 line(NULL);
95         }
96
97 #undef line
98 }
99
100 void sysinfo_screen_update(struct sysinfo_screen *screen,
101                 const struct system_info *sysinfo)
102 {
103         sysinfo_screen_populate(screen, sysinfo);
104         text_screen_draw(&screen->text_scr);
105 }
106
107 struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
108                 const struct system_info *sysinfo,
109                 void (*on_exit)(struct cui *))
110 {
111         struct sysinfo_screen *screen;
112
113         screen = talloc_zero(cui, struct sysinfo_screen);
114         text_screen_init(&screen->text_scr, cui,
115                         "Petitboot System Information", on_exit);
116         text_screen_set_help(&screen->text_scr,
117                         "System Information", sysinfo_help_text);
118
119         sysinfo_screen_update(screen, sysinfo);
120
121         return screen;
122 }