1 /* opkglib.c - the opkg 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.
22 #include "opkg_conf.h"
24 #include "file_util.h"
26 #include "opkg_message.h"
27 #include "opkg_error.h"
29 opkg_status_callback opkg_cb_status
= NULL
;
30 opkg_list_callback opkg_cb_list
= NULL
;
34 opkg_init (opkg_message_callback mcall
,
35 opkg_response_callback rcall
,
38 opkg_cb_message
= mcall
;
39 opkg_cb_response
= rcall
;
48 opkg_deinit (args_t
* args
)
51 opkg_cb_message
= NULL
;
52 opkg_cb_response
= NULL
;
54 /* place other cleanup stuff here */
61 opkg_packages_list(args_t
*args
,
63 opkg_list_callback cblist
,
67 opkg_conf_t opkg_conf
;
70 err
= opkg_conf_init (&opkg_conf
, args
);
76 opkg_cb_list
= cblist
;
77 /* we need to do this because of static declarations,
78 * maybe a good idea to change */
79 cmd
= opkg_cmd_find ("list");
81 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &packages
, userdata
);
83 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 0, NULL
, userdata
);
85 opkg_conf_deinit (&opkg_conf
);
91 opkg_packages_status(args_t
*args
,
93 opkg_status_callback cbstatus
,
97 opkg_conf_t opkg_conf
;
100 err
= opkg_conf_init (&opkg_conf
, args
);
106 opkg_cb_status
= cbstatus
;
108 /* we need to do this because of static declarations,
109 * maybe a good idea to change */
110 cmd
= opkg_cmd_find ("status");
112 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &packages
, userdata
);
114 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 0, NULL
, userdata
);
116 opkg_cb_status
= NULL
;
117 opkg_conf_deinit (&opkg_conf
);
123 opkg_packages_info(args_t
*args
,
124 const char *packages
,
125 opkg_status_callback cbstatus
,
129 opkg_conf_t opkg_conf
;
132 err
= opkg_conf_init (&opkg_conf
, args
);
138 opkg_cb_status
= cbstatus
;
140 /* we need to do this because of static declarations,
141 * maybe a good idea to change */
142 cmd
= opkg_cmd_find ("info");
144 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &packages
, userdata
);
146 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 0, NULL
, userdata
);
148 opkg_cb_status
= NULL
;
149 opkg_conf_deinit (&opkg_conf
);
155 opkg_packages_install (args_t
* args
, const char *name
)
158 opkg_conf_t opkg_conf
;
161 /* this error should be handled in application */
162 if (!name
|| !strlen (name
))
165 err
= opkg_conf_init (&opkg_conf
, args
);
171 /* we need to do this because of static declarations,
172 * maybe a good idea to change */
173 cmd
= opkg_cmd_find ("install");
174 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &name
, NULL
);
176 opkg_conf_deinit(&opkg_conf
);
182 opkg_packages_remove(args_t
*args
, const char *name
, int purge
)
185 opkg_conf_t opkg_conf
;
188 /* this error should be handled in application */
189 if (!name
|| !strlen (name
))
192 err
= opkg_conf_init (&opkg_conf
, args
);
198 /* we need to do this because of static declarations,
199 * maybe a good idea to change */
201 cmd
= opkg_cmd_find ("purge");
203 cmd
= opkg_cmd_find ("remove");
205 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &name
, NULL
);
207 opkg_conf_deinit(&opkg_conf
);
213 opkg_lists_update(args_t
*args
)
216 opkg_conf_t opkg_conf
;
219 err
= opkg_conf_init (&opkg_conf
, args
);
225 /* we need to do this because of static declarations,
226 * maybe a good idea to change */
227 cmd
= opkg_cmd_find ("update");
229 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 0, NULL
, NULL
);
231 opkg_conf_deinit(&opkg_conf
);
237 opkg_packages_upgrade(args_t
*args
)
240 opkg_conf_t opkg_conf
;
243 err
= opkg_conf_init (&opkg_conf
, args
);
249 /* we need to do this because of static declarations,
250 * maybe a good idea to change */
251 cmd
= opkg_cmd_find ("upgrade");
253 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 0, NULL
, NULL
);
255 opkg_conf_deinit(&opkg_conf
);
261 opkg_packages_download (args_t
* args
, const char *name
)
264 opkg_conf_t opkg_conf
;
267 /* this error should be handled in application */
268 if (!name
|| !strlen (name
))
271 err
= opkg_conf_init (&opkg_conf
, args
);
274 opkg_print_error_list (&opkg_conf
);
278 /* we need to do this because of static declarations,
279 * maybe a good idea to change */
280 cmd
= opkg_cmd_find ("download");
281 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &name
, NULL
);
283 opkg_conf_deinit(&opkg_conf
);
289 opkg_package_files(args_t
*args
,
291 opkg_list_callback cblist
,
295 opkg_conf_t opkg_conf
;
298 /* this error should be handled in application */
299 if (!name
|| !strlen (name
))
302 err
= opkg_conf_init (&opkg_conf
, args
);
308 opkg_cb_list
= cblist
;
310 /* we need to do this because of static declarations,
311 * maybe a good idea to change */
312 cmd
= opkg_cmd_find ("files");
314 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &name
, userdata
);
317 opkg_conf_deinit(&opkg_conf
);
323 opkg_file_search(args_t
*args
,
325 opkg_list_callback cblist
,
329 opkg_conf_t opkg_conf
;
332 /* this error should be handled in application */
333 if (!file
|| !strlen (file
))
336 err
= opkg_conf_init (&opkg_conf
, args
);
342 opkg_cb_list
= cblist
;
344 /* we need to do this because of static declarations,
345 * maybe a good idea to change */
346 cmd
= opkg_cmd_find ("search");
347 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &file
, userdata
);
350 opkg_conf_deinit(&opkg_conf
);
356 opkg_file_what(args_t
*args
, const char *file
, const char* command
)
359 opkg_conf_t opkg_conf
;
362 /* this error should be handled in application */
363 if (!file
|| !strlen (file
))
366 err
= opkg_conf_init (&opkg_conf
, args
);
372 /* we need to do this because of static declarations,
373 * maybe a good idea to change */
374 cmd
= opkg_cmd_find (command
);
375 err
= opkg_cmd_exec (cmd
, &opkg_conf
, 1, &file
, NULL
);
377 opkg_conf_deinit(&opkg_conf
);
381 #define opkg_package_whatdepends(args,file) opkg_file_what(args,file,"whatdepends")
382 #define opkg_package_whatrecommends(args, file) opkg_file_what(args,file,"whatrecommends")
383 #define opkg_package_whatprovides(args, file) opkg_file_what(args,file,"whatprovides")
384 #define opkg_package_whatconflicts(args, file) opkg_file_what(args,file,"whatconflicts")
385 #define opkg_package_whatreplaces(args, file) opkg_file_what(args,file,"whatreplaces")
388 int default_opkg_message_callback(opkg_conf_t
*conf
, message_level_t level
,
391 if (conf
&& (conf
->verbosity
< level
)) {
394 if ( level
== OPKG_ERROR
){
395 push_error_list(&error_list
, msg
);
402 int default_opkg_list_callback(char *name
, char *desc
, char *version
,
403 pkg_state_status_t status
, void *userdata
)
406 printf("%s - %s - %s\n", name
, version
, desc
);
408 printf("%s - %s\n", name
, version
);
412 int default_opkg_files_callback(char *name
, char *desc
, char *version
,
413 pkg_state_status_t status
, void *userdata
)
416 printf("%s\n", desc
);
420 int default_opkg_status_callback(char *name
, int istatus
, char *desc
,
423 printf("%s\n", desc
);
427 char* default_opkg_response_callback(char *question
)
429 char *response
= NULL
;
433 response
= (char *)file_read_line_alloc(stdin
);
434 } while (response
== NULL
);
438 /* This is used for backward compatibility */
440 opkg_op (int argc
, char *argv
[])
446 opkg_conf_t opkg_conf
;
450 optind
= args_parse (&args
, argc
, argv
);
451 if (optind
== argc
|| optind
< 0)
453 args_usage ("opkg must have one sub-command argument");
456 cmd_name
= argv
[optind
++];
457 /* Pigi: added a flag to disable the checking of structures if the command does not need to
458 read anything from there.
460 if ( !strcmp(cmd_name
,"print-architecture") ||
461 !strcmp(cmd_name
,"print_architecture") ||
462 !strcmp(cmd_name
,"print-installation-architecture") ||
463 !strcmp(cmd_name
,"print_installation_architecture") )
464 args
.nocheckfordirorfile
= 1;
466 /* Pigi: added a flag to disable the reading of feed files if the command does not need to
467 read anything from there.
469 if ( !strcmp(cmd_name
,"flag") ||
470 !strcmp(cmd_name
,"configure") ||
471 !strcmp(cmd_name
,"remove") ||
472 !strcmp(cmd_name
,"files") ||
473 !strcmp(cmd_name
,"search") ||
474 !strcmp(cmd_name
,"compare_versions") ||
475 !strcmp(cmd_name
,"compare-versions") ||
476 !strcmp(cmd_name
,"list_installed") ||
477 !strcmp(cmd_name
,"list-installed") ||
478 !strcmp(cmd_name
,"status") )
479 args
.noreadfeedsfile
= 1;
481 opkg_cb_message
= default_opkg_message_callback
;
482 opkg_cb_response
= default_opkg_response_callback
;
483 opkg_cb_status
= default_opkg_status_callback
;
486 err
= opkg_conf_init (&opkg_conf
, &args
);
489 opkg_print_error_list (&opkg_conf
);
495 if ( strcmp(cmd_name
, "files")==0)
496 opkg_cb_list
= default_opkg_files_callback
;
498 opkg_cb_list
= default_opkg_list_callback
;
500 cmd
= opkg_cmd_find (cmd_name
);
503 fprintf (stderr
, "%s: unknown sub-command %s\n", argv
[0],
508 if (cmd
->requires_args
&& optind
== argc
)
511 "%s: the ``%s'' command requires at least one argument\n",
512 __FUNCTION__
, cmd_name
);
516 err
= opkg_cmd_exec (cmd
, &opkg_conf
, argc
- optind
, (const char **) (argv
+ optind
), NULL
);
518 opkg_conf_deinit (&opkg_conf
);