1 /* opkglib.c - the itsy package management system
5 Copyright (C) 2003 kernel concepts
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
25 #include "opkg_conf.h"
27 #include "file_util.h"
31 opkg_message_callback opkg_cb_message = NULL;
32 opkg_response_callback opkg_cb_response = NULL;
33 opkg_status_callback opkg_cb_status = NULL;
34 opkg_list_callback opkg_cb_list = NULL;
38 opkg_init (opkg_message_callback mcall,
39 opkg_response_callback rcall,
42 opkg_cb_message = mcall;
43 opkg_cb_response = rcall;
52 opkg_deinit (args_t * args)
55 opkg_cb_message = NULL;
56 opkg_cb_response = NULL;
58 /* place other cleanup stuff here */
65 opkg_packages_list(args_t *args,
67 opkg_list_callback cblist,
71 opkg_conf_t opkg_conf;
74 err = opkg_conf_init (&opkg_conf, args);
80 opkg_cb_list = cblist;
81 /* we need to do this because of static declarations,
82 * maybe a good idea to change */
83 cmd = opkg_cmd_find ("list");
85 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
87 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
89 opkg_conf_deinit (&opkg_conf);
95 opkg_packages_status(args_t *args,
97 opkg_status_callback cbstatus,
101 opkg_conf_t opkg_conf;
104 err = opkg_conf_init (&opkg_conf, args);
110 opkg_cb_status = cbstatus;
112 /* we need to do this because of static declarations,
113 * maybe a good idea to change */
114 cmd = opkg_cmd_find ("status");
116 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
118 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
120 opkg_cb_status = NULL;
121 opkg_conf_deinit (&opkg_conf);
127 opkg_packages_info(args_t *args,
128 const char *packages,
129 opkg_status_callback cbstatus,
133 opkg_conf_t opkg_conf;
136 err = opkg_conf_init (&opkg_conf, args);
142 opkg_cb_status = cbstatus;
144 /* we need to do this because of static declarations,
145 * maybe a good idea to change */
146 cmd = opkg_cmd_find ("info");
148 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
150 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
152 opkg_cb_status = NULL;
153 opkg_conf_deinit (&opkg_conf);
159 opkg_packages_install (args_t * args, const char *name)
162 opkg_conf_t opkg_conf;
165 /* this error should be handled in application */
166 if (!name || !strlen (name))
169 err = opkg_conf_init (&opkg_conf, args);
175 /* we need to do this because of static declarations,
176 * maybe a good idea to change */
177 cmd = opkg_cmd_find ("install");
178 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
180 opkg_conf_deinit(&opkg_conf);
186 opkg_packages_remove(args_t *args, const char *name, int purge)
189 opkg_conf_t opkg_conf;
192 /* this error should be handled in application */
193 if (!name || !strlen (name))
196 err = opkg_conf_init (&opkg_conf, args);
202 /* we need to do this because of static declarations,
203 * maybe a good idea to change */
205 cmd = opkg_cmd_find ("purge");
207 cmd = opkg_cmd_find ("remove");
209 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
211 opkg_conf_deinit(&opkg_conf);
217 opkg_lists_update(args_t *args)
220 opkg_conf_t opkg_conf;
223 err = opkg_conf_init (&opkg_conf, args);
229 /* we need to do this because of static declarations,
230 * maybe a good idea to change */
231 cmd = opkg_cmd_find ("update");
233 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, NULL);
235 opkg_conf_deinit(&opkg_conf);
241 opkg_packages_upgrade(args_t *args)
244 opkg_conf_t opkg_conf;
247 err = opkg_conf_init (&opkg_conf, args);
253 /* we need to do this because of static declarations,
254 * maybe a good idea to change */
255 cmd = opkg_cmd_find ("upgrade");
257 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, NULL);
259 opkg_conf_deinit(&opkg_conf);
265 opkg_packages_download (args_t * args, const char *name)
268 opkg_conf_t opkg_conf;
271 /* this error should be handled in application */
272 if (!name || !strlen (name))
275 err = opkg_conf_init (&opkg_conf, args);
281 /* we need to do this because of static declarations,
282 * maybe a good idea to change */
283 cmd = opkg_cmd_find ("download");
284 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
286 opkg_conf_deinit(&opkg_conf);
292 opkg_package_files(args_t *args,
294 opkg_list_callback cblist,
298 opkg_conf_t opkg_conf;
301 /* this error should be handled in application */
302 if (!name || !strlen (name))
305 err = opkg_conf_init (&opkg_conf, args);
311 opkg_cb_list = cblist;
313 /* we need to do this because of static declarations,
314 * maybe a good idea to change */
315 cmd = opkg_cmd_find ("files");
317 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, userdata);
320 opkg_conf_deinit(&opkg_conf);
326 opkg_file_search(args_t *args,
328 opkg_list_callback cblist,
332 opkg_conf_t opkg_conf;
335 /* this error should be handled in application */
336 if (!file || !strlen (file))
339 err = opkg_conf_init (&opkg_conf, args);
345 opkg_cb_list = cblist;
347 /* we need to do this because of static declarations,
348 * maybe a good idea to change */
349 cmd = opkg_cmd_find ("search");
350 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &file, userdata);
353 opkg_conf_deinit(&opkg_conf);
359 opkg_file_what(args_t *args, const char *file, const char* command)
362 opkg_conf_t opkg_conf;
365 /* this error should be handled in application */
366 if (!file || !strlen (file))
369 err = opkg_conf_init (&opkg_conf, args);
375 /* we need to do this because of static declarations,
376 * maybe a good idea to change */
377 cmd = opkg_cmd_find (command);
378 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &file, NULL);
380 opkg_conf_deinit(&opkg_conf);
384 #define opkg_package_whatdepends(args,file) opkg_file_what(args,file,"whatdepends")
385 #define opkg_package_whatrecommends(args, file) opkg_file_what(args,file,"whatrecommends")
386 #define opkg_package_whatprovides(args, file) opkg_file_what(args,file,"whatprovides")
387 #define opkg_package_whatconflicts(args, file) opkg_file_what(args,file,"whatconflicts")
388 #define opkg_package_whatreplaces(args, file) opkg_file_what(args,file,"whatreplaces")
391 int default_opkg_message_callback(opkg_conf_t *conf, message_level_t level,
394 if (conf && (conf->verbosity < level)) {
398 if ( level == OPKG_ERROR ){
399 push_error_list(&error_list, msg);
408 int default_opkg_list_callback(char *name, char *desc, char *version,
409 pkg_state_status_t status, void *userdata)
412 printf("%s - %s - %s\n", name, version, desc);
414 printf("%s - %s\n", name, version);
418 int default_opkg_files_callback(char *name, char *desc, char *version,
419 pkg_state_status_t status, void *userdata)
422 printf("%s\n", desc);
426 int default_opkg_status_callback(char *name, int istatus, char *desc,
429 printf("%s\n", desc);
433 char* default_opkg_response_callback(char *question)
435 char *response = NULL;
439 response = (char *)file_read_line_alloc(stdin);
440 } while (response == NULL);
444 /* This is used for backward compatibility */
446 opkg_op (int argc, char *argv[])
452 opkg_conf_t opkg_conf;
456 optind = args_parse (&args, argc, argv);
457 if (optind == argc || optind < 0)
459 args_usage ("opkg must have one sub-command argument");
462 cmd_name = argv[optind++];
463 /* Pigi: added a flag to disable the checking of structures if the command does not need to
464 read anything from there.
466 if ( !strcmp(cmd_name,"print-architecture") ||
467 !strcmp(cmd_name,"print_architecture") ||
468 !strcmp(cmd_name,"print-installation-architecture") ||
469 !strcmp(cmd_name,"print_installation_architecture") )
470 args.nocheckfordirorfile = 1;
472 /* Pigi: added a flag to disable the reading of feed files if the command does not need to
473 read anything from there.
475 if ( !strcmp(cmd_name,"flag") ||
476 !strcmp(cmd_name,"configure") ||
477 !strcmp(cmd_name,"remove") ||
478 !strcmp(cmd_name,"files") ||
479 !strcmp(cmd_name,"search") ||
480 !strcmp(cmd_name,"compare_versions") ||
481 !strcmp(cmd_name,"compare-versions") ||
482 !strcmp(cmd_name,"list_installed") ||
483 !strcmp(cmd_name,"list-installed") ||
484 !strcmp(cmd_name,"status") )
485 args.noreadfeedsfile = 1;
488 err = opkg_conf_init (&opkg_conf, &args);
496 opkg_cb_message = default_opkg_message_callback;
497 opkg_cb_response = default_opkg_response_callback;
498 opkg_cb_status = default_opkg_status_callback;
499 if ( strcmp(cmd_name, "files")==0)
500 opkg_cb_list = default_opkg_files_callback;
502 opkg_cb_list = default_opkg_list_callback;
504 cmd = opkg_cmd_find (cmd_name);
507 fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
512 if (cmd->requires_args && optind == argc)
515 "%s: the ``%s'' command requires at least one argument\n",
516 __FUNCTION__, cmd_name);
520 err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL);
522 opkg_conf_deinit (&opkg_conf);
527 #endif /* OPKG_LIB */