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.
34 #if !defined(DEFAULT_KEY_FILE)
35 #define DEFAULT_KEY_FILE "key.pem"
37 #if !defined(DEFAULT_CERT_FILE)
38 #define DEFAULT_CERT_FILE "cert.pem"
41 const char appname[] = "wgtpkg-pack";
46 "usage: %s [-f] [-o wgtfile] directory\n"
48 " -o wgtfile the output widget file\n"
49 " -f force overwriting\n"
57 static struct option options[] = {
58 { "output", required_argument, NULL, 'o' },
59 { "force", no_argument, NULL, 'f' },
60 { "help", no_argument, NULL, 'h' },
61 { "quiet", no_argument, NULL, 'q' },
62 { "verbose", no_argument, NULL, 'v' },
66 /* install the widgets of the list */
67 int main(int ac, char **av)
70 char *wgtfile, *directory, *x;
76 wgtfile = directory = NULL;
78 i = getopt_long(ac, av, "qvhfo:", options, NULL);
99 ERROR("missing argument");
102 ERROR("unrecognized option");
107 /* remaining arguments and final checks */
109 ERROR("no directory set");
112 directory = av[optind++];
114 ERROR("extra parameters found");
118 /* set default values */
119 if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
120 ERROR("asprintf failed");
125 if (stat(directory, &s)) {
126 ERROR("can't find directory %s", directory);
129 if (!S_ISDIR(s.st_mode)) {
130 ERROR("%s isn't a directory", directory);
133 if (access(wgtfile, F_OK) == 0 && force == 0) {
134 ERROR("can't overwrite existing %s", wgtfile);
138 NOTICE("-- PACKING widget %s from directory %s", wgtfile, directory);
140 /* creates an existing widget (for realpath it must exist) */
141 i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0644);
143 ERROR("can't write widget %s", wgtfile);
148 /* compute absolutes paths */
149 x = realpath(wgtfile, NULL);
151 ERROR("realpath failed for %s",wgtfile);
156 /* set and enter the workdir */
157 if (set_workdir(directory, 0))
164 return !!zwrite(wgtfile);