1 /* args.c - parse command-line args
5 Copyright 2001 University of Southern California
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
27 #include "sprintf_alloc.h"
28 #include "libbb/libbb.h"
30 static void print_version(void);
34 ARGS_OPT_FORCE_DEFAULTS = 129,
35 ARGS_OPT_FORCE_MAINTAINER,
36 ARGS_OPT_FORCE_DEPENDS,
37 ARGS_OPT_FORCE_OVERWRITE,
38 ARGS_OPT_FORCE_DOWNGRADE,
39 ARGS_OPT_FORCE_REINSTALL,
40 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
41 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
45 ARGS_OPT_MULTIPLE_PROVIDERS,
50 void args_init(args_t *args)
52 memset(args, 0, sizeof(args_t));
54 args->dest = ARGS_DEFAULT_DEST;
56 sprintf_alloc(&args->conf_file, "%s/%s", OPKGETCDIR,
57 ARGS_DEFAULT_CONF_FILE_NAME);
59 args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
60 args->force_maintainer = ARGS_DEFAULT_FORCE_MAINTAINER;
61 args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
62 args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
63 args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
64 args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
65 args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
66 args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
67 args->autoremove = ARGS_DEFAULT_AUTOREMOVE;
68 args->noaction = ARGS_DEFAULT_NOACTION;
69 args->nodeps = ARGS_DEFAULT_NODEPS;
70 args->verbosity = ARGS_DEFAULT_VERBOSITY;
71 args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
72 args->offline_root_path = ARGS_DEFAULT_OFFLINE_ROOT_PATH;
73 args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
74 args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
75 args->multiple_providers = 0;
76 args->nocheckfordirorfile = 0;
77 args->noreadfeedsfile = 0;
80 void args_deinit(args_t *args)
82 free (args->offline_root);
83 free (args->offline_root_path);
84 free (args->offline_root_pre_script_cmd);
85 free (args->offline_root_post_script_cmd);
90 free(args->conf_file);
91 args->conf_file = NULL;
94 int args_parse(args_t *args, int argc, char *argv[])
99 static struct option long_options[] = {
100 {"query-all", 0, 0, 'A'},
101 {"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE},
102 {"cache", 1, 0, ARGS_OPT_CACHE},
103 {"conf-file", 1, 0, 'f'},
106 {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
107 {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
108 {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
109 {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
110 {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
111 {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
112 {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
113 {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
114 {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
115 {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
116 {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
117 {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
118 {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
119 {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
121 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
122 {"force-removal-of-dependent-packages", 0, 0,
123 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
124 {"force_removal_of_dependent_packages", 0, 0,
125 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
126 {"force-removal-of-essential-packages", 0, 0,
127 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
128 {"force_removal_of_essential_packages", 0, 0,
129 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
130 {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
131 {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
132 {"noaction", 0, 0, ARGS_OPT_NOACTION},
133 {"nodeps", 0, 0, ARGS_OPT_NODEPS},
134 {"offline", 1, 0, 'o'},
135 {"offline-root", 1, 0, 'o'},
136 {"offline-path", 1, 0, 'p'},
137 {"offline-root-path", 1, 0, 'p'},
138 {"test", 0, 0, ARGS_OPT_NOACTION},
139 {"tmp-dir", 1, 0, 't'},
140 {"tmp_dir", 1, 0, 't'},
141 {"verbosity", 2, 0, 'V'},
142 {"version", 0, 0, 'v'},
147 c = getopt_long_only(argc, argv, "Ad:f:no:p:t:vV:", long_options, &option_index);
156 args->dest = xstrdup(optarg);
159 free(args->conf_file);
160 args->conf_file = xstrdup(optarg);
163 args->offline_root = xstrdup(optarg);
166 args->offline_root_path = xstrdup(optarg);
169 args->tmp_dir = xstrdup(optarg);
175 args->verbosity = atoi(optarg);
177 case ARGS_OPT_AUTOREMOVE:
178 args->autoremove = 1;
182 args->cache = xstrdup(optarg);
184 case ARGS_OPT_FORCE_DEFAULTS:
185 args->force_defaults = 1;
187 case ARGS_OPT_FORCE_MAINTAINER:
188 args->force_maintainer = 1;
190 case ARGS_OPT_FORCE_DEPENDS:
191 args->force_depends = 1;
193 case ARGS_OPT_FORCE_OVERWRITE:
194 args->force_overwrite = 1;
196 case ARGS_OPT_FORCE_DOWNGRADE:
197 args->force_downgrade = 1;
199 case ARGS_OPT_FORCE_REINSTALL:
200 args->force_reinstall = 1;
202 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
203 args->force_removal_of_essential_packages = 1;
205 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
206 args->force_removal_of_dependent_packages = 1;
208 case ARGS_OPT_FORCE_SPACE:
209 args->force_space = 1;
211 case ARGS_OPT_MULTIPLE_PROVIDERS:
212 args->multiple_providers = 1;
214 case ARGS_OPT_NODEPS:
217 case ARGS_OPT_NOACTION:
227 printf("Confusion: getopt_long returned %d\n", c);
238 void args_usage(char *complaint)
241 printf("opkg: %s\n", complaint);
244 printf("usage: opkg [options...] sub-command [arguments...]\n");
245 printf("where sub-command is one of:\n");
247 printf("\nPackage Manipulation:\n");
248 printf("\tupdate Update list of available packages\n");
249 printf("\tupgrade Upgrade installed packages\n");
250 printf("\tinstall <pkgs> Install package(s)\n");
251 printf("\tconfigure <pkgs> Configure unpacked package(s)\n");
252 printf("\tremove <pkgs|regexp> Remove package(s)\n");
253 printf("\tflag <flag> <pkgs> Flag package(s)\n");
254 printf("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n");
256 printf("\nInformational Commands:\n");
257 printf("\tlist List available packages\n");
258 printf("\tlist-installed List installed packages\n");
259 printf("\tlist-upgradable List installed and upgradable packages\n");
260 printf("\tfiles <pkg> List files belonging to <pkg>\n");
261 printf("\tsearch <file|regexp> List package providing <file>\n");
262 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
263 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
264 printf("\tdownload <pkg> Download <pkg> to current directory\n");
265 printf("\tcompare-versions <v1> <op> <v2>\n");
266 printf("\t compare versions using <= < > >= = << >>\n");
267 printf("\tprint-architecture List installable package architectures\n");
268 printf("\twhatdepends [-A] [pkgname|pat]+\n");
269 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
270 printf("\twhatprovides [-A] [pkgname|pat]+\n");
271 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
272 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
274 printf("\nOptions:\n");
275 printf("\t-A Query all packages not just those installed\n");
276 printf("\t-V <level> Set verbosity level to <level>.\n");
277 printf("\t--verbosity <level> Verbosity levels:\n");
278 printf("\t 0 errors only\n");
279 printf("\t 1 normal messages (default)\n");
280 printf("\t 2 informative messages\n");
281 printf("\t 3 debug\n");
282 printf("\t 4 debug level 2\n");
283 printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
284 printf("\t--conf <conf_file> Default configuration file location\n");
285 printf(" is %s/%s\n", ARGS_DEFAULT_CONF_FILE_DIR, ARGS_DEFAULT_CONF_FILE_NAME);
286 printf("\t--cache <directory> Use a package cache\n");
287 printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
288 printf("\t--dest <dest_name> package installation, removal, upgrading.\n");
289 printf(" <dest_name> should be a defined dest name from\n");
290 printf(" the configuration file, (but can also be a\n");
291 printf(" directory name in a pinch).\n");
292 printf("\t-o <dir> Use <dir> as the root directory for\n");
293 printf("\t--offline-root <dir> offline installation of packages.\n");
294 printf("\t--offline-path <path> $PATH for postinsts scripts in offline mode\n");
296 printf("\nForce Options:\n");
297 printf("\t--force-depends Install/remove despite failed dependences\n");
298 printf("\t--force-defaults Use default options for questions asked by opkg\n");
299 printf("\t--force-reinstall Reinstall package(s)\n");
300 printf("\t--force-overwrite Overwrite files from other package(s)\n");
301 printf("\t--force-downgrade Allow opkg to downgrade packages\n");
302 printf("\t--force-space Disable free space checks\n");
303 printf("\t--noaction No action -- test only\n");
304 printf("\t--nodeps Do not follow dependences\n");
305 printf("\t--force-removal-of-dependent-packages\n");
306 printf("\t Remove package and all dependencies\n");
307 printf("\t--autoremove Remove packages that were installed\n");
308 printf("\t automatically to satisfy dependencies\n");
309 printf("\t-t Specify tmp-dir.\n");
310 printf("\t--tmp-dir Specify tmp-dir.\n");
314 printf(" regexp could be something like 'pkgname*' '*file*' or similar\n");
315 printf(" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
316 /* -force-removal-of-essential-packages Let opkg remove essential packages.
317 Using this option is almost guaranteed to break your system, hence this option
318 is not even advertised in the usage statement. */
322 static void print_version(void)
324 printf("opkg version %s\n", VERSION);