doc: add new document quick-tutorial
[src/app-framework-main.git] / src / wgtpkg-installer.c
1 /*
2  Copyright 2015 IoT.bzh
3
4  author: José Bollo <jose.bollo@iot.bzh>
5
6  Licensed under the Apache License, Version 2.0 (the "License");
7  you may not use this file except in compliance with the License.
8  You may obtain a copy of the License at
9
10      http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  See the License for the specific language governing permissions and
16  limitations under the License.
17 */
18
19 #define _GNU_SOURCE
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <dirent.h>
25 #include <unistd.h>
26 #include <limits.h>
27 #include <errno.h>
28 #include <getopt.h>
29
30 #include <libxml/tree.h>
31
32 #include "verbose.h"
33 #include "wgtpkg-permissions.h"
34 #include "wgtpkg-xmlsec.h"
35 #include "wgt-info.h"
36 #include "wgtpkg-install.h"
37
38 static const char appname[] = "wgtpkg-installer";
39 static const char *root;
40 static int force;
41
42 static void usage()
43 {
44         printf(
45                 "usage: %s [-f] [-q] [-v] [-p list] rootdir wgtfile...\n"
46                 "\n"
47                 "   rootdir       the root directory for installing\n"
48                 "   -p list       a list of comma separated permissions to allow\n"
49                 "   -f            force overwriting\n"
50                 "   -q            quiet\n"
51                 "   -v            verbose\n"
52                 "\n",
53                 appname
54         );
55 }
56
57 static struct option options[] = {
58         { "permissions", required_argument, NULL, 'p' },
59         { "force",       no_argument,       NULL, 'f' },
60         { "help",        no_argument,       NULL, 'h' },
61         { "quiet",       no_argument,       NULL, 'q' },
62         { "verbose",     no_argument,       NULL, 'v' },
63         { NULL, 0, NULL, 0 }
64 };
65
66 /* install the widgets of the list */
67 int main(int ac, char **av)
68 {
69         int i;
70         struct wgt_info *ifo;
71
72         LOGAUTH(appname);
73
74         xmlsec_init();
75
76         force = 0;
77         for (;;) {
78                 i = getopt_long(ac, av, "hfqvp:", options, NULL);
79                 if (i < 0)
80                         break;
81                 switch (i) {
82                 case 'f':
83                         force = 1;
84                         break;
85                 case 'h':
86                         usage();
87                         return 0;
88                 case 'q':
89                         if (verbosity)
90                                 verbosity--;
91                         break;
92                 case 'v':
93                         verbosity++;
94                         break;
95                 case 'p':
96                         grant_permission_list(optarg);
97                         break;
98                 case ':':
99                         ERROR("missing argument value");
100                         return 1;
101                 default:
102                         ERROR("unrecognized option");
103                         return 1;
104                 }
105         }
106
107         ac -= optind;
108         if (ac < 2) {
109                 ERROR("arguments are missing");
110                 return 1;
111         }
112
113         /* install widgets */
114         av += optind;
115         root = *av++;
116         for ( ; *av ; av++) {
117                 ifo = install_widget(*av, root, force);
118                 if (ifo)
119                         wgt_info_unref(ifo);
120         }
121
122         return 0;
123 }
124