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
27 #include "opkg_conf.h"
29 #include "file_util.h"
30 #include "opkg_message.h"
31 #include "opkg_download.h"
32 #include "../libbb/libbb.h"
35 ARGS_OPT_FORCE_MAINTAINER
= 129,
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
,
43 ARGS_OPT_FORCE_POSTINSTALL
,
44 ARGS_OPT_FORCE_REMOVE
,
45 ARGS_OPT_FORCE_CHECKSUM
,
49 ARGS_OPT_DOWNLOAD_ONLY
,
54 ARGS_OPT_FORCE_SIGNATURE
,
55 ARGS_OPT_NO_CHECK_CERTIFICATE
,
56 ARGS_OPT_VERIFY_PROGRAM
,
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 {"no-check-certificate", 0, 0, ARGS_OPT_NO_CHECK_CERTIFICATE
},
97 {"no_check_certificate", 0, 0, ARGS_OPT_NO_CHECK_CERTIFICATE
},
98 {"noaction", 0, 0, ARGS_OPT_NOACTION
},
99 {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY
},
100 {"nodeps", 0, 0, ARGS_OPT_NODEPS
},
101 {"nocase", 0, 0, ARGS_OPT_NOCASE
},
102 {"offline", 1, 0, 'o'},
103 {"offline-root", 1, 0, 'o'},
104 {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH
},
105 {"add-dest", 1, 0, ARGS_OPT_ADD_DEST
},
106 {"size", 0, 0, ARGS_OPT_SIZE
},
107 {"test", 0, 0, ARGS_OPT_NOACTION
},
108 {"tmp-dir", 1, 0, 't'},
109 {"tmp_dir", 1, 0, 't'},
110 {"lists-dir", 1, 0, 'l'},
111 {"lists_dir", 1, 0, 'l'},
112 {"verbosity", 2, 0, 'V'},
113 {"verify-program", 1, 0, ARGS_OPT_VERIFY_PROGRAM
},
114 {"verify_program", 1, 0, ARGS_OPT_VERIFY_PROGRAM
},
115 {"version", 0, 0, 'v'},
119 static int args_parse(int argc
, char *argv
[])
122 int option_index
= 0;
127 c
= getopt_long_only(argc
, argv
, "Ad:f:ino:p:l:t:vV::",
128 long_options
, &option_index
);
137 conf
->dest_str
= xstrdup(optarg
);
140 conf
->conf_file
= xstrdup(optarg
);
143 conf
->nocase
= FNM_CASEFOLD
;
146 conf
->offline_root
= xstrdup(optarg
);
149 conf
->tmp_dir
= xstrdup(optarg
);
152 conf
->lists_dir
= xstrdup(optarg
);
155 printf("opkg version %s\n", VERSION
);
158 conf
->verbosity
= INFO
;
160 conf
->verbosity
= atoi(optarg
);
162 case ARGS_OPT_AUTOREMOVE
:
163 conf
->autoremove
= 1;
167 conf
->cache
= xstrdup(optarg
);
169 case ARGS_OPT_FORCE_MAINTAINER
:
170 conf
->force_maintainer
= 1;
172 case ARGS_OPT_FORCE_DEPENDS
:
173 conf
->force_depends
= 1;
175 case ARGS_OPT_FORCE_OVERWRITE
:
176 conf
->force_overwrite
= 1;
178 case ARGS_OPT_FORCE_DOWNGRADE
:
179 conf
->force_downgrade
= 1;
181 case ARGS_OPT_FORCE_REINSTALL
:
182 conf
->force_reinstall
= 1;
184 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES
:
185 conf
->force_removal_of_essential_packages
= 1;
187 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES
:
188 conf
->force_removal_of_dependent_packages
= 1;
190 case ARGS_OPT_FORCE_SPACE
:
191 conf
->force_space
= 1;
193 case ARGS_OPT_FORCE_POSTINSTALL
:
194 conf
->force_postinstall
= 1;
196 case ARGS_OPT_FORCE_REMOVE
:
197 conf
->force_remove
= 1;
199 case ARGS_OPT_FORCE_CHECKSUM
:
200 conf
->force_checksum
= 1;
202 case ARGS_OPT_NODEPS
:
205 case ARGS_OPT_NOCASE
:
206 conf
->nocase
= FNM_CASEFOLD
;
208 case ARGS_OPT_ADD_ARCH
:
209 case ARGS_OPT_ADD_DEST
:
210 tuple
= xstrdup(optarg
);
211 if ((targ
= strchr(tuple
, ':')) != NULL
) {
213 if ((strlen(tuple
) > 0) && (strlen(targ
) > 0)) {
214 nv_pair_list_append((c
==
217 &conf
->tmp_dest_list
,
226 case ARGS_OPT_NOACTION
:
229 case ARGS_OPT_DOWNLOAD_ONLY
:
230 conf
->download_only
= 1;
232 case ARGS_OPT_FORCE_SIGNATURE
:
233 conf
->force_signature
= 1;
235 case ARGS_OPT_NO_CHECK_CERTIFICATE
:
236 conf
->no_check_certificate
= 1;
238 case ARGS_OPT_VERIFY_PROGRAM
:
239 conf
->verify_program
= xstrdup(optarg
);
248 printf("Confusion: getopt_long returned %d\n", c
);
252 if (!conf
->conf_file
&& !conf
->offline_root
)
253 conf
->conf_file
= xstrdup("/etc/opkg.conf");
263 printf("usage: opkg [options...] sub-command [arguments...]\n");
264 printf("where sub-command is one of:\n");
266 printf("\nPackage Manipulation:\n");
268 ("\tupdate Update list of available packages\n");
269 printf("\tupgrade <pkgs> Upgrade packages\n");
270 printf("\tinstall <pkgs> Install package(s)\n");
271 printf("\tconfigure <pkgs> Configure unpacked package(s)\n");
272 printf("\tremove <pkgs|regexp> Remove package(s)\n");
273 printf("\tflag <flag> <pkgs> Flag package(s)\n");
275 ("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n");
277 printf("\nInformational Commands:\n");
278 printf("\tlist List available packages\n");
279 printf("\tlist-installed List installed packages\n");
281 ("\tlist-upgradable List installed and upgradable packages\n");
283 ("\tlist-changed-conffiles List user modified configuration files\n");
284 printf("\tfiles <pkg> List files belonging to <pkg>\n");
285 printf("\tsearch <file|regexp> List package providing <file>\n");
287 ("\tfind <regexp> List packages whose name or description matches <regexp>\n");
288 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
289 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
291 ("\tdownload <pkg> Download <pkg> to current directory\n");
292 printf("\tcompare-versions <v1> <op> <v2>\n");
294 ("\t compare versions using <= < > >= = << >>\n");
296 ("\tprint-architecture List installable package architectures\n");
297 printf("\tdepends [-A] [pkgname|pat]+\n");
298 printf("\twhatdepends [-A] [pkgname|pat]+\n");
299 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
300 printf("\twhatrecommends[-A] [pkgname|pat]+\n");
301 printf("\twhatsuggests[-A] [pkgname|pat]+\n");
302 printf("\twhatprovides [-A] [pkgname|pat]+\n");
303 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
304 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
306 printf("\nOptions:\n");
308 ("\t-A Query all packages not just those installed\n");
309 printf("\t-V[<level>] Set verbosity level to <level>.\n");
310 printf("\t--verbosity[=<level>] Verbosity levels:\n");
311 printf("\t 0 errors only\n");
312 printf("\t 1 normal messages (default)\n");
313 printf("\t 2 informative messages\n");
314 printf("\t 3 debug\n");
315 printf("\t 4 debug level 2\n");
317 ("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
318 printf("\t--conf <conf_file>\n");
319 printf("\t--cache <directory> Use a package cache\n");
321 ("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
323 ("\t--dest <dest_name> package installation, removal, upgrading.\n");
325 (" <dest_name> should be a defined dest name from\n");
327 (" the configuration file, (but can also be a\n");
328 printf(" directory name in a pinch).\n");
329 printf("\t-o <dir> Use <dir> as the root directory for\n");
330 printf("\t--offline-root <dir> offline installation of packages.\n");
332 ("\t--verify-program <path> Use the given program to verify usign signatures\n");
334 ("\t--add-arch <arch>:<prio> Register architecture with given priority\n");
336 ("\t--add-dest <name>:<path> Register destination with given path\n");
338 printf("\nForce Options:\n");
340 ("\t--force-depends Install/remove despite failed dependencies\n");
341 printf("\t--force-maintainer Overwrite preexisting config files\n");
342 printf("\t--force-reinstall Reinstall package(s)\n");
344 ("\t--force-overwrite Overwrite files from other package(s)\n");
345 printf("\t--force-downgrade Allow opkg to downgrade packages\n");
346 printf("\t--force-space Disable free space checks\n");
348 ("\t--force-postinstall Run postinstall scripts even in offline mode\n");
350 ("\t--force-remove Remove package even if prerm script fails\n");
351 printf("\t--force-checksum Don't fail on checksum mismatches\n");
352 printf("\t--no-check-certificate Don't validate SSL certificates\n");
353 printf("\t--noaction No action -- test only\n");
354 printf("\t--download-only No action -- download only\n");
355 printf("\t--nodeps Do not follow dependencies\n");
357 ("\t--nocase Perform case insensitive pattern matching\n");
359 ("\t--size Print package size when listing available packages\n");
360 printf("\t--force-removal-of-dependent-packages\n");
361 printf("\t Remove package and all dependencies\n");
362 printf("\t--autoremove Remove packages that were installed\n");
364 ("\t automatically to satisfy dependencies\n");
365 printf("\t-t Specify tmp-dir.\n");
366 printf("\t--tmp-dir Specify tmp-dir.\n");
367 printf("\t-l Specify lists-dir.\n");
368 printf("\t--lists-dir Specify lists-dir.\n");
373 (" regexp could be something like 'pkgname*' '*file*' or similar\n");
375 (" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
377 /* --force-removal-of-essential-packages Let opkg remove essential packages.
378 Using this option is almost guaranteed to break your system, hence this option
379 is not even advertised in the usage statement. */
384 int main(int argc
, char *argv
[])
389 int nocheckfordirorfile
= 0;
390 int noreadfeedsfile
= 0;
392 if (opkg_conf_init())
395 conf
->verbosity
= NOTICE
;
397 opts
= args_parse(argc
, argv
);
398 if (opts
== argc
|| opts
< 0) {
399 fprintf(stderr
, "opkg must have one sub-command argument\n");
403 cmd_name
= argv
[opts
++];
405 if (!strcmp(cmd_name
, "install") ||
406 !strcmp(cmd_name
, "print-architecture") ||
407 !strcmp(cmd_name
, "print_architecture") ||
408 !strcmp(cmd_name
, "print-installation-architecture") ||
409 !strcmp(cmd_name
, "print_installation_architecture") ||
410 !strcmp(cmd_name
, "compare_versions") ||
411 !strcmp(cmd_name
, "compare-versions"))
412 nocheckfordirorfile
= 1;
414 if (!strcmp(cmd_name
, "flag") ||
415 !strcmp(cmd_name
, "configure") ||
416 !strcmp(cmd_name
, "install") ||
417 !strcmp(cmd_name
, "remove") ||
418 !strcmp(cmd_name
, "files") ||
419 !strcmp(cmd_name
, "search") ||
420 !strcmp(cmd_name
, "list") ||
421 !strcmp(cmd_name
, "list_installed") ||
422 !strcmp(cmd_name
, "list-installed") ||
423 !strcmp(cmd_name
, "list_changed_conffiles") ||
424 !strcmp(cmd_name
, "list-changed-conffiles") ||
425 !strcmp(cmd_name
, "status") ||
426 !strcmp(cmd_name
, "update"))
429 cmd
= opkg_cmd_find(cmd_name
);
431 fprintf(stderr
, "%s: unknown sub-command %s\n", argv
[0],
436 conf
->pfm
= cmd
->pfm
;
438 if (opkg_conf_load())
441 if (!nocheckfordirorfile
) {
442 if (!noreadfeedsfile
) {
443 if (pkg_hash_load_feeds(SF_NEED_DETAIL
, NULL
, NULL
))
447 if (pkg_hash_load_status_files(NULL
, NULL
))
451 if (cmd
->requires_args
&& opts
== argc
) {
453 "%s: the ``%s'' command requires at least one argument\n",
458 err
= opkg_cmd_exec(cmd
, argc
- opts
, (const char **)(argv
+ opts
));