1 /* opkg.c - the opkg package management system
3 Thomas Wood <thomas@openedhand.com>
5 Copyright (C) 2008 OpenMoko Inc
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"
25 #include "opkg_install.h"
26 #include "opkg_configure.h"
32 opkg_option_t *options[];
35 /** Private Functions ***/
39 opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
46 all = pkg_vec_alloc();
47 pkg_hash_fetch_available(&conf->pkg_hash, all);
49 for (i = 0; i < all->len; i++)
53 if (pkg_name && fnmatch(pkg_name, pkg->name, 0))
56 if (pkg->state_status == SS_UNPACKED)
58 r = opkg_configure(conf, pkg);
61 pkg->state_status = SS_INSTALLED;
62 pkg->parent->state_status = SS_INSTALLED;
63 pkg->state_flag &= ~SF_PREFER;
85 opkg = malloc (sizeof (opkg_t));
86 args_init (opkg->args);
87 opkg_conf_init (opkg->conf, opkg->args);
88 opkg_init_options_array (opkg->conf, opkg->options);
93 opkg_free (opkg_t *opkg)
95 opkg_conf_deinit (opkg->conf);
96 args_deinit (opkg->args);
100 opkg_get_option (opkg_t *opkg, char *option, void **value)
103 opkg_option_t **options = opkg->options;
105 /* can't store a value in a NULL pointer! */
109 /* look up the option
110 * TODO: this would be much better as a hash table
112 while (options[i]->name)
114 if (strcmp(options[i]->name, option) != 0)
122 switch (options[i]->type)
124 case OPKG_OPT_TYPE_BOOL:
125 *((int *) value) = *((int *) options[i]->value);
128 case OPKG_OPT_TYPE_INT:
129 *((int *) value) = *((int *) options[i]->value);
132 case OPKG_OPT_TYPE_STRING:
133 *((char **)value) = strdup (options[i]->value);
140 opkg_set_option (opkg_t *opkg, char *option, void *value)
143 opkg_option_t **options = opkg->options;
145 /* NULL values are not defined */
149 /* look up the option
150 * TODO: this would be much better as a hash table
152 while (options[i]->name)
154 if (strcmp(options[i]->name, option) != 0)
162 switch (options[i]->type)
164 case OPKG_OPT_TYPE_BOOL:
165 if (*((int *) value) == 0)
166 *((int *)options[i]->value) = 0;
168 *((int *)options[i]->value) = 1;
171 case OPKG_OPT_TYPE_INT:
172 *((int *) options[i]->value) = *((int *) value);
175 case OPKG_OPT_TYPE_STRING:
176 *((char **)options[i]->value) = strdup(value);
183 opkg_install_package (opkg_t *opkg, char *package_name)
187 pkg_info_preinstall_check(opkg->conf);
189 if (opkg->conf->multiple_providers)
191 err = opkg_install_multi_by_name (opkg->conf, package_name);
195 err = opkg_install_by_name (opkg->conf, package_name);
198 err = opkg_configure_packages (opkg->conf, NULL);
200 if (opkg->conf->noaction)
203 opkg_conf_write_status_files (opkg->conf);
204 pkg_write_changed_filelists (opkg->conf);
210 opkg_remove_package (opkg_t *opkg, char *package_name)
216 opkg_upgrade_package (opkg_t *opkg, char *package_name)
222 opkg_upgrade_all (opkg_t *opkg)
228 opkg_update_package_lists (opkg_t *opkg)