7 pkg_t *find_pkg = NULL;
10 #define TEST_PACKAGE "aspell"
13 progress_callback (const opkg_progress_data_t *progress, void *data)
15 printf ("\r%s %3d%%\n", (char*) data, progress->percentage);
19 static void list_pkg(pkg_t *pkg)
21 char *v = pkg_version_str_alloc(pkg);
22 printf ("%s - %s\n", pkg->name, v);
27 package_list_installed_callback (pkg_t *pkg, void *data)
29 if (pkg->state_status == SS_INSTALLED)
34 package_list_callback (pkg_t *pkg, void *data)
36 static int install_count = 0;
37 static int total_count = 0;
39 if (pkg->state_status == SS_INSTALLED)
44 printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
49 /* store the first package to print out later */
55 package_list_upgradable_callback (pkg_t *pkg, void *data)
61 print_package (pkg_t *pkg)
90 err = opkg_update_package_lists (progress_callback, "Updating...");
91 printf ("\nopkg_update_package_lists returned %d\n", err);
93 opkg_list_packages (package_list_callback, NULL);
98 printf ("Finding package \"%s\"\n", find_pkg->name);
99 pkg = opkg_find_package (find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->src->name);
105 printf ("Package \"%s\" not found!\n", find_pkg->name);
108 printf ("No package available to test find_package.\n");
110 err = opkg_install_package (TEST_PACKAGE, progress_callback, "Installing...");
111 printf ("\nopkg_install_package returned %d\n", err);
113 err = opkg_upgrade_package (TEST_PACKAGE, progress_callback, "Upgrading...");
114 printf ("\nopkg_upgrade_package returned %d\n", err);
116 err = opkg_remove_package (TEST_PACKAGE, progress_callback, "Removing...");
117 printf ("\nopkg_remove_package returned %d\n", err);
119 printf ("Listing upgradable packages...\n");
120 opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
122 err = opkg_upgrade_all (progress_callback, "Upgrading all...");
123 printf ("\nopkg_upgrade_all returned %d\n", err);
128 main (int argc, char **argv)
135 printf ("Usage: %s command\n"
137 "\tupdate - Update package lists\n"
138 "\tfind [package] - Print details of the specified package\n"
139 "\tinstall [package] - Install the specified package\n"
140 "\tupgrade [package] - Upgrade the specified package\n"
141 "\tlist upgrades - List the available upgrades\n"
142 "\tlist all - List all available packages\n"
143 "\tlist installed - List all the installed packages\n"
144 "\tremove [package] - Remove the specified package\n"
145 "\trping - Reposiroties ping, check the accessibility of repositories\n"
146 "\ttest - Run test script\n"
147 , basename (argv[0]));
151 setenv("OFFLINE_ROOT", "/tmp", 0);
154 printf("opkg_new() failed. This sucks.\n");
162 pkg = opkg_find_package (argv[2], NULL, NULL, NULL);
168 printf ("Package \"%s\" not found!\n", find_pkg->name);
171 err = opkg_install_package (argv[2], progress_callback, "Installing...");
172 printf ("\nopkg_install_package returned %d\n", err);
176 if (argv[1][2] == 'd')
178 err = opkg_update_package_lists (progress_callback, "Updating...");
179 printf ("\nopkg_update_package_lists returned %d\n", err);
186 err = opkg_upgrade_all (progress_callback, "Upgrading all...");
187 printf ("\nopkg_upgrade_all returned %d\n", err);
191 err = opkg_upgrade_package (argv[2], progress_callback, "Upgrading...");
192 printf ("\nopkg_upgrade_package returned %d\n", err);
200 printf ("Please specify one either all, installed or upgrades\n");
207 printf ("Listing upgradable packages...\n");
208 opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
211 printf ("Listing all packages...\n");
212 opkg_list_packages (package_list_callback, NULL);
216 printf ("Listing installed packages...\n");
217 opkg_list_packages (package_list_installed_callback, NULL);
220 printf ("Unknown list option \"%s\"\n", argv[2]);
226 if (argv[1][1] == 'e')
228 err = opkg_remove_package (argv[2], progress_callback, "Removing...");
229 printf ("\nopkg_remove_package returned %d\n", err);
231 }else if (argv[1][1] == 'p')
233 err = opkg_repository_accessibility_check();
234 printf("\nopkg_repository_accessibility_check returned (%d)\n", err);
239 printf ("Unknown command \"%s\"\n", argv[1]);