2 Copyright (C) 2015-2020 IoT.bzh
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.
31 #include "wgtpkg-files.h"
32 #include "wgtpkg-workdir.h"
33 #include "wgtpkg-zip.h"
34 #include "wgtpkg-digsig.h"
36 const char appname[] = "wgtpkg-pack";
42 " %s version="AFM_VERSION"\n"
44 " Copyright (C) 2015-2020 \"IoT.bzh\"\n"
45 " AFB comes with ABSOLUTELY NO WARRANTY.\n"
55 "usage: %s [-f] [-o wgtfile] directory\n"
57 " -o wgtfile the output widget file\n"
58 " -f force overwriting\n"
69 static struct option options[] = {
70 { "output", required_argument, NULL, 'o' },
71 { "force", no_argument, NULL, 'f' },
72 { "help", no_argument, NULL, 'h' },
73 { "no-auto-sign",no_argument, NULL, 'N' },
74 { "quiet", no_argument, NULL, 'q' },
75 { "auto-sign", no_argument, NULL, 'S' },
76 { "verbose", no_argument, NULL, 'v' },
77 { "version", no_argument, NULL, 'V' },
81 /* install the widgets of the list */
82 int main(int ac, char **av)
84 int i, force, autosign;
85 char *wgtfile, *directory, *x;
92 wgtfile = directory = NULL;
94 i = getopt_long(ac, av, "qvVhfo:", options, NULL);
124 ERROR("missing argument");
127 ERROR("unrecognized option");
132 /* remaining arguments and final checks */
134 ERROR("no directory set");
137 directory = av[optind++];
139 ERROR("extra parameters found");
143 /* set default values */
144 if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
145 ERROR("asprintf failed");
150 if (stat(directory, &s)) {
151 ERROR("can't find directory %s", directory);
154 if (!S_ISDIR(s.st_mode)) {
155 ERROR("%s isn't a directory", directory);
158 if (access(wgtfile, F_OK) == 0 && force == 0) {
159 ERROR("can't overwrite existing %s", wgtfile);
163 NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory);
165 /* creates an existing widget (for realpath it must exist) */
166 i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
168 ERROR("can't write widget %s", wgtfile);
173 /* compute absolutes paths */
174 x = realpath(wgtfile, NULL);
176 ERROR("realpath failed for %s", wgtfile);
181 /* set and enter the workdir */
182 if (chdir(directory)) {
183 ERROR("failed to enter directory %s", directory);
186 if (set_workdir(".", 0))
192 if (autosign && create_auto_digsig() < 0)
195 return !!zwrite(wgtfile);