e113847aae47a2b1251b404447530fc9f1919c2c
[project/opkg-lede.git] / opkg.c
1 /* opkg.c - the itsy package management system
2
3 Carl D. Worth
4
5 Copyright (C) 2001 University of Southern California
6
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.
11
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.
16 */
17
18 #include "opkg.h"
19
20 #include "args.h"
21 #include "opkg_conf.h"
22 #include "opkg_cmd.h"
23
24 int main(int argc, const char *argv[])
25 {
26 int err, optind;
27 args_t args;
28 char *cmd_name;
29 opkg_cmd_t *cmd;
30 opkg_conf_t opkg_conf;
31
32 error_list=NULL;
33
34 args_init(&args);
35
36 optind = args_parse(&args, argc, argv);
37 if (optind == argc || optind < 0) {
38 args_usage("opkg must have one sub-command argument");
39 }
40
41 cmd_name = argv[optind++];
42
43 err = opkg_conf_init(&opkg_conf, &args);
44 if (err) {
45 return err;
46 }
47
48 args_deinit(&args);
49
50 cmd = opkg_cmd_find(cmd_name);
51 if (cmd == NULL) {
52 fprintf(stderr, "%s: unknown sub-command %s\n", argv[0], cmd_name);
53 args_usage(NULL);
54 }
55
56 if (cmd->requires_args && optind == argc) {
57 fprintf(stderr, "%s: the ``%s'' command requires at least one argument\n",
58 __FUNCTION__, cmd_name);
59 args_usage(NULL);
60 }
61
62 err = opkg_cmd_exec(cmd, &opkg_conf, argc - optind, argv + optind);
63
64 if ( err == 0 ) {
65 opkg_message(opkg_conf, OPKG_NOTICE, "Succesfully done.\n");
66 } else {
67 opkg_message(opkg_conf, OPKG_NOTICE, "Error returned. Return value is %d\n.",err);
68
69 }
70
71 }
72 /* XXX: FEATURE request: run ldconfig and/or depmod after package needing them are installed or removed */
73 // opkg_global_postinst();
74
75 opkg_conf_deinit(&opkg_conf);
76
77 return err;
78 }
79
80
81