4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
35 #if !defined(DEFAULT_KEY_FILE)
36 #define DEFAULT_KEY_FILE "key.pem"
38 #if !defined(DEFAULT_CERT_FILE)
39 #define DEFAULT_CERT_FILE "cert.pem"
42 const char appname[] = "wgtpkg-pack";
47 "usage: %s [-f] [-o wgtfile] directory\n"
49 " -o wgtfile the output widget file\n"
50 " -f force overwriting\n"
58 static struct option options[] = {
59 { "output", required_argument, NULL, 'o' },
60 { "force", no_argument, NULL, 'f' },
61 { "help", no_argument, NULL, 'h' },
62 { "quiet", no_argument, NULL, 'q' },
63 { "verbose", no_argument, NULL, 'v' },
67 /* install the widgets of the list */
68 int main(int ac, char **av)
71 char *wgtfile, *directory, *x;
74 openlog(appname, LOG_PERROR, LOG_USER);
77 wgtfile = directory = NULL;
79 i = getopt_long(ac, av, "qvhfo:", options, NULL);
100 ERROR("missing argument");
103 ERROR("unrecognized option");
108 /* remaining arguments and final checks */
110 ERROR("no directory set");
113 directory = av[optind++];
115 ERROR("extra parameters found");
119 /* set default values */
120 if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
121 ERROR("asprintf failed");
126 if (stat(directory, &s)) {
127 ERROR("can't find directory %s", directory);
130 if (!S_ISDIR(s.st_mode)) {
131 ERROR("%s isn't a directory", directory);
134 if (access(wgtfile, F_OK) == 0 && force == 0) {
135 ERROR("can't overwrite existing %s", wgtfile);
139 NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory);
141 /* creates an existing widget (for realpath it must exist) */
142 i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
144 ERROR("can't write widget %s", wgtfile);
149 /* compute absolutes paths */
150 x = realpath(wgtfile, NULL);
152 ERROR("realpath failed for %s",wgtfile);
157 /* set and enter the workdir */
158 if (set_workdir(directory, 0))
165 return !!zwrite(wgtfile);