1 /* ipkglib.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 "ipkg_conf.h"
27 #include "file_util.h"
31 ipkg_message_callback ipkg_cb_message
= NULL
;
32 ipkg_response_callback ipkg_cb_response
= NULL
;
33 ipkg_status_callback ipkg_cb_status
= NULL
;
34 ipkg_list_callback ipkg_cb_list
= NULL
;
38 ipkg_init (ipkg_message_callback mcall
,
39 ipkg_response_callback rcall
,
42 ipkg_cb_message
= mcall
;
43 ipkg_cb_response
= rcall
;
52 ipkg_deinit (args_t
* args
)
55 ipkg_cb_message
= NULL
;
56 ipkg_cb_response
= NULL
;
58 /* place other cleanup stuff here */
65 ipkg_packages_list(args_t
*args
,
67 ipkg_list_callback cblist
,
71 ipkg_conf_t ipkg_conf
;
74 err
= ipkg_conf_init (&ipkg_conf
, args
);
80 ipkg_cb_list
= cblist
;
81 /* we need to do this because of static declarations,
82 * maybe a good idea to change */
83 cmd
= ipkg_cmd_find ("list");
85 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &packages
, userdata
);
87 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 0, NULL
, userdata
);
89 ipkg_conf_deinit (&ipkg_conf
);
95 ipkg_packages_status(args_t
*args
,
97 ipkg_status_callback cbstatus
,
101 ipkg_conf_t ipkg_conf
;
104 err
= ipkg_conf_init (&ipkg_conf
, args
);
110 ipkg_cb_status
= cbstatus
;
112 /* we need to do this because of static declarations,
113 * maybe a good idea to change */
114 cmd
= ipkg_cmd_find ("status");
116 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &packages
, userdata
);
118 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 0, NULL
, userdata
);
120 ipkg_cb_status
= NULL
;
121 ipkg_conf_deinit (&ipkg_conf
);
127 ipkg_packages_info(args_t
*args
,
128 const char *packages
,
129 ipkg_status_callback cbstatus
,
133 ipkg_conf_t ipkg_conf
;
136 err
= ipkg_conf_init (&ipkg_conf
, args
);
142 ipkg_cb_status
= cbstatus
;
144 /* we need to do this because of static declarations,
145 * maybe a good idea to change */
146 cmd
= ipkg_cmd_find ("info");
148 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &packages
, userdata
);
150 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 0, NULL
, userdata
);
152 ipkg_cb_status
= NULL
;
153 ipkg_conf_deinit (&ipkg_conf
);
159 ipkg_packages_install (args_t
* args
, const char *name
)
162 ipkg_conf_t ipkg_conf
;
165 /* this error should be handled in application */
166 if (!name
|| !strlen (name
))
169 err
= ipkg_conf_init (&ipkg_conf
, args
);
175 /* we need to do this because of static declarations,
176 * maybe a good idea to change */
177 cmd
= ipkg_cmd_find ("install");
178 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &name
, NULL
);
180 ipkg_conf_deinit(&ipkg_conf
);
186 ipkg_packages_remove(args_t
*args
, const char *name
, int purge
)
189 ipkg_conf_t ipkg_conf
;
192 /* this error should be handled in application */
193 if (!name
|| !strlen (name
))
196 err
= ipkg_conf_init (&ipkg_conf
, args
);
202 /* we need to do this because of static declarations,
203 * maybe a good idea to change */
205 cmd
= ipkg_cmd_find ("purge");
207 cmd
= ipkg_cmd_find ("remove");
209 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &name
, NULL
);
211 ipkg_conf_deinit(&ipkg_conf
);
217 ipkg_lists_update(args_t
*args
)
220 ipkg_conf_t ipkg_conf
;
223 err
= ipkg_conf_init (&ipkg_conf
, args
);
229 /* we need to do this because of static declarations,
230 * maybe a good idea to change */
231 cmd
= ipkg_cmd_find ("update");
233 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 0, NULL
, NULL
);
235 ipkg_conf_deinit(&ipkg_conf
);
241 ipkg_packages_upgrade(args_t
*args
)
244 ipkg_conf_t ipkg_conf
;
247 err
= ipkg_conf_init (&ipkg_conf
, args
);
253 /* we need to do this because of static declarations,
254 * maybe a good idea to change */
255 cmd
= ipkg_cmd_find ("upgrade");
257 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 0, NULL
, NULL
);
259 ipkg_conf_deinit(&ipkg_conf
);
265 ipkg_packages_download (args_t
* args
, const char *name
)
268 ipkg_conf_t ipkg_conf
;
271 /* this error should be handled in application */
272 if (!name
|| !strlen (name
))
275 err
= ipkg_conf_init (&ipkg_conf
, args
);
281 /* we need to do this because of static declarations,
282 * maybe a good idea to change */
283 cmd
= ipkg_cmd_find ("download");
284 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &name
, NULL
);
286 ipkg_conf_deinit(&ipkg_conf
);
292 ipkg_package_files(args_t
*args
,
294 ipkg_list_callback cblist
,
298 ipkg_conf_t ipkg_conf
;
301 /* this error should be handled in application */
302 if (!name
|| !strlen (name
))
305 err
= ipkg_conf_init (&ipkg_conf
, args
);
311 ipkg_cb_list
= cblist
;
313 /* we need to do this because of static declarations,
314 * maybe a good idea to change */
315 cmd
= ipkg_cmd_find ("files");
317 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &name
, userdata
);
320 ipkg_conf_deinit(&ipkg_conf
);
326 ipkg_file_search(args_t
*args
,
328 ipkg_list_callback cblist
,
332 ipkg_conf_t ipkg_conf
;
335 /* this error should be handled in application */
336 if (!file
|| !strlen (file
))
339 err
= ipkg_conf_init (&ipkg_conf
, args
);
345 ipkg_cb_list
= cblist
;
347 /* we need to do this because of static declarations,
348 * maybe a good idea to change */
349 cmd
= ipkg_cmd_find ("search");
350 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &file
, userdata
);
353 ipkg_conf_deinit(&ipkg_conf
);
359 ipkg_file_what(args_t
*args
, const char *file
, const char* command
)
362 ipkg_conf_t ipkg_conf
;
365 /* this error should be handled in application */
366 if (!file
|| !strlen (file
))
369 err
= ipkg_conf_init (&ipkg_conf
, args
);
375 /* we need to do this because of static declarations,
376 * maybe a good idea to change */
377 cmd
= ipkg_cmd_find (command
);
378 err
= ipkg_cmd_exec (cmd
, &ipkg_conf
, 1, &file
, NULL
);
380 ipkg_conf_deinit(&ipkg_conf
);
384 #define ipkg_package_whatdepends(args,file) ipkg_file_what(args,file,"whatdepends")
385 #define ipkg_package_whatrecommends(args, file) ipkg_file_what(args,file,"whatrecommends")
386 #define ipkg_package_whatprovides(args, file) ipkg_file_what(args,file,"whatprovides")
387 #define ipkg_package_whatconflicts(args, file) ipkg_file_what(args,file,"whatconflicts")
388 #define ipkg_package_whatreplaces(args, file) ipkg_file_what(args,file,"whatreplaces")
391 int default_ipkg_message_callback(ipkg_conf_t
*conf
, message_level_t level
,
394 if (conf
&& (conf
->verbosity
< level
)) {
398 if ( level
== IPKG_ERROR
){
399 push_error_list(&error_list
, msg
);
408 int default_ipkg_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_ipkg_files_callback(char *name
, char *desc
, char *version
,
419 pkg_state_status_t status
, void *userdata
)
422 printf("%s\n", desc
);
426 int default_ipkg_status_callback(char *name
, int istatus
, char *desc
,
429 printf("%s\n", desc
);
433 char* default_ipkg_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 ipkg_op (int argc
, char *argv
[])
452 ipkg_conf_t ipkg_conf
;
456 optind
= args_parse (&args
, argc
, argv
);
457 if (optind
== argc
|| optind
< 0)
459 args_usage ("ipkg 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
= ipkg_conf_init (&ipkg_conf
, &args
);
496 ipkg_cb_message
= default_ipkg_message_callback
;
497 ipkg_cb_response
= default_ipkg_response_callback
;
498 ipkg_cb_status
= default_ipkg_status_callback
;
499 if ( strcmp(cmd_name
, "files")==0)
500 ipkg_cb_list
= default_ipkg_files_callback
;
502 ipkg_cb_list
= default_ipkg_list_callback
;
504 cmd
= ipkg_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
= ipkg_cmd_exec (cmd
, &ipkg_conf
, argc
- optind
, (const char **) (argv
+ optind
), NULL
);
522 ipkg_conf_deinit (&ipkg_conf
);
527 #endif /* IPKG_LIB */