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
,
58 static struct option long_options
[] = {
59 {"query-all", 0, 0, 'A'},
60 {"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE
},
61 {"cache", 1, 0, ARGS_OPT_CACHE
},
62 {"conf-file", 1, 0, 'f'},
65 {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER
},
66 {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER
},
67 {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS
},
68 {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS
},
69 {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE
},
70 {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE
},
71 {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE
},
72 {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE
},
73 {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL
},
74 {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL
},
75 {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE
},
76 {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE
},
77 {"recursive", 0, 0, ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES
},
78 {"force-removal-of-dependent-packages", 0, 0,
79 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-essential-packages", 0, 0,
83 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES
},
84 {"force_removal_of_essential_packages", 0, 0,
85 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES
},
86 {"force-postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL
},
87 {"force_postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL
},
88 {"force-remove", 0, 0, ARGS_OPT_FORCE_REMOVE
},
89 {"force_remove", 0, 0, ARGS_OPT_FORCE_REMOVE
},
90 {"force-checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM
},
91 {"force_checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM
},
92 {"force-signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE
},
93 {"force_signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE
},
94 {"noaction", 0, 0, ARGS_OPT_NOACTION
},
95 {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY
},
96 {"nodeps", 0, 0, ARGS_OPT_NODEPS
},
97 {"nocase", 0, 0, ARGS_OPT_NOCASE
},
98 {"offline", 1, 0, 'o'},
99 {"offline-root", 1, 0, 'o'},
100 {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH
},
101 {"add-dest", 1, 0, ARGS_OPT_ADD_DEST
},
102 {"size", 0, 0, ARGS_OPT_SIZE
},
103 {"test", 0, 0, ARGS_OPT_NOACTION
},
104 {"tmp-dir", 1, 0, 't'},
105 {"tmp_dir", 1, 0, 't'},
106 {"lists-dir", 1, 0, 'l'},
107 {"lists_dir", 1, 0, 'l'},
108 {"verbosity", 2, 0, 'V'},
109 {"version", 0, 0, 'v'},
114 args_parse(int argc
, char *argv
[])
117 int option_index
= 0;
122 c
= getopt_long_only(argc
, argv
, "Ad:f:ino:p:l:t:vV::",
123 long_options
, &option_index
);
132 conf
->dest_str
= xstrdup(optarg
);
135 conf
->conf_file
= xstrdup(optarg
);
138 conf
->nocase
= FNM_CASEFOLD
;
141 conf
->offline_root
= xstrdup(optarg
);
144 conf
->tmp_dir
= xstrdup(optarg
);
147 conf
->lists_dir
= xstrdup(optarg
);
150 printf("opkg version %s\n", VERSION
);
153 conf
->verbosity
= INFO
;
155 conf
->verbosity
= atoi(optarg
);
157 case ARGS_OPT_AUTOREMOVE
:
158 conf
->autoremove
= 1;
162 conf
->cache
= xstrdup(optarg
);
164 case ARGS_OPT_FORCE_MAINTAINER
:
165 conf
->force_maintainer
= 1;
167 case ARGS_OPT_FORCE_DEPENDS
:
168 conf
->force_depends
= 1;
170 case ARGS_OPT_FORCE_OVERWRITE
:
171 conf
->force_overwrite
= 1;
173 case ARGS_OPT_FORCE_DOWNGRADE
:
174 conf
->force_downgrade
= 1;
176 case ARGS_OPT_FORCE_REINSTALL
:
177 conf
->force_reinstall
= 1;
179 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES
:
180 conf
->force_removal_of_essential_packages
= 1;
182 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES
:
183 conf
->force_removal_of_dependent_packages
= 1;
185 case ARGS_OPT_FORCE_SPACE
:
186 conf
->force_space
= 1;
188 case ARGS_OPT_FORCE_POSTINSTALL
:
189 conf
->force_postinstall
= 1;
191 case ARGS_OPT_FORCE_REMOVE
:
192 conf
->force_remove
= 1;
194 case ARGS_OPT_FORCE_CHECKSUM
:
195 conf
->force_checksum
= 1;
197 case ARGS_OPT_NODEPS
:
200 case ARGS_OPT_NOCASE
:
201 conf
->nocase
= FNM_CASEFOLD
;
203 case ARGS_OPT_ADD_ARCH
:
204 case ARGS_OPT_ADD_DEST
:
205 tuple
= xstrdup(optarg
);
206 if ((targ
= strchr(tuple
, ':')) != NULL
) {
208 if ((strlen(tuple
) > 0) && (strlen(targ
) > 0)) {
210 (c
== ARGS_OPT_ADD_ARCH
)
211 ? &conf
->arch_list
: &conf
->tmp_dest_list
,
220 case ARGS_OPT_NOACTION
:
223 case ARGS_OPT_DOWNLOAD_ONLY
:
224 conf
->download_only
= 1;
226 case ARGS_OPT_FORCE_SIGNATURE
:
227 conf
->force_signature
= 1;
236 printf("Confusion: getopt_long returned %d\n", c
);
240 if(!conf
->conf_file
&& !conf
->offline_root
)
241 conf
->conf_file
= xstrdup("/etc/opkg.conf");
252 printf("usage: opkg [options...] sub-command [arguments...]\n");
253 printf("where sub-command is one of:\n");
255 printf("\nPackage Manipulation:\n");
256 printf("\tupdate Update list of available packages\n");
257 printf("\tupgrade <pkgs> Upgrade packages\n");
258 printf("\tinstall <pkgs> Install package(s)\n");
259 printf("\tconfigure <pkgs> Configure unpacked package(s)\n");
260 printf("\tremove <pkgs|regexp> Remove package(s)\n");
261 printf("\tflag <flag> <pkgs> Flag package(s)\n");
262 printf("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n");
264 printf("\nInformational Commands:\n");
265 printf("\tlist List available packages\n");
266 printf("\tlist-installed List installed packages\n");
267 printf("\tlist-upgradable List installed and upgradable packages\n");
268 printf("\tlist-changed-conffiles List user modified configuration files\n");
269 printf("\tfiles <pkg> List files belonging to <pkg>\n");
270 printf("\tsearch <file|regexp> List package providing <file>\n");
271 printf("\tfind <regexp> List packages whose name or description matches <regexp>\n");
272 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
273 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
274 printf("\tdownload <pkg> Download <pkg> to current directory\n");
275 printf("\tcompare-versions <v1> <op> <v2>\n");
276 printf("\t compare versions using <= < > >= = << >>\n");
277 printf("\tprint-architecture List installable package architectures\n");
278 printf("\tdepends [-A] [pkgname|pat]+\n");
279 printf("\twhatdepends [-A] [pkgname|pat]+\n");
280 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
281 printf("\twhatrecommends[-A] [pkgname|pat]+\n");
282 printf("\twhatsuggests[-A] [pkgname|pat]+\n");
283 printf("\twhatprovides [-A] [pkgname|pat]+\n");
284 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
285 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
287 printf("\nOptions:\n");
288 printf("\t-A Query all packages not just those installed\n");
289 printf("\t-V[<level>] Set verbosity level to <level>.\n");
290 printf("\t--verbosity[=<level>] Verbosity levels:\n");
291 printf("\t 0 errors only\n");
292 printf("\t 1 normal messages (default)\n");
293 printf("\t 2 informative messages\n");
294 printf("\t 3 debug\n");
295 printf("\t 4 debug level 2\n");
296 printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
297 printf("\t--conf <conf_file>\n");
298 printf("\t--cache <directory> Use a package cache\n");
299 printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
300 printf("\t--dest <dest_name> package installation, removal, upgrading.\n");
301 printf(" <dest_name> should be a defined dest name from\n");
302 printf(" the configuration file, (but can also be a\n");
303 printf(" directory name in a pinch).\n");
304 printf("\t-o <dir> Use <dir> as the root directory for\n");
305 printf("\t--offline-root <dir> offline installation of packages.\n");
306 printf("\t--add-arch <arch>:<prio> Register architecture with given priority\n");
307 printf("\t--add-dest <name>:<path> Register destination with given path\n");
309 printf("\nForce Options:\n");
310 printf("\t--force-depends Install/remove despite failed dependencies\n");
311 printf("\t--force-maintainer Overwrite preexisting config files\n");
312 printf("\t--force-reinstall Reinstall package(s)\n");
313 printf("\t--force-overwrite Overwrite files from other package(s)\n");
314 printf("\t--force-downgrade Allow opkg to downgrade packages\n");
315 printf("\t--force-space Disable free space checks\n");
316 printf("\t--force-postinstall Run postinstall scripts even in offline mode\n");
317 printf("\t--force-remove Remove package even if prerm script fails\n");
318 printf("\t--force-checksum Don't fail on checksum mismatches\n");
319 printf("\t--noaction No action -- test only\n");
320 printf("\t--download-only No action -- download only\n");
321 printf("\t--nodeps Do not follow dependencies\n");
322 printf("\t--nocase Perform case insensitive pattern matching\n");
323 printf("\t--size Print package size when listing available packages\n");
324 printf("\t--force-removal-of-dependent-packages\n");
325 printf("\t Remove package and all dependencies\n");
326 printf("\t--autoremove Remove packages that were installed\n");
327 printf("\t automatically to satisfy dependencies\n");
328 printf("\t-t Specify tmp-dir.\n");
329 printf("\t--tmp-dir Specify tmp-dir.\n");
330 printf("\t-l Specify lists-dir.\n");
331 printf("\t--lists-dir Specify lists-dir.\n");
335 printf(" regexp could be something like 'pkgname*' '*file*' or similar\n");
336 printf(" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
338 /* --force-removal-of-essential-packages Let opkg remove essential packages.
339 Using this option is almost guaranteed to break your system, hence this option
340 is not even advertised in the usage statement. */
346 main(int argc
, char *argv
[])
351 int nocheckfordirorfile
= 0;
352 int noreadfeedsfile
= 0;
354 if (opkg_conf_init())
357 conf
->verbosity
= NOTICE
;
359 opts
= args_parse(argc
, argv
);
360 if (opts
== argc
|| opts
< 0) {
361 fprintf(stderr
, "opkg must have one sub-command argument\n");
365 cmd_name
= argv
[opts
++];
367 if (!strcmp(cmd_name
,"print-architecture") ||
368 !strcmp(cmd_name
,"print_architecture") ||
369 !strcmp(cmd_name
,"print-installation-architecture") ||
370 !strcmp(cmd_name
,"print_installation_architecture") )
371 nocheckfordirorfile
= 1;
373 if (!strcmp(cmd_name
,"flag") ||
374 !strcmp(cmd_name
,"configure") ||
375 !strcmp(cmd_name
,"remove") ||
376 !strcmp(cmd_name
,"files") ||
377 !strcmp(cmd_name
,"search") ||
378 !strcmp(cmd_name
,"compare_versions") ||
379 !strcmp(cmd_name
,"compare-versions") ||
380 !strcmp(cmd_name
,"list_installed") ||
381 !strcmp(cmd_name
,"list-installed") ||
382 !strcmp(cmd_name
,"list_changed_conffiles") ||
383 !strcmp(cmd_name
,"list-changed-conffiles") ||
384 !strcmp(cmd_name
,"status") )
387 cmd
= opkg_cmd_find(cmd_name
);
389 fprintf(stderr
, "%s: unknown sub-command %s\n", argv
[0],
394 conf
->pfm
= cmd
->pfm
;
396 if (opkg_conf_load())
399 if (!nocheckfordirorfile
) {
400 if (!noreadfeedsfile
) {
401 if (pkg_hash_load_feeds())
405 if (pkg_hash_load_status_files())
409 if (cmd
->requires_args
&& opts
== argc
) {
411 "%s: the ``%s'' command requires at least one argument\n",
416 err
= opkg_cmd_exec(cmd
, argc
- opts
, (const char **) (argv
+ opts
));