4 author: José Bollo <jose.bollo@iot.bzh>
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
36 #if !defined(DEFAULT_KEY_FILE)
37 #define DEFAULT_KEY_FILE "key.pem"
39 #if !defined(DEFAULT_CERT_FILE)
40 #define DEFAULT_CERT_FILE "cert.pem"
43 const char appname[] = "wgtpkg-pack";
48 "usage: %s [-f] [-o wgtfile] directory\n"
50 " -o wgtfile the output widget file\n"
51 " -f force overwriting\n"
59 static struct option options[] = {
60 { "output", required_argument, NULL, 'o' },
61 { "force", no_argument, NULL, 'f' },
62 { "help", no_argument, NULL, 'h' },
63 { "quiet", no_argument, NULL, 'q' },
64 { "verbose", no_argument, NULL, 'v' },
68 /* install the widgets of the list */
69 int main(int ac, char **av)
72 char *wgtfile, *directory, *x;
78 wgtfile = directory = NULL;
80 i = getopt_long(ac, av, "qvhfo:", options, NULL);
101 ERROR("missing argument");
104 ERROR("unrecognized option");
109 /* remaining arguments and final checks */
111 ERROR("no directory set");
114 directory = av[optind++];
116 ERROR("extra parameters found");
120 /* set default values */
121 if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
122 ERROR("asprintf failed");
127 if (stat(directory, &s)) {
128 ERROR("can't find directory %s", directory);
131 if (!S_ISDIR(s.st_mode)) {
132 ERROR("%s isn't a directory", directory);
135 if (access(wgtfile, F_OK) == 0 && force == 0) {
136 ERROR("can't overwrite existing %s", wgtfile);
140 NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory);
142 /* creates an existing widget (for realpath it must exist) */
143 i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
145 ERROR("can't write widget %s", wgtfile);
150 /* compute absolutes paths */
151 x = realpath(wgtfile, NULL);
153 ERROR("realpath failed for %s",wgtfile);
158 /* set and enter the workdir */
159 if (set_workdir(directory, 0))
166 return !!zwrite(wgtfile);