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"
27 #include "opkg_download.h"
29 #include "sprintf_alloc.h"
30 #include "file_util.h"
38 opkg_option_t *options[];
41 /** Private Functions ***/
45 opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
52 all = pkg_vec_alloc ();
53 pkg_hash_fetch_available (&conf->pkg_hash, all);
55 for (i = 0; i < all->len; i++)
59 if (pkg_name && fnmatch (pkg_name, pkg->name, 0))
62 if (pkg->state_status == SS_UNPACKED)
64 r = opkg_configure (conf, pkg);
67 pkg->state_status = SS_INSTALLED;
68 pkg->parent->state_status = SS_INSTALLED;
69 pkg->state_flag &= ~SF_PREFER;
91 opkg = malloc (sizeof (opkg_t));
92 args_init (opkg->args);
93 opkg_conf_init (opkg->conf, opkg->args);
94 opkg_init_options_array (opkg->conf, opkg->options);
99 opkg_free (opkg_t *opkg)
101 opkg_conf_deinit (opkg->conf);
102 args_deinit (opkg->args);
106 opkg_get_option (opkg_t *opkg, char *option, void **value)
109 opkg_option_t **options = opkg->options;
111 /* can't store a value in a NULL pointer! */
115 /* look up the option
116 * TODO: this would be much better as a hash table
118 while (options[i]->name)
120 if (strcmp (options[i]->name, option) != 0)
128 switch (options[i]->type)
130 case OPKG_OPT_TYPE_BOOL:
131 *((int *) value) = *((int *) options[i]->value);
134 case OPKG_OPT_TYPE_INT:
135 *((int *) value) = *((int *) options[i]->value);
138 case OPKG_OPT_TYPE_STRING:
139 *((char **)value) = strdup (options[i]->value);
146 opkg_set_option (opkg_t *opkg, char *option, void *value)
149 opkg_option_t **options = opkg->options;
151 /* NULL values are not defined */
155 /* look up the option
156 * TODO: this would be much better as a hash table
158 while (options[i]->name)
160 if (strcmp (options[i]->name, option) != 0)
168 switch (options[i]->type)
170 case OPKG_OPT_TYPE_BOOL:
171 if (*((int *) value) == 0)
172 *((int *)options[i]->value) = 0;
174 *((int *)options[i]->value) = 1;
177 case OPKG_OPT_TYPE_INT:
178 *((int *) options[i]->value) = *((int *) value);
181 case OPKG_OPT_TYPE_STRING:
182 *((char **)options[i]->value) = strdup (value);
189 opkg_install_package (opkg_t *opkg, char *package_name)
193 pkg_info_preinstall_check (opkg->conf);
195 if (opkg->conf->multiple_providers)
197 err = opkg_install_multi_by_name (opkg->conf, package_name);
201 err = opkg_install_by_name (opkg->conf, package_name);
204 err = opkg_configure_packages (opkg->conf, NULL);
206 if (opkg->conf->noaction)
209 opkg_conf_write_status_files (opkg->conf);
210 pkg_write_changed_filelists (opkg->conf);
216 opkg_remove_package (opkg_t *opkg, char *package_name)
222 opkg_upgrade_package (opkg_t *opkg, char *package_name)
228 opkg_upgrade_all (opkg_t *opkg)
234 opkg_update_package_lists (opkg_t *opkg)
239 pkg_src_list_elt_t *iter;
243 sprintf_alloc (&lists_dir, "%s",
244 (opkg->conf->restrict_to_default_dest)
245 ? opkg->conf->default_dest->lists_dir
246 : opkg->conf->lists_dir);
248 if (!file_is_dir (lists_dir))
250 if (file_exists (lists_dir))
252 /* XXX: Error: file exists but is not a directory */
257 err = file_mkdir_hier (lists_dir, 0755);
260 /* XXX: Error: failed to create directory */
266 tmp = strdup ("/tmp/opkg.XXXXXX");
268 if (mkdtemp (tmp) == NULL)
270 /* XXX: Error: could not create temporary file name */
277 for (iter = opkg->conf->pkg_src_list.head; iter; iter = iter->next)
279 char *url, *list_file_name;
283 if (src->extra_data) /* debian style? */
284 sprintf_alloc (&url, "%s/%s/%s", src->value, src->extra_data,
285 src->gzip ? "Packages.gz" : "Packages");
287 sprintf_alloc (&url, "%s/%s", src->value, src->gzip ? "Packages.gz" : "Packages");
289 sprintf_alloc (&list_file_name, "%s/%s", lists_dir, src->name);
295 sprintf_alloc (&tmp_file_name, "%s/%s.gz", tmp, src->name);
297 /* XXX: Note: downloading url */
298 err = opkg_download (opkg->conf, url, tmp_file_name);
302 /* XXX: Note: Inflating downloaded file */
303 in = fopen (tmp_file_name, "r");
304 out = fopen (list_file_name, "w");
313 unlink (tmp_file_name);
317 err = opkg_download (opkg->conf, url, list_file_name);
321 /* XXX: Error: download error */
326 /* download detached signitures to verify the package lists */
327 /* get the url for the sig file */
328 if (src->extra_data) /* debian style? */
329 sprintf_alloc (&url, "%s/%s/%s", src->value, src->extra_data,
332 sprintf_alloc (&url, "%s/%s", src->value, "Packages.sig");
334 /* create temporary file for it */
337 sprintf_alloc (&tmp_file_name, "%s/%s", tmp, "Packages.sig");
339 err = opkg_download (opkg->conf, url, tmp_file_name);
342 /* XXX: Warning: Download failed */
347 err = opkg_verify_file (opkg->conf, list_file_name, tmp_file_name);
350 /* XXX: Notice: Signature check passed */
354 /* XXX: Warning: Signature check failed */
357 unlink (tmp_file_name);
358 free (tmp_file_name);
361 /* XXX: Note: Signiture check for %s skipped because GPG support was not
362 * enabled in this build
365 free (list_file_name);