8 int opkg_state_changed;
9 pkg_t *find_pkg = NULL;
12 #define TEST_PACKAGE "aspell"
15 progress_callback (const opkg_progress_data_t *progress, void *data)
17 printf ("\r%s %3d%%\n", (char*) data, progress->percentage);
21 static void list_pkg(pkg_t *pkg)
23 char *v = pkg_version_str_alloc(pkg);
24 printf ("%s - %s\n", pkg->name, v);
29 package_list_installed_callback (pkg_t *pkg, void *data)
31 if (pkg->state_status == SS_INSTALLED)
36 package_list_callback (pkg_t *pkg, void *data)
38 static int install_count = 0;
39 static int total_count = 0;
41 if (pkg->state_status == SS_INSTALLED)
46 printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
51 /* store the first package to print out later */
57 package_list_upgradable_callback (pkg_t *pkg, void *data)
63 print_package (pkg_t *pkg)
65 char *v = pkg_version_str_alloc(pkg);
80 pkg->tags? pkg->tags : "",
93 err = opkg_update_package_lists (progress_callback, "Updating...");
94 printf ("\nopkg_update_package_lists returned %d\n", err);
96 opkg_list_packages (package_list_callback, NULL);
101 printf ("Finding package \"%s\"\n", find_pkg->name);
102 pkg = opkg_find_package (find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->src->name);
108 printf ("Package \"%s\" not found!\n", find_pkg->name);
111 printf ("No package available to test find_package.\n");
113 err = opkg_install_package (TEST_PACKAGE, progress_callback, "Installing...");
114 printf ("\nopkg_install_package returned %d\n", err);
116 err = opkg_upgrade_package (TEST_PACKAGE, progress_callback, "Upgrading...");
117 printf ("\nopkg_upgrade_package returned %d\n", err);
119 err = opkg_remove_package (TEST_PACKAGE, progress_callback, "Removing...");
120 printf ("\nopkg_remove_package returned %d\n", err);
122 printf ("Listing upgradable packages...\n");
123 opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
125 err = opkg_upgrade_all (progress_callback, "Upgrading all...");
126 printf ("\nopkg_upgrade_all returned %d\n", err);
131 main (int argc, char **argv)
138 printf ("Usage: %s command\n"
140 "\tupdate - Update package lists\n"
141 "\tfind [package] - Print details of the specified package\n"
142 "\tinstall [package] - Install the specified package\n"
143 "\tupgrade [package] - Upgrade the specified package\n"
144 "\tlist upgrades - List the available upgrades\n"
145 "\tlist all - List all available packages\n"
146 "\tlist installed - List all the installed packages\n"
147 "\tremove [package] - Remove the specified package\n"
148 "\trping - Reposiroties ping, check the accessibility of repositories\n"
149 "\ttest - Run test script\n"
150 , basename (argv[0]));
154 setenv("OFFLINE_ROOT", "/tmp", 0);
157 printf("opkg_new() failed. This sucks.\n");
165 pkg = opkg_find_package (argv[2], NULL, NULL, NULL);
171 printf ("Package \"%s\" not found!\n", find_pkg->name);
174 err = opkg_install_package (argv[2], progress_callback, "Installing...");
175 printf ("\nopkg_install_package returned %d\n", err);
179 if (argv[1][2] == 'd')
181 err = opkg_update_package_lists (progress_callback, "Updating...");
182 printf ("\nopkg_update_package_lists returned %d\n", err);
189 err = opkg_upgrade_all (progress_callback, "Upgrading all...");
190 printf ("\nopkg_upgrade_all returned %d\n", err);
194 err = opkg_upgrade_package (argv[2], progress_callback, "Upgrading...");
195 printf ("\nopkg_upgrade_package returned %d\n", err);
203 printf ("Please specify one either all, installed or upgrades\n");
210 printf ("Listing upgradable packages...\n");
211 opkg_list_upgradable_packages (package_list_upgradable_callback, NULL);
214 printf ("Listing all packages...\n");
215 opkg_list_packages (package_list_callback, NULL);
219 printf ("Listing installed packages...\n");
220 opkg_list_packages (package_list_installed_callback, NULL);
223 printf ("Unknown list option \"%s\"\n", argv[2]);
229 if (argv[1][1] == 'e')
231 err = opkg_remove_package (argv[2], progress_callback, "Removing...");
232 printf ("\nopkg_remove_package returned %d\n", err);
234 }else if (argv[1][1] == 'p')
236 err = opkg_repository_accessibility_check();
237 printf("\nopkg_repository_accessibility_check returned (%d)\n", err);
242 printf ("Unknown command \"%s\"\n", argv[1]);