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"
55 static struct option options[] = {
56 { "output", required_argument, NULL, 'o' },
57 { "force", no_argument, NULL, 'f' },
58 { "help", no_argument, NULL, 'h' },
62 /* install the widgets of the list */
63 int main(int ac, char **av)
66 char *wgtfile, *directory, *x;
69 openlog(appname, LOG_PERROR, LOG_USER);
72 wgtfile = directory = NULL;
74 i = getopt_long(ac, av, "hfo:", options, NULL);
88 syslog(LOG_ERR, "missing argument");
91 syslog(LOG_ERR, "unrecognized option");
96 /* remaining arguments and final checks */
98 syslog(LOG_ERR, "no directory set");
101 directory = av[optind++];
103 syslog(LOG_ERR, "extra parameters found");
107 /* set default values */
108 if (wgtfile == NULL && 0 > asprintf(&wgtfile, "%s.wgt", directory)) {
109 syslog(LOG_ERR, "asprintf failed");
114 if (stat(directory, &s)) {
115 syslog(LOG_ERR, "can't find directory %s", directory);
118 if (!S_ISDIR(s.st_mode)) {
119 syslog(LOG_ERR, "%s isn't a directory", directory);
122 if (access(wgtfile, F_OK) == 0 && force == 0) {
123 syslog(LOG_ERR, "can't overwrite existing %s", wgtfile);
127 printf("\n\nPACKING widget %s from directory %s\n", wgtfile, directory);
129 /* creates an existing widget (for realpath it must exist) */
130 i = open(wgtfile, O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666);
132 syslog(LOG_ERR, "can't write widget %s", wgtfile);
137 /* compute absolutes paths */
138 x = realpath(wgtfile, NULL);
140 syslog(LOG_ERR, "realpath failed for %s",wgtfile);
145 /* set and enter the workdir */
146 if (set_workdir(directory, 0) || enter_workdir(0))
153 return !!zwrite(wgtfile);