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.
23 #include "opkg_conf.h"
25 #include "file_util.h"
29 opkg_message_callback opkg_cb_message = NULL;
30 opkg_response_callback opkg_cb_response = NULL;
31 opkg_status_callback opkg_cb_status = NULL;
32 opkg_list_callback opkg_cb_list = NULL;
36 opkg_init (opkg_message_callback mcall,
37 opkg_response_callback rcall,
40 opkg_cb_message = mcall;
41 opkg_cb_response = rcall;
50 opkg_deinit (args_t * args)
53 opkg_cb_message = NULL;
54 opkg_cb_response = NULL;
56 /* place other cleanup stuff here */
63 opkg_packages_list(args_t *args,
65 opkg_list_callback cblist,
69 opkg_conf_t opkg_conf;
72 err = opkg_conf_init (&opkg_conf, args);
78 opkg_cb_list = cblist;
79 /* we need to do this because of static declarations,
80 * maybe a good idea to change */
81 cmd = opkg_cmd_find ("list");
83 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
85 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
87 opkg_conf_deinit (&opkg_conf);
93 opkg_packages_status(args_t *args,
95 opkg_status_callback cbstatus,
99 opkg_conf_t opkg_conf;
102 err = opkg_conf_init (&opkg_conf, args);
108 opkg_cb_status = cbstatus;
110 /* we need to do this because of static declarations,
111 * maybe a good idea to change */
112 cmd = opkg_cmd_find ("status");
114 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
116 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
118 opkg_cb_status = NULL;
119 opkg_conf_deinit (&opkg_conf);
125 opkg_packages_info(args_t *args,
126 const char *packages,
127 opkg_status_callback cbstatus,
131 opkg_conf_t opkg_conf;
134 err = opkg_conf_init (&opkg_conf, args);
140 opkg_cb_status = cbstatus;
142 /* we need to do this because of static declarations,
143 * maybe a good idea to change */
144 cmd = opkg_cmd_find ("info");
146 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &packages, userdata);
148 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, userdata);
150 opkg_cb_status = NULL;
151 opkg_conf_deinit (&opkg_conf);
157 opkg_packages_install (args_t * args, const char *name)
160 opkg_conf_t opkg_conf;
163 /* this error should be handled in application */
164 if (!name || !strlen (name))
167 err = opkg_conf_init (&opkg_conf, args);
173 /* we need to do this because of static declarations,
174 * maybe a good idea to change */
175 cmd = opkg_cmd_find ("install");
176 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
178 opkg_conf_deinit(&opkg_conf);
184 opkg_packages_remove(args_t *args, const char *name, int purge)
187 opkg_conf_t opkg_conf;
190 /* this error should be handled in application */
191 if (!name || !strlen (name))
194 err = opkg_conf_init (&opkg_conf, args);
200 /* we need to do this because of static declarations,
201 * maybe a good idea to change */
203 cmd = opkg_cmd_find ("purge");
205 cmd = opkg_cmd_find ("remove");
207 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
209 opkg_conf_deinit(&opkg_conf);
215 opkg_lists_update(args_t *args)
218 opkg_conf_t opkg_conf;
221 err = opkg_conf_init (&opkg_conf, args);
227 /* we need to do this because of static declarations,
228 * maybe a good idea to change */
229 cmd = opkg_cmd_find ("update");
231 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, NULL);
233 opkg_conf_deinit(&opkg_conf);
239 opkg_packages_upgrade(args_t *args)
242 opkg_conf_t opkg_conf;
245 err = opkg_conf_init (&opkg_conf, args);
251 /* we need to do this because of static declarations,
252 * maybe a good idea to change */
253 cmd = opkg_cmd_find ("upgrade");
255 err = opkg_cmd_exec (cmd, &opkg_conf, 0, NULL, NULL);
257 opkg_conf_deinit(&opkg_conf);
263 opkg_packages_download (args_t * args, const char *name)
266 opkg_conf_t opkg_conf;
269 /* this error should be handled in application */
270 if (!name || !strlen (name))
273 err = opkg_conf_init (&opkg_conf, args);
279 /* we need to do this because of static declarations,
280 * maybe a good idea to change */
281 cmd = opkg_cmd_find ("download");
282 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, NULL);
284 opkg_conf_deinit(&opkg_conf);
290 opkg_package_files(args_t *args,
292 opkg_list_callback cblist,
296 opkg_conf_t opkg_conf;
299 /* this error should be handled in application */
300 if (!name || !strlen (name))
303 err = opkg_conf_init (&opkg_conf, args);
309 opkg_cb_list = cblist;
311 /* we need to do this because of static declarations,
312 * maybe a good idea to change */
313 cmd = opkg_cmd_find ("files");
315 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &name, userdata);
318 opkg_conf_deinit(&opkg_conf);
324 opkg_file_search(args_t *args,
326 opkg_list_callback cblist,
330 opkg_conf_t opkg_conf;
333 /* this error should be handled in application */
334 if (!file || !strlen (file))
337 err = opkg_conf_init (&opkg_conf, args);
343 opkg_cb_list = cblist;
345 /* we need to do this because of static declarations,
346 * maybe a good idea to change */
347 cmd = opkg_cmd_find ("search");
348 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &file, userdata);
351 opkg_conf_deinit(&opkg_conf);
357 opkg_file_what(args_t *args, const char *file, const char* command)
360 opkg_conf_t opkg_conf;
363 /* this error should be handled in application */
364 if (!file || !strlen (file))
367 err = opkg_conf_init (&opkg_conf, args);
373 /* we need to do this because of static declarations,
374 * maybe a good idea to change */
375 cmd = opkg_cmd_find (command);
376 err = opkg_cmd_exec (cmd, &opkg_conf, 1, &file, NULL);
378 opkg_conf_deinit(&opkg_conf);
382 #define opkg_package_whatdepends(args,file) opkg_file_what(args,file,"whatdepends")
383 #define opkg_package_whatrecommends(args, file) opkg_file_what(args,file,"whatrecommends")
384 #define opkg_package_whatprovides(args, file) opkg_file_what(args,file,"whatprovides")
385 #define opkg_package_whatconflicts(args, file) opkg_file_what(args,file,"whatconflicts")
386 #define opkg_package_whatreplaces(args, file) opkg_file_what(args,file,"whatreplaces")
389 int default_opkg_message_callback(opkg_conf_t *conf, message_level_t level,
392 if (conf && (conf->verbosity < level)) {
395 if ( level == OPKG_ERROR ){
396 push_error_list(&error_list, msg);
403 int default_opkg_list_callback(char *name, char *desc, char *version,
404 pkg_state_status_t status, void *userdata)
407 printf("%s - %s - %s\n", name, version, desc);
409 printf("%s - %s\n", name, version);
413 int default_opkg_files_callback(char *name, char *desc, char *version,
414 pkg_state_status_t status, void *userdata)
417 printf("%s\n", desc);
421 int default_opkg_status_callback(char *name, int istatus, char *desc,
424 printf("%s\n", desc);
428 char* default_opkg_response_callback(char *question)
430 char *response = NULL;
434 response = (char *)file_read_line_alloc(stdin);
435 } while (response == NULL);
439 /* This is used for backward compatibility */
441 opkg_op (int argc, char *argv[])
447 opkg_conf_t opkg_conf;
451 optind = args_parse (&args, argc, argv);
452 if (optind == argc || optind < 0)
454 args_usage ("opkg must have one sub-command argument");
457 cmd_name = argv[optind++];
458 /* Pigi: added a flag to disable the checking of structures if the command does not need to
459 read anything from there.
461 if ( !strcmp(cmd_name,"print-architecture") ||
462 !strcmp(cmd_name,"print_architecture") ||
463 !strcmp(cmd_name,"print-installation-architecture") ||
464 !strcmp(cmd_name,"print_installation_architecture") )
465 args.nocheckfordirorfile = 1;
467 /* Pigi: added a flag to disable the reading of feed files if the command does not need to
468 read anything from there.
470 if ( !strcmp(cmd_name,"flag") ||
471 !strcmp(cmd_name,"configure") ||
472 !strcmp(cmd_name,"remove") ||
473 !strcmp(cmd_name,"files") ||
474 !strcmp(cmd_name,"search") ||
475 !strcmp(cmd_name,"compare_versions") ||
476 !strcmp(cmd_name,"compare-versions") ||
477 !strcmp(cmd_name,"list_installed") ||
478 !strcmp(cmd_name,"list-installed") ||
479 !strcmp(cmd_name,"status") )
480 args.noreadfeedsfile = 1;
483 err = opkg_conf_init (&opkg_conf, &args);
491 opkg_cb_message = default_opkg_message_callback;
492 opkg_cb_response = default_opkg_response_callback;
493 opkg_cb_status = default_opkg_status_callback;
494 if ( strcmp(cmd_name, "files")==0)
495 opkg_cb_list = default_opkg_files_callback;
497 opkg_cb_list = default_opkg_list_callback;
499 cmd = opkg_cmd_find (cmd_name);
502 fprintf (stderr, "%s: unknown sub-command %s\n", argv[0],
507 if (cmd->requires_args && optind == argc)
510 "%s: the ``%s'' command requires at least one argument\n",
511 __FUNCTION__, cmd_name);
515 err = opkg_cmd_exec (cmd, &opkg_conf, argc - optind, (const char **) (argv + optind), NULL);
517 opkg_conf_deinit (&opkg_conf);