}
int
-opkg_install_package (opkg_t *opkg, char *package_name)
+opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
int err;
+ char *package_id;
+ progress_callback (opkg, 0, user_data);
+
+ /* download the package */
+ opkg_prepare_url_for_install (opkg->conf, package_name, &package_id);
+ progress_callback (opkg, 50, user_data);
+
+ /* ... */
pkg_info_preinstall_check (opkg->conf);
+ /* unpack the package */
if (opkg->conf->multiple_providers)
{
- err = opkg_install_multi_by_name (opkg->conf, package_name);
+ err = opkg_install_multi_by_name (opkg->conf, package_id);
}
else
{
- err = opkg_install_by_name (opkg->conf, package_name);
+ err = opkg_install_by_name (opkg->conf, package_id);
}
- err = opkg_configure_packages (opkg->conf, NULL);
+ progress_callback (opkg, 75, user_data);
- if (opkg->conf->noaction)
- return err;
+ /* run configure scripts, etc. */
+ err = opkg_configure_packages (opkg->conf, NULL);
+ /* write out status files and file lists */
opkg_conf_write_status_files (opkg->conf);
pkg_write_changed_filelists (opkg->conf);
+ progress_callback (opkg, 100, user_data);
return err;
}
int
-opkg_remove_package (opkg_t *opkg, char *package_name)
+opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
return 1;
}
int
-opkg_upgrade_package (opkg_t *opkg, char *package_name)
+opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t progress_callback, void *user_data)
{
return 1;
}
int
-opkg_upgrade_all (opkg_t *opkg)
+opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
{
return 1;
}
int
-opkg_update_package_lists (opkg_t *opkg)
+opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callback, void *user_data)
{
char *tmp;
int err;
char *lists_dir;
pkg_src_list_elt_t *iter;
pkg_src_t *src;
+ int sources_list_count, sources_done;
+ progress_callback (opkg, 0, user_data);
sprintf_alloc (&lists_dir, "%s",
(opkg->conf->restrict_to_default_dest)
return 1;
}
+ /* cout the number of sources so we can give some progress updates */
+ sources_list_count = 0;
+ sources_done = 0;
+ iter = opkg->conf->pkg_src_list.head;
+ while (iter)
+ {
+ sources_list_count++;
+ iter = iter->next;
+ }
for (iter = opkg->conf->pkg_src_list.head; iter; iter = iter->next)
{
*/
#endif
free (list_file_name);
+
+ sources_done++;
+ progress_callback (opkg, 100 * sources_done / sources_list_count, user_data);
}
rmdir (tmp);
free (tmp);
*/
typedef struct _opkg_t opkg_t;
+typedef void (*opkg_progress_callback_t) (opkg_t *opkg, int percentage, void *user_data);
opkg_t* opkg_new ();
void opkg_free (opkg_t *opkg);
void opkg_set_option (opkg_t *opkg, char *option, void *value);
int opkg_read_config_files (opkg_t *opkg);
-int opkg_install_package (opkg_t *opkg, char *package_name);
-int opkg_remove_package (opkg_t *opkg, char *package_name);
-int opkg_upgrade_package (opkg_t *opkg, char *package_name);
-int opkg_upgrade_all (opkg_t *opkg);
-int opkg_update_package_lists (opkg_t *opkg);
+int opkg_install_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_remove_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_package (opkg_t *opkg, const char *package_name, opkg_progress_callback_t callback, void *user_data);
+int opkg_upgrade_all (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
+int opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t callback, void *user_data);
#include <opkg.h>
#include <stdlib.h>
+#include <stdio.h>
+
+void
+progress_callback (opkg_t *opkg, int percent, void *data)
+{
+ printf ("%s %d\n", (char*) data, percent);
+}
+
int
main (int argc, char **argv)
opkg_read_config_files (opkg);
- err = opkg_update_package_lists (opkg);
+ err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
printf ("opkg_update_package_lists returned %d\n", err);
+ err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
+
+ printf ("opkg_install_package returned %d\n", err);
+
opkg_free (opkg);
}