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"
29 static void print_version(void);
33 ARGS_OPT_FORCE_DEFAULTS = 129,
34 ARGS_OPT_FORCE_DEPENDS,
35 ARGS_OPT_FORCE_OVERWRITE,
36 ARGS_OPT_FORCE_DOWNGRADE,
37 ARGS_OPT_FORCE_REINSTALL,
38 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
39 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
44 ARGS_OPT_MULTIPLE_PROVIDERS,
48 int args_init(args_t *args)
52 memset(args, 0, sizeof(args_t));
54 args->dest = ARGS_DEFAULT_DEST;
56 conf_file_dir = getenv("OPKG_CONF_DIR");
57 if (conf_file_dir == NULL || conf_file_dir[0] == '\0') {
58 conf_file_dir = ARGS_DEFAULT_CONF_FILE_DIR;
60 sprintf_alloc(&args->conf_file, "%s/%s", conf_file_dir,
61 ARGS_DEFAULT_CONF_FILE_NAME);
63 args->force_defaults = ARGS_DEFAULT_FORCE_DEFAULTS;
64 args->force_depends = ARGS_DEFAULT_FORCE_DEPENDS;
65 args->force_overwrite = ARGS_DEFAULT_FORCE_OVERWRITE;
66 args->force_downgrade = ARGS_DEFAULT_FORCE_DOWNGRADE;
67 args->force_reinstall = ARGS_DEFAULT_FORCE_REINSTALL;
68 args->force_removal_of_dependent_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES;
69 args->force_removal_of_essential_packages = ARGS_DEFAULT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES;
70 args->autoremove = ARGS_DEFAULT_AUTOREMOVE;
71 args->noaction = ARGS_DEFAULT_NOACTION;
72 args->nodeps = ARGS_DEFAULT_NODEPS;
73 args->verbosity = ARGS_DEFAULT_VERBOSITY;
74 args->offline_root = ARGS_DEFAULT_OFFLINE_ROOT;
75 args->offline_root_pre_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_PRE_SCRIPT_CMD;
76 args->offline_root_post_script_cmd = ARGS_DEFAULT_OFFLINE_ROOT_POST_SCRIPT_CMD;
77 args->multiple_providers = 0;
78 args->nocheckfordirorfile = 0;
79 args->noreadfeedsfile = 0;
84 void args_deinit(args_t *args)
86 free (args->offline_root);
87 free (args->offline_root_pre_script_cmd);
88 free (args->offline_root_post_script_cmd);
92 free(args->conf_file);
93 args->conf_file = NULL;
96 int args_parse(args_t *args, int argc, char *argv[])
101 static struct option long_options[] = {
102 {"query-all", 0, 0, 'A'},
103 {"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE},
104 {"conf-file", 1, 0, 'f'},
107 {"force-defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
108 {"force_defaults", 0, 0, ARGS_OPT_FORCE_DEFAULTS},
109 {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
110 {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
111 {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
112 {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
113 {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
114 {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
115 {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
116 {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
117 {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
118 {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
120 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
121 {"force-removal-of-dependent-packages", 0, 0,
122 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
123 {"force_removal_of_dependent_packages", 0, 0,
124 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
125 {"force-removal-of-essential-packages", 0, 0,
126 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
127 {"force_removal_of_essential_packages", 0, 0,
128 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
129 {"multiple-providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
130 {"multiple_providers", 0, 0, ARGS_OPT_MULTIPLE_PROVIDERS},
131 {"noaction", 0, 0, ARGS_OPT_NOACTION},
132 {"nodeps", 0, 0, ARGS_OPT_NODEPS},
133 {"offline", 1, 0, 'o'},
134 {"offline-root", 1, 0, 'o'},
135 {"test", 0, 0, ARGS_OPT_NOACTION},
136 {"tmp-dir", 1, 0, 't'},
137 {"verbosity", 2, 0, 'V'},
138 {"version", 0, 0, 'v'},
143 c = getopt_long_only(argc, argv, "Ad:f:no:t:vV:", long_options, &option_index);
152 args->dest = strdup (optarg);
155 free(args->conf_file);
156 args->conf_file = strdup(optarg);
159 args->offline_root = strdup (optarg);
165 args->tmp_dir = strdup(optarg);
171 case ARGS_OPT_VERBOSITY:
173 args->verbosity = atoi(optarg);
175 args->verbosity += 1;
177 case ARGS_OPT_AUTOREMOVE:
178 args->autoremove = 1;
180 case ARGS_OPT_FORCE_DEFAULTS:
181 args->force_defaults = 1;
183 case ARGS_OPT_FORCE_DEPENDS:
184 args->force_depends = 1;
186 case ARGS_OPT_FORCE_OVERWRITE:
187 args->force_overwrite = 1;
189 case ARGS_OPT_FORCE_DOWNGRADE:
190 args->force_downgrade = 1;
192 case ARGS_OPT_FORCE_REINSTALL:
193 args->force_reinstall = 1;
195 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
196 args->force_removal_of_essential_packages = 1;
198 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
199 args->force_removal_of_dependent_packages = 1;
201 case ARGS_OPT_FORCE_SPACE:
202 args->force_space = 1;
204 case ARGS_OPT_MULTIPLE_PROVIDERS:
205 args->multiple_providers = 1;
207 case ARGS_OPT_NODEPS:
210 case ARGS_OPT_NOACTION:
220 printf("Confusion: getopt_long returned %d\n", c);
231 void args_usage(char *complaint)
234 printf("opkg: %s\n", complaint);
237 printf("usage: opkg [options...] sub-command [arguments...]\n");
238 printf("where sub-command is one of:\n");
240 printf("\nPackage Manipulation:\n");
241 printf("\tupdate Update list of available packages\n");
242 printf("\tupgrade Upgrade all installed packages to latest version\n");
243 printf("\tinstall <pkg> Download and install <pkg> (and dependencies)\n");
244 printf("\tinstall <file.ipk> Install package <file.ipk>\n");
245 printf("\tconfigure [<pkg>] Configure unpacked packages\n");
246 printf("\tremove <pkg|regexp> Remove package <pkg|packages following regexp>\n");
247 printf("\tflag <flag> <pkg> ... Flag package(s) <pkg>\n");
248 printf("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation) \n");
250 printf("\nInformational Commands:\n");
251 printf("\tlist List available packages and descriptions\n");
252 printf("\tlist_installed List all and only the installed packages and description \n");
253 printf("\tfiles <pkg> List all files belonging to <pkg>\n");
254 printf("\tsearch <file|regexp> Search for a package providing <file>\n");
255 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
256 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
257 printf("\tdownload <pkg> Download <pkg> to current directory.\n");
258 printf("\tcompare_versions <v1> <op> <v2>\n");
259 printf("\t compare versions using <= < > >= = << >>\n");
260 printf("\tprint_architecture prints the architecture.\n");
261 printf("\tprint_installation_architecture\n");
262 printf("\twhatdepends [-A] [pkgname|pat]+\n");
263 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
264 printf("\twhatprovides [-A] [pkgname|pat]+\n");
265 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
266 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
267 printf("\t prints the installation architecture.\n");
268 printf("\nOptions:\n");
269 printf("\t-A Query all packages with whatdepends, whatprovides, whatreplaces, whatconflicts\n");
270 printf("\t-V <level> Set verbosity level to <level>. If no value is\n");
271 printf("\t--verbosity <level> provided increase verbosity by one. Verbosity levels:\n");
272 printf("\t 0 errors only\n");
273 printf("\t 1 normal messages (default)\n");
274 printf("\t 2 informative messages\n");
275 printf("\t 3 debug output\n");
276 printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
277 printf("\t-conf <conf_file> Default configuration file location\n");
278 printf(" is %s/%s\n", ARGS_DEFAULT_CONF_FILE_DIR, ARGS_DEFAULT_CONF_FILE_NAME);
279 printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
280 printf("\t-dest <dest_name> package installation, removal, upgrading.\n");
281 printf(" <dest_name> should be a defined dest name from\n");
282 printf(" the configuration file, (but can also be a\n");
283 printf(" directory name in a pinch).\n");
284 printf("\t-o <offline_root> Use <offline_root> as the root directory for\n");
285 printf("\t-offline <offline_root> offline installation of packages.\n");
287 printf("\tForce Options (use when opkg is too smart for its own good):\n");
288 printf("\t-force-depends Make dependency checks warnings instead of errors\n");
289 printf("\t Install/remove package in spite of failed dependences\n");
290 printf("\t-force-defaults Use default options for questions asked by opkg.\n");
291 printf(" (no prompts). Note that this will not prevent\n");
292 printf(" package installation scripts from prompting.\n");
293 printf("\t-force-reinstall Allow opkg to reinstall a package.\n");
294 printf("\t-force-overwrite Allow opkg to overwrite files from another package during an install.\n");
295 printf("\t-force-downgrade Allow opkg to downgrade packages.\n");
296 printf("\t-force_space Install even if there does not seem to be enough space.\n");
297 printf("\t-noaction No action -- test only\n");
298 printf("\t-nodeps Do not follow dependences\n");
299 printf("\t-force-removal-of-dependent-packages\n");
300 printf("\t-recursive Allow opkg to remove package and all that depend on it.\n");
301 printf("\t-autoremove Allow opkg to remove packages that where installed automatically to satisfy dependencies.\n");
302 printf("\t-test No action -- test only\n");
303 printf("\t-t Specify tmp-dir.\n");
304 printf("\t--tmp-dir Specify tmp-dir.\n");
306 printf("\tregexp could be something like 'pkgname*' '*file*' or similar\n");
307 printf("\teg: opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
308 /* -force-removal-of-essential-packages Let opkg remove essential packages.
309 Using this option is almost guaranteed to break your system, hence this option
310 is not even advertised in the usage statement. */
314 static void print_version(void)
316 printf("opkg version %s\n", VERSION);