1 /* opkg-cl.c - the opkg package management system 2 3 Florian Boor 4 Copyright (C) 2003 kernel concepts 5 6 Carl D. Worth 7 Copyright 2001 University of Southern California 8 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. 13 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. 18 19 opkg command line frontend using libopkg 20 */ 21 22 #define _GNU_SOURCE 23 #include <stdio.h> 24 #include <getopt.h> 25 #include <fnmatch.h> 26 27 #include "opkg_conf.h" 28 #include "opkg_cmd.h" 29 #include "file_util.h" 30 #include "opkg_message.h" 31 #include "opkg_download.h" 32 #include "../libbb/libbb.h" 33 34 enum { 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, 42 ARGS_OPT_FORCE_SPACE, 43 ARGS_OPT_FORCE_POSTINSTALL, 44 ARGS_OPT_FORCE_REMOVE, 45 ARGS_OPT_FORCE_CHECKSUM, 46 ARGS_OPT_ADD_ARCH, 47 ARGS_OPT_ADD_DEST, 48 ARGS_OPT_NOACTION, 49 ARGS_OPT_DOWNLOAD_ONLY, 50 ARGS_OPT_NODEPS, 51 ARGS_OPT_NOCASE, 52 ARGS_OPT_AUTOREMOVE, 53 ARGS_OPT_CACHE, 54 ARGS_OPT_FORCE_SIGNATURE, 55 ARGS_OPT_NO_CHECK_CERTIFICATE, 56 ARGS_OPT_VERIFY_PROGRAM, 57 ARGS_OPT_SIZE, 58 ARGS_OPT_STRIP_ABI, 59 }; 60 61 static struct option long_options[] = { 62 {"query-all", 0, 0, 'A'}, 63 {"autoremove", 0, 0, ARGS_OPT_AUTOREMOVE}, 64 {"cache", 1, 0, ARGS_OPT_CACHE}, 65 {"conf-file", 1, 0, 'f'}, 66 {"conf", 1, 0, 'f'}, 67 {"dest", 1, 0, 'd'}, 68 {"force-maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 69 {"force_maintainer", 0, 0, ARGS_OPT_FORCE_MAINTAINER}, 70 {"force-depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, 71 {"force_depends", 0, 0, ARGS_OPT_FORCE_DEPENDS}, 72 {"force-overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, 73 {"force_overwrite", 0, 0, ARGS_OPT_FORCE_OVERWRITE}, 74 {"force_downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, 75 {"force-downgrade", 0, 0, ARGS_OPT_FORCE_DOWNGRADE}, 76 {"force-reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, 77 {"force_reinstall", 0, 0, ARGS_OPT_FORCE_REINSTALL}, 78 {"force-space", 0, 0, ARGS_OPT_FORCE_SPACE}, 79 {"force_space", 0, 0, ARGS_OPT_FORCE_SPACE}, 80 {"recursive", 0, 0, 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_dependent_packages", 0, 0, 84 ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES}, 85 {"force-removal-of-essential-packages", 0, 0, 86 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, 87 {"force_removal_of_essential_packages", 0, 0, 88 ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES}, 89 {"force-postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL}, 90 {"force_postinstall", 0, 0, ARGS_OPT_FORCE_POSTINSTALL}, 91 {"force-remove", 0, 0, ARGS_OPT_FORCE_REMOVE}, 92 {"force_remove", 0, 0, ARGS_OPT_FORCE_REMOVE}, 93 {"force-checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM}, 94 {"force_checksum", 0, 0, ARGS_OPT_FORCE_CHECKSUM}, 95 {"force-signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE}, 96 {"force_signature", 0, 0, ARGS_OPT_FORCE_SIGNATURE}, 97 {"no-check-certificate", 0, 0, ARGS_OPT_NO_CHECK_CERTIFICATE}, 98 {"no_check_certificate", 0, 0, ARGS_OPT_NO_CHECK_CERTIFICATE}, 99 {"noaction", 0, 0, ARGS_OPT_NOACTION}, 100 {"download-only", 0, 0, ARGS_OPT_DOWNLOAD_ONLY}, 101 {"nodeps", 0, 0, ARGS_OPT_NODEPS}, 102 {"nocase", 0, 0, ARGS_OPT_NOCASE}, 103 {"offline", 1, 0, 'o'}, 104 {"offline-root", 1, 0, 'o'}, 105 {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH}, 106 {"add-dest", 1, 0, ARGS_OPT_ADD_DEST}, 107 {"size", 0, 0, ARGS_OPT_SIZE}, 108 {"strip-abi", 0, 0, ARGS_OPT_STRIP_ABI}, 109 {"strip_abi", 0, 0, ARGS_OPT_STRIP_ABI}, 110 {"test", 0, 0, ARGS_OPT_NOACTION}, 111 {"tmp-dir", 1, 0, 't'}, 112 {"tmp_dir", 1, 0, 't'}, 113 {"lists-dir", 1, 0, 'l'}, 114 {"lists_dir", 1, 0, 'l'}, 115 {"verbosity", 2, 0, 'V'}, 116 {"verify-program", 1, 0, ARGS_OPT_VERIFY_PROGRAM}, 117 {"verify_program", 1, 0, ARGS_OPT_VERIFY_PROGRAM}, 118 {"version", 0, 0, 'v'}, 119 {0, 0, 0, 0} 120 }; 121 122 static int args_parse(int argc, char *argv[]) 123 { 124 int c; 125 int option_index = 0; 126 int parse_err = 0; 127 char *tuple, *targ; 128 129 while (1) { 130 c = getopt_long_only(argc, argv, "Ad:f:ino:p:l:t:vV::", 131 long_options, &option_index); 132 if (c == -1) 133 break; 134 135 switch (c) { 136 case 'A': 137 conf->query_all = 1; 138 break; 139 case 'd': 140 conf->dest_str = xstrdup(optarg); 141 break; 142 case 'f': 143 conf->conf_file = xstrdup(optarg); 144 break; 145 case 'i': 146 conf->nocase = FNM_CASEFOLD; 147 break; 148 case 'o': 149 conf->offline_root = xstrdup(optarg); 150 break; 151 case 't': 152 conf->tmp_dir = xstrdup(optarg); 153 break; 154 case 'l': 155 conf->lists_dir = xstrdup(optarg); 156 break; 157 case 'v': 158 printf("opkg version %s\n", VERSION); 159 exit(0); 160 case 'V': 161 conf->verbosity = INFO; 162 if (optarg != NULL) 163 conf->verbosity = atoi(optarg); 164 break; 165 case ARGS_OPT_AUTOREMOVE: 166 conf->autoremove = 1; 167 break; 168 case ARGS_OPT_CACHE: 169 free(conf->cache); 170 conf->cache = xstrdup(optarg); 171 break; 172 case ARGS_OPT_FORCE_MAINTAINER: 173 conf->force_maintainer = 1; 174 break; 175 case ARGS_OPT_FORCE_DEPENDS: 176 conf->force_depends = 1; 177 break; 178 case ARGS_OPT_FORCE_OVERWRITE: 179 conf->force_overwrite = 1; 180 break; 181 case ARGS_OPT_FORCE_DOWNGRADE: 182 conf->force_downgrade = 1; 183 break; 184 case ARGS_OPT_FORCE_REINSTALL: 185 conf->force_reinstall = 1; 186 break; 187 case ARGS_OPT_FORCE_REMOVAL_OF_ESSENTIAL_PACKAGES: 188 conf->force_removal_of_essential_packages = 1; 189 break; 190 case ARGS_OPT_FORCE_REMOVAL_OF_DEPENDENT_PACKAGES: 191 conf->force_removal_of_dependent_packages = 1; 192 break; 193 case ARGS_OPT_FORCE_SPACE: 194 conf->force_space = 1; 195 break; 196 case ARGS_OPT_FORCE_POSTINSTALL: 197 conf->force_postinstall = 1; 198 break; 199 case ARGS_OPT_FORCE_REMOVE: 200 conf->force_remove = 1; 201 break; 202 case ARGS_OPT_FORCE_CHECKSUM: 203 conf->force_checksum = 1; 204 break; 205 case ARGS_OPT_NODEPS: 206 conf->nodeps = 1; 207 break; 208 case ARGS_OPT_NOCASE: 209 conf->nocase = FNM_CASEFOLD; 210 break; 211 case ARGS_OPT_ADD_ARCH: 212 case ARGS_OPT_ADD_DEST: 213 tuple = xstrdup(optarg); 214 if ((targ = strchr(tuple, ':')) != NULL) { 215 *targ++ = 0; 216 if ((strlen(tuple) > 0) && (strlen(targ) > 0)) { 217 nv_pair_list_append((c == 218 ARGS_OPT_ADD_ARCH) 219 ? &conf->arch_list : 220 &conf->tmp_dest_list, 221 tuple, targ); 222 } 223 } 224 free(tuple); 225 break; 226 case ARGS_OPT_SIZE: 227 conf->size = 1; 228 break; 229 case ARGS_OPT_NOACTION: 230 conf->noaction = 1; 231 break; 232 case ARGS_OPT_DOWNLOAD_ONLY: 233 conf->download_only = 1; 234 break; 235 case ARGS_OPT_FORCE_SIGNATURE: 236 conf->force_signature = 1; 237 break; 238 case ARGS_OPT_NO_CHECK_CERTIFICATE: 239 conf->no_check_certificate = 1; 240 break; 241 case ARGS_OPT_VERIFY_PROGRAM: 242 conf->verify_program = xstrdup(optarg); 243 break; 244 case ARGS_OPT_STRIP_ABI: 245 conf->strip_abi = 1; 246 break; 247 case ':': 248 parse_err = -1; 249 break; 250 case '?': 251 parse_err = -1; 252 break; 253 default: 254 printf("Confusion: getopt_long returned %d\n", c); 255 } 256 } 257 258 if (!conf->conf_file && !conf->offline_root) 259 conf->conf_file = xstrdup("/etc/opkg.conf"); 260 261 if (parse_err) 262 return parse_err; 263 else 264 return optind; 265 } 266 267 static void usage() 268 { 269 printf("usage: opkg [options...] sub-command [arguments...]\n"); 270 printf("where sub-command is one of:\n"); 271 272 printf("\nPackage Manipulation:\n"); 273 printf 274 ("\tupdate Update list of available packages\n"); 275 printf("\tupgrade <pkgs> Upgrade packages\n"); 276 printf("\tinstall <pkgs> Install package(s)\n"); 277 printf("\tconfigure <pkgs> Configure unpacked package(s)\n"); 278 printf("\tremove <pkgs|regexp> Remove package(s)\n"); 279 printf("\tflag <flag> <pkgs> Flag package(s)\n"); 280 printf 281 ("\t <flag>=hold|noprune|user|ok|installed|unpacked (one per invocation)\n"); 282 283 printf("\nInformational Commands:\n"); 284 printf("\tlist List available packages\n"); 285 printf("\tlist-installed List installed packages\n"); 286 printf 287 ("\tlist-upgradable List installed and upgradable packages\n"); 288 printf 289 ("\tlist-changed-conffiles List user modified configuration files\n"); 290 printf("\tfiles <pkg> List files belonging to <pkg>\n"); 291 printf("\tsearch <file|regexp> List package providing <file>\n"); 292 printf 293 ("\tfind <regexp> List packages whose name or description matches <regexp>\n"); 294 printf("\tinfo [pkg|regexp] Display all info for <pkg>\n"); 295 printf("\tstatus [pkg|regexp] Display all status for <pkg>\n"); 296 printf 297 ("\tdownload <pkg> Download <pkg> to current directory\n"); 298 printf("\tcompare-versions <v1> <op> <v2>\n"); 299 printf 300 ("\t compare versions using <= < > >= = << >>\n"); 301 printf 302 ("\tprint-architecture List installable package architectures\n"); 303 printf("\tdepends [-A] [pkgname|pat]+\n"); 304 printf("\twhatdepends [-A] [pkgname|pat]+\n"); 305 printf("\twhatdependsrec [-A] [pkgname|pat]+\n"); 306 printf("\twhatrecommends[-A] [pkgname|pat]+\n"); 307 printf("\twhatsuggests[-A] [pkgname|pat]+\n"); 308 printf("\twhatprovides [-A] [pkgname|pat]+\n"); 309 printf("\twhatconflicts [-A] [pkgname|pat]+\n"); 310 printf("\twhatreplaces [-A] [pkgname|pat]+\n"); 311 312 printf("\nOptions:\n"); 313 printf 314 ("\t-A Query all packages not just those installed\n"); 315 printf("\t-V[<level>] Set verbosity level to <level>.\n"); 316 printf("\t--verbosity[=<level>] Verbosity levels:\n"); 317 printf("\t 0 errors only\n"); 318 printf("\t 1 normal messages (default)\n"); 319 printf("\t 2 informative messages\n"); 320 printf("\t 3 debug\n"); 321 printf("\t 4 debug level 2\n"); 322 printf 323 ("\t-f <conf_file> Use <conf_file> as the opkg configuration file\n"); 324 printf("\t--conf <conf_file>\n"); 325 printf("\t--cache <directory> Use a package cache\n"); 326 printf 327 ("\t-d <dest_name> Use <dest_name> as the the root directory for\n"); 328 printf 329 ("\t--dest <dest_name> package installation, removal, upgrading.\n"); 330 printf 331 (" <dest_name> should be a defined dest name from\n"); 332 printf 333 (" the configuration file, (but can also be a\n"); 334 printf(" directory name in a pinch).\n"); 335 printf("\t-o <dir> Use <dir> as the root directory for\n"); 336 printf("\t--offline-root <dir> offline installation of packages.\n"); 337 printf 338 ("\t--verify-program <path> Use the given program to verify usign signatures\n"); 339 printf 340 ("\t--add-arch <arch>:<prio> Register architecture with given priority\n"); 341 printf 342 ("\t--add-dest <name>:<path> Register destination with given path\n"); 343 344 printf("\nForce Options:\n"); 345 printf 346 ("\t--force-depends Install/remove despite failed dependencies\n"); 347 printf("\t--force-maintainer Overwrite preexisting config files\n"); 348 printf("\t--force-reinstall Reinstall package(s)\n"); 349 printf 350 ("\t--force-overwrite Overwrite files from other package(s)\n"); 351 printf("\t--force-downgrade Allow opkg to downgrade packages\n"); 352 printf("\t--force-space Disable free space checks\n"); 353 printf 354 ("\t--force-postinstall Run postinstall scripts even in offline mode\n"); 355 printf 356 ("\t--force-remove Remove package even if prerm script fails\n"); 357 printf("\t--force-checksum Don't fail on checksum mismatches\n"); 358 printf("\t--no-check-certificate Don't validate SSL certificates\n"); 359 printf("\t--noaction No action -- test only\n"); 360 printf("\t--download-only No action -- download only\n"); 361 printf("\t--nodeps Do not follow dependencies\n"); 362 printf 363 ("\t--nocase Perform case insensitive pattern matching\n"); 364 printf 365 ("\t--size Print package size when listing available packages\n"); 366 printf 367 ("\t--strip-abi Print package name without appended ABI version\n"); 368 printf("\t--force-removal-of-dependent-packages\n"); 369 printf("\t Remove package and all dependencies\n"); 370 printf("\t--autoremove Remove packages that were installed\n"); 371 printf 372 ("\t automatically to satisfy dependencies\n"); 373 printf("\t-t Specify tmp-dir.\n"); 374 printf("\t--tmp-dir Specify tmp-dir.\n"); 375 printf("\t-l Specify lists-dir.\n"); 376 printf("\t--lists-dir Specify lists-dir.\n"); 377 378 printf("\n"); 379 380 printf 381 (" regexp could be something like 'pkgname*' '*file*' or similar\n"); 382 printf 383 (" e.g. opkg info 'libstd*' or opkg search '*libop*' or opkg remove 'libncur*'\n"); 384 385 /* --force-removal-of-essential-packages Let opkg remove essential packages. 386 Using this option is almost guaranteed to break your system, hence this option 387 is not even advertised in the usage statement. */ 388 389 exit(1); 390 } 391 392 int main(int argc, char *argv[]) 393 { 394 int opts, err = -1; 395 char *cmd_name; 396 opkg_cmd_t *cmd; 397 int nocheckfordirorfile = 0; 398 int noreadfeedsfile = 0; 399 400 if (opkg_conf_init()) 401 goto err0; 402 403 conf->verbosity = NOTICE; 404 405 opts = args_parse(argc, argv); 406 if (opts == argc || opts < 0) { 407 fprintf(stderr, "opkg must have one sub-command argument\n"); 408 usage(); 409 } 410 411 cmd_name = argv[opts++]; 412 413 if (!strcmp(cmd_name, "install") || 414 !strcmp(cmd_name, "print-architecture") || 415 !strcmp(cmd_name, "print_architecture") || 416 !strcmp(cmd_name, "print-installation-architecture") || 417 !strcmp(cmd_name, "print_installation_architecture") || 418 !strcmp(cmd_name, "compare_versions") || 419 !strcmp(cmd_name, "compare-versions")) 420 nocheckfordirorfile = 1; 421 422 if (!strcmp(cmd_name, "flag") || 423 !strcmp(cmd_name, "configure") || 424 !strcmp(cmd_name, "install") || 425 !strcmp(cmd_name, "remove") || 426 !strcmp(cmd_name, "files") || 427 !strcmp(cmd_name, "search") || 428 !strcmp(cmd_name, "list") || 429 !strcmp(cmd_name, "list_installed") || 430 !strcmp(cmd_name, "list-installed") || 431 !strcmp(cmd_name, "list_changed_conffiles") || 432 !strcmp(cmd_name, "list-changed-conffiles") || 433 !strcmp(cmd_name, "status") || 434 !strcmp(cmd_name, "update")) 435 noreadfeedsfile = 1; 436 437 cmd = opkg_cmd_find(cmd_name); 438 if (cmd == NULL) { 439 fprintf(stderr, "%s: unknown sub-command %s\n", argv[0], 440 cmd_name); 441 usage(); 442 } 443 444 conf->pfm = cmd->pfm; 445 446 if (opkg_conf_load()) 447 goto err0; 448 449 if (!nocheckfordirorfile) { 450 if (!noreadfeedsfile) { 451 if (pkg_hash_load_feeds(SF_NEED_DETAIL, NULL, NULL)) 452 goto err1; 453 } 454 455 if (pkg_hash_load_status_files(NULL, NULL)) 456 goto err1; 457 } 458 459 if (cmd->requires_args && opts == argc) { 460 fprintf(stderr, 461 "%s: the ``%s'' command requires at least one argument\n", 462 argv[0], cmd_name); 463 usage(); 464 } 465 466 err = opkg_cmd_exec(cmd, argc - opts, (const char **)(argv + opts)); 467 468 err1: 469 opkg_conf_deinit(); 470 471 err0: 472 print_error_list(); 473 free_error_list(); 474 475 return err; 476 } 477
This page was automatically generated by LXR 0.3.1. • OpenWrt