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 "../libbb/libbb.h"
35 static void print_version(void);
39 ARGS_OPT_FORCE_MAINTAINER = 129,
40 ARGS_OPT_FORCE_DEPENDS,
41 ARGS_OPT_FORCE_OVERWRITE,
42 ARGS_OPT_FORCE_DOWNGRADE,
43 ARGS_OPT_FORCE_REINSTALL,
44 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES,
45 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES,
53 int args_parse(int argc, char *argv[])
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},
78 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
79 {"force-removal-of-dependent-packages", 0, 0,
80 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
81 {"force_removal_of_dependent_packages", 0, 0,
82 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES},
83 {"force-removal-of-essential-packages", 0, 0,
84 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
85 {"force_removal_of_essential_packages", 0, 0,
86 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES},
87 {"noaction", 0, 0, ARGS_OPT_NOACTION},
88 {"nodeps", 0, 0, ARGS_OPT_NODEPS},
89 {"offline", 1, 0, 'o'},
90 {"offline-root", 1, 0, 'o'},
91 {"test", 0, 0, ARGS_OPT_NOACTION},
92 {"tmp-dir", 1, 0, 't'},
93 {"tmp_dir", 1, 0, 't'},
94 {"verbosity", 2, 0, 'V'},
95 {"version", 0, 0, 'v'},
100 c = getopt_long_only(argc, argv, "Ad:f:no:p:t:vV:", long_options, &option_index);
109 conf->dest_str = xstrdup(optarg);
112 conf->conf_file = xstrdup(optarg);
115 conf->offline_root = xstrdup(optarg);
118 conf->tmp_dir = xstrdup(optarg);
124 conf->verbosity = atoi(optarg);
126 case ARGS_OPT_AUTOREMOVE:
127 conf->autoremove = 1;
131 conf->cache = xstrdup(optarg);
133 case ARGS_OPT_FORCE_MAINTAINER:
134 conf->force_maintainer = 1;
136 case ARGS_OPT_FORCE_DEPENDS:
137 conf->force_depends = 1;
139 case ARGS_OPT_FORCE_OVERWRITE:
140 conf->force_overwrite = 1;
142 case ARGS_OPT_FORCE_DOWNGRADE:
143 conf->force_downgrade = 1;
145 case ARGS_OPT_FORCE_REINSTALL:
146 conf->force_reinstall = 1;
148 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES:
149 conf->force_removal_of_essential_packages = 1;
151 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES:
152 conf->force_removal_of_dependent_packages = 1;
154 case ARGS_OPT_FORCE_SPACE:
155 conf->force_space = 1;
157 case ARGS_OPT_NODEPS:
160 case ARGS_OPT_NOACTION:
170 printf("Confusion: getopt_long returned %d\n", c);
181 void args_usage(const char *complaint)
184 printf("opkg: %s\n", complaint);
187 printf("usage: opkg [options...] sub-command [arguments...]\n");
188 printf("where sub-command is one of:\n");
190 printf("\nPackage Manipulation:\n");
191 printf("\tupdate Update list of available packages\n");
192 printf("\tupgrade Upgrade installed packages\n");
193 printf("\tinstall <pkgs> Install package(s)\n");
194 printf("\tconfigure <pkgs> Configure unpacked package(s)\n");
195 printf("\tremove <pkgs|regexp> Remove package(s)\n");
196 printf("\tflag <flag> <pkgs> Flag package(s)\n");
197 printf("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n");
199 printf("\nInformational Commands:\n");
200 printf("\tlist List available packages\n");
201 printf("\tlist-installed List installed packages\n");
202 printf("\tlist-upgradable List installed and upgradable packages\n");
203 printf("\tfiles <pkg> List files belonging to <pkg>\n");
204 printf("\tsearch <file|regexp> List package providing <file>\n");
205 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n");
206 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n");
207 printf("\tdownload <pkg> Download <pkg> to current directory\n");
208 printf("\tcompare-versions <v1> <op> <v2>\n");
209 printf("\t compare versions using <= < > >= = << >>\n");
210 printf("\tprint-architecture List installable package architectures\n");
211 printf("\twhatdepends [-A] [pkgname|pat]+\n");
212 printf("\twhatdependsrec [-A] [pkgname|pat]+\n");
213 printf("\twhatprovides [-A] [pkgname|pat]+\n");
214 printf("\twhatconflicts [-A] [pkgname|pat]+\n");
215 printf("\twhatreplaces [-A] [pkgname|pat]+\n");
217 printf("\nOptions:\n");
218 printf("\t-A Query all packages not just those installed\n");
219 printf("\t-V <level> Set verbosity level to <level>.\n");
220 printf("\t--verbosity <level> Verbosity levels:\n");
221 printf("\t 0 errors only\n");
222 printf("\t 1 normal messages (default)\n");
223 printf("\t 2 informative messages\n");
224 printf("\t 3 debug\n");
225 printf("\t 4 debug level 2\n");
226 printf("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n");
227 printf("\t--conf <conf_file>\n");
228 printf("\t--cache <directory> Use a package cache\n");
229 printf("\t-d <dest_name> Use <dest_name> as the the root directory for\n");
230 printf("\t--dest <dest_name> package installation, removal, upgrading.\n");
231 printf(" <dest_name> should be a defined dest name from\n");
232 printf(" the configuration file, (but can also be a\n");
233 printf(" directory name in a pinch).\n");
234 printf("\t-o <dir> Use <dir> as the root directory for\n");
235 printf("\t--offline-root <dir> offline installation of packages.\n");
237 printf("\nForce Options:\n");
238 printf("\t--force-depends Install/remove despite failed dependences\n");
239 printf("\t--force-maintainer Overwrite preexisting config files\n");
240 printf("\t--force-reinstall Reinstall package(s)\n");
241 printf("\t--force-overwrite Overwrite files from other package(s)\n");
242 printf("\t--force-downgrade Allow opkg to downgrade packages\n");
243 printf("\t--force-space Disable free space checks\n");
244 printf("\t--noaction No action -- test only\n");
245 printf("\t--nodeps Do not follow dependences\n");
246 printf("\t--force-removal-of-dependent-packages\n");
247 printf("\t Remove package and all dependencies\n");
248 printf("\t--autoremove Remove packages that were installed\n");
249 printf("\t automatically to satisfy dependencies\n");
250 printf("\t-t Specify tmp-dir.\n");
251 printf("\t--tmp-dir Specify tmp-dir.\n");
255 printf(" regexp could be something like 'pkgname*' '*file*' or similar\n");
256 printf(" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n");
257 /* -force-removal-of-essential-packages Let opkg remove essential packages.
258 Using this option is almost guaranteed to break your system, hence this option
259 is not even advertised in the usage statement. */
263 static void print_version(void)
265 printf("opkg version %s\n", VERSION);
276 main(int argc, char *argv[])
281 int nocheckfordirorfile = 0;
282 int noreadfeedsfile = 0;
284 conf->verbosity = NOTICE;
286 opts = args_parse (argc, argv);
287 if (opts == argc || opts < 0)
289 args_usage ("opkg must have one sub-command argument");
292 cmd_name = argv[opts++];
294 if ( !strcmp(cmd_name,"print-architecture") ||
295 !strcmp(cmd_name,"print_architecture") ||
296 !strcmp(cmd_name,"print-installation-architecture") ||
297 !strcmp(cmd_name,"print_installation_architecture") )
298 nocheckfordirorfile = 1;
300 if ( !strcmp(cmd_name,"flag") ||
301 !strcmp(cmd_name,"configure") ||
302 !strcmp(cmd_name,"remove") ||
303 !strcmp(cmd_name,"files") ||
304 !strcmp(cmd_name,"search") ||
305 !strcmp(cmd_name,"compare_versions") ||
306 !strcmp(cmd_name,"compare-versions") ||
307 !strcmp(cmd_name,"list_installed") ||
308 !strcmp(cmd_name,"list-installed") ||
309 !strcmp(cmd_name,"status") )
312 cmd = opkg_cmd_find (cmd_name);
315 fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
320 conf->pfm = cmd->pfm;
322 if (opkg_conf_init())
325 if (!nocheckfordirorfile) {
326 if (!noreadfeedsfile) {
327 if (pkg_hash_load_feeds())
331 if (pkg_hash_load_status_files())
335 if (cmd->requires_args && opts == argc)
338 "%s: the ``%s'' command requires at least one argument\n",
343 if (opkg_cmd_exec (cmd, argc - opts, (const char **) (argv + opts)))