1 /* opkg-cl.c - the opkg package management system
4 Copyright (C) 2003 kernel concepts
7 Copyright 2001 University of Southern California
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2, or (at
12 your option) any later version.
14 This program is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 opkg command line frontend using libopkg
29 #include "opkg_conf.h"
31 #include "file_util.h"
32 #include "opkg_message.h"
33 #include "opkg_download.h"
34 #include "../libbb/libbb.h"
37 ARGS_OPT_FORCE_MAINTAINER = 129,
38 ARGS_OPT_FORCE_DEPENDS,
39 ARGS_OPT_FORCE_OVERWRITE,
40 ARGS_OPT_FORCE_DOWNGRADE,
41 ARGS_OPT_FORCE_REINSTALL,
42 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
43 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
45 ARGS_OPT_FORCE_POSTINSTALL,
46 ARGS_OPT_FORCE_REMOVE,
47 ARGS_OPT_FORCE_CHECKSUM,
51 ARGS_OPT_DOWNLOAD_ONLY,
56 ARGS_OPT_FORCE_SIGNATURE,
60 static struct option long_options[] = {
61 {"query-all", 0, 0, 'A'},
62 {"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE},
63 {"cache", 1, 0, ARGS_OPT_CACHE},
64 {"conf-file", 1, 0, 'f'},
67 {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
68 {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER},
69 {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
70 {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS},
71 {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
72 {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE},
73 {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
74 {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE},
75 {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
76 {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL},
77 {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE},
78 {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE},
79 {"recursive", 0, 0, ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
80 {"force-removal-of-dependent-packages", 0, 0,
81 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
82 {"force_removal_of_dependent_packages", 0, 0,
83 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
84 {"force-removal-of-essential-packages", 0, 0,
85 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
86 {"force_removal_of_essential_packages", 0, 0,
87 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
88 {"force-postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL},
89 {"force_postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL},
90 {"force-remove", 0, 0, ARGS_OPT_FORCE_REMOVE},
91 {"force_remove", 0, 0, ARGS_OPT_FORCE_REMOVE},
92 {"force-checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM},
93 {"force_checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM},
94 {"force-signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE},
95 {"force_signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE},
96 {"noaction", 0, 0, ARGS_OPT_NOACTION},
97 {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY},
98 {"nodeps", 0, 0, ARGS_OPT_NODEPS},
99 {"nocase", 0, 0, ARGS_OPT_NOCASE},
100 {"offline", 1, 0, 'o'},
101 {"offline-root", 1, 0, 'o'},
102 {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
103 {"add-dest", 1, 0, ARGS_OPT_ADD_DEST},
104 {"size", 0, 0, ARGS_OPT_SIZE},
105 {"test", 0, 0, ARGS_OPT_NOACTION},
106 {"tmp-dir", 1, 0, 't'},
107 {"tmp_dir", 1, 0, 't'},
108 {"lists-dir", 1, 0, 'l'},
109 {"lists_dir", 1, 0, 'l'},
110 {"verbosity", 2, 0, 'V'},
111 {"version", 0, 0, 'v'},
115 static int args_parse(int argc, char *argv[])
118 int option_index = 0;
123 c = getopt_long_only(argc, argv, "Ad:f:ino:p:l:t:vV::",
124 long_options, &option_index);
133 conf->dest_str = xstrdup(optarg);
136 conf->conf_file = xstrdup(optarg);
139 conf->nocase = FNM_CASEFOLD;
142 conf->offline_root = xstrdup(optarg);
145 conf->tmp_dir = xstrdup(optarg);
148 conf->lists_dir = xstrdup(optarg);
151 printf("opkg version %s\n", VERSION);
154 conf->verbosity = INFO;
156 conf->verbosity = atoi(optarg);
158 case ARGS_OPT_AUTOREMOVE:
159 conf->autoremove = 1;
163 conf->cache = xstrdup(optarg);
165 case ARGS_OPT_FORCE_MAINTAINER:
166 conf->force_maintainer = 1;
168 case ARGS_OPT_FORCE_DEPENDS:
169 conf->force_depends = 1;
171 case ARGS_OPT_FORCE_OVERWRITE:
172 conf->force_overwrite = 1;
174 case ARGS_OPT_FORCE_DOWNGRADE:
175 conf->force_downgrade = 1;
177 case ARGS_OPT_FORCE_REINSTALL:
178 conf->force_reinstall = 1;
180 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
181 conf->force_removal_of_essential_packages = 1;
183 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
184 conf->force_removal_of_dependent_packages = 1;
186 case ARGS_OPT_FORCE_SPACE:
187 conf->force_space = 1;
189 case ARGS_OPT_FORCE_POSTINSTALL:
190 conf->force_postinstall = 1;
192 case ARGS_OPT_FORCE_REMOVE:
193 conf->force_remove = 1;
195 case ARGS_OPT_FORCE_CHECKSUM:
196 conf->force_checksum = 1;
198 case ARGS_OPT_NODEPS:
201 case ARGS_OPT_NOCASE:
202 conf->nocase = FNM_CASEFOLD;
204 case ARGS_OPT_ADD_ARCH:
205 case ARGS_OPT_ADD_DEST:
206 tuple = xstrdup(optarg);
207 if ((targ = strchr(tuple, ':')) != NULL) {
209 if ((strlen(tuple) > 0) && (strlen(targ) > 0)) {
210 nv_pair_list_append((c ==
213 &conf->tmp_dest_list,
222 case ARGS_OPT_NOACTION:
225 case ARGS_OPT_DOWNLOAD_ONLY:
226 conf->download_only = 1;
228 case ARGS_OPT_FORCE_SIGNATURE:
229 conf->force_signature = 1;
238 printf("Confusion: getopt_long returned %d\n", c);
242 if (!conf->conf_file && !conf->offline_root)
243 conf->conf_file = xstrdup("/etc/opkg.conf");
253 printf("usage: opkg [options...] sub-command [arguments...]\n");
254 printf("where sub-command is one of:\n");
256 printf("\nPackage Manipulation:\n");
258 ("\tupdate Update list of available packages\n");
259 printf("\tupgrade <pkgs> Upgrade packages\n");
260 printf("\tinstall <pkgs> Install package(s)\n");
261 printf("\tconfigure <pkgs> Configure unpacked package(s)\n");
262 printf("\tremove <pkgs|regexp> Remove package(s)\n");
263 printf("\tflag <flag> <pkgs> Flag package(s)\n");
265 ("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n");
267 printf("\nInformational Commands:\n");
268 printf("\tlist List available packages\n");
269 printf("\tlist-installed List installed packages\n");
271 ("\tlist-upgradable List installed and upgradable packages\n");
273 ("\tlist-changed-conffiles List user modified configuration files\n");
274 printf("\tfiles <pkg> List files belonging to <pkg>\n");
275 printf("\tsearch <file|regexp> List package providing <file>\n");
277 ("\tfind <regexp> List packages whose name or description matches <regexp>\n");
278 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
279 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
281 ("\tdownload <pkg> Download <pkg> to current directory\n");
282 printf("\tcompare-versions <v1> <op> <v2>\n");
284 ("\t compare versions using <= < > >= = << >>\n");
286 ("\tprint-architecture List installable package architectures\n");
287 printf("\tdepends [-A] [pkgname|pat]+\n");
288 printf("\twhatdepends [-A] [pkgname|pat]+\n");
289 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
290 printf("\twhatrecommends[-A] [pkgname|pat]+\n");
291 printf("\twhatsuggests[-A] [pkgname|pat]+\n");
292 printf("\twhatprovides [-A] [pkgname|pat]+\n");
293 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
294 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
296 printf("\nOptions:\n");
298 ("\t-A Query all packages not just those installed\n");
299 printf("\t-V[<level>] Set verbosity level to <level>.\n");
300 printf("\t--verbosity[=<level>] Verbosity levels:\n");
301 printf("\t 0 errors only\n");
302 printf("\t 1 normal messages (default)\n");
303 printf("\t 2 informative messages\n");
304 printf("\t 3 debug\n");
305 printf("\t 4 debug level 2\n");
307 ("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
308 printf("\t--conf <conf_file>\n");
309 printf("\t--cache <directory> Use a package cache\n");
311 ("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
313 ("\t--dest <dest_name> package installation, removal, upgrading.\n");
315 (" <dest_name> should be a defined dest name from\n");
317 (" the configuration file, (but can also be a\n");
318 printf(" directory name in a pinch).\n");
319 printf("\t-o <dir> Use <dir> as the root directory for\n");
320 printf("\t--offline-root <dir> offline installation of packages.\n");
322 ("\t--add-arch <arch>:<prio> Register architecture with given priority\n");
324 ("\t--add-dest <name>:<path> Register destination with given path\n");
326 printf("\nForce Options:\n");
328 ("\t--force-depends Install/remove despite failed dependencies\n");
329 printf("\t--force-maintainer Overwrite preexisting config files\n");
330 printf("\t--force-reinstall Reinstall package(s)\n");
332 ("\t--force-overwrite Overwrite files from other package(s)\n");
333 printf("\t--force-downgrade Allow opkg to downgrade packages\n");
334 printf("\t--force-space Disable free space checks\n");
336 ("\t--force-postinstall Run postinstall scripts even in offline mode\n");
338 ("\t--force-remove Remove package even if prerm script fails\n");
339 printf("\t--force-checksum Don't fail on checksum mismatches\n");
340 printf("\t--noaction No action -- test only\n");
341 printf("\t--download-only No action -- download only\n");
342 printf("\t--nodeps Do not follow dependencies\n");
344 ("\t--nocase Perform case insensitive pattern matching\n");
346 ("\t--size Print package size when listing available packages\n");
347 printf("\t--force-removal-of-dependent-packages\n");
348 printf("\t Remove package and all dependencies\n");
349 printf("\t--autoremove Remove packages that were installed\n");
351 ("\t automatically to satisfy dependencies\n");
352 printf("\t-t Specify tmp-dir.\n");
353 printf("\t--tmp-dir Specify tmp-dir.\n");
354 printf("\t-l Specify lists-dir.\n");
355 printf("\t--lists-dir Specify lists-dir.\n");
360 (" regexp could be something like 'pkgname*' '*file*' or similar\n");
362 (" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
364 /* --force-removal-of-essential-packages Let opkg remove essential packages.
365 Using this option is almost guaranteed to break your system, hence this option
366 is not even advertised in the usage statement. */
371 int main(int argc, char *argv[])
376 int nocheckfordirorfile = 0;
377 int noreadfeedsfile = 0;
379 if (opkg_conf_init())
382 conf->verbosity = NOTICE;
384 opts = args_parse(argc, argv);
385 if (opts == argc || opts < 0) {
386 fprintf(stderr, "opkg must have one sub-command argument\n");
390 cmd_name = argv[opts++];
392 if (!strcmp(cmd_name, "install") ||
393 !strcmp(cmd_name, "print-architecture") ||
394 !strcmp(cmd_name, "print_architecture") ||
395 !strcmp(cmd_name, "print-installation-architecture") ||
396 !strcmp(cmd_name, "print_installation_architecture"))
397 nocheckfordirorfile = 1;
399 if (!strcmp(cmd_name, "flag") ||
400 !strcmp(cmd_name, "configure") ||
401 !strcmp(cmd_name, "install") ||
402 !strcmp(cmd_name, "remove") ||
403 !strcmp(cmd_name, "files") ||
404 !strcmp(cmd_name, "search") ||
405 !strcmp(cmd_name, "compare_versions") ||
406 !strcmp(cmd_name, "compare-versions") ||
407 !strcmp(cmd_name, "list_installed") ||
408 !strcmp(cmd_name, "list-installed") ||
409 !strcmp(cmd_name, "list_changed_conffiles") ||
410 !strcmp(cmd_name, "list-changed-conffiles") ||
411 !strcmp(cmd_name, "status"))
414 cmd = opkg_cmd_find(cmd_name);
416 fprintf(stderr, "%s: unknown sub-command %s\n", argv[0],
421 conf->pfm = cmd->pfm;
423 if (opkg_conf_load())
426 if (!nocheckfordirorfile) {
427 if (!noreadfeedsfile) {
428 if (pkg_hash_load_feeds(SF_NEED_DETAIL))
432 if (pkg_hash_load_status_files())
436 if (cmd->requires_args && opts == argc) {
438 "%s: the ``%s'' command requires at least one argument\n",
443 err = opkg_cmd_exec(cmd, argc - opts, (const char **)(argv + opts));