8 pkg_t
*find_pkg
= NULL
;
11 #define TEST_PACKAGE "aspell"
14 progress_callback (const opkg_progress_data_t
*progress
, void *data
)
16 printf ("\r%s %3d%%\n", (char*) data
, progress
->percentage
);
20 static void list_pkg(pkg_t
*pkg
)
22 char *v
= pkg_version_str_alloc(pkg
);
23 printf ("%s - %s\n", pkg
->name
, v
);
28 package_list_installed_callback (pkg_t
*pkg
, void *data
)
30 if (pkg
->state_status
== SS_INSTALLED
)
35 package_list_callback (pkg_t
*pkg
, void *data
)
37 static int install_count
= 0;
38 static int total_count
= 0;
40 if (pkg
->state_status
== SS_INSTALLED
)
45 printf ("\rPackage count: %d Installed, %d Total Available", install_count
, total_count
);
50 /* store the first package to print out later */
56 package_list_upgradable_callback (pkg_t
*pkg
, void *data
)
62 print_package (pkg_t
*pkg
)
64 char *v
= pkg_version_str_alloc(pkg
);
79 pkg
->tags
? pkg
->tags
: "",
92 err
= opkg_update_package_lists (progress_callback
, "Updating...");
93 printf ("\nopkg_update_package_lists returned %d\n", err
);
95 opkg_list_packages (package_list_callback
, NULL
);
100 printf ("Finding package \"%s\"\n", find_pkg
->name
);
101 pkg
= opkg_find_package (find_pkg
->name
, find_pkg
->version
, find_pkg
->architecture
, find_pkg
->src
->name
);
107 printf ("Package \"%s\" not found!\n", find_pkg
->name
);
110 printf ("No package available to test find_package.\n");
112 err
= opkg_install_package (TEST_PACKAGE
, progress_callback
, "Installing...");
113 printf ("\nopkg_install_package returned %d\n", err
);
115 err
= opkg_upgrade_package (TEST_PACKAGE
, progress_callback
, "Upgrading...");
116 printf ("\nopkg_upgrade_package returned %d\n", err
);
118 err
= opkg_remove_package (TEST_PACKAGE
, progress_callback
, "Removing...");
119 printf ("\nopkg_remove_package returned %d\n", err
);
121 printf ("Listing upgradable packages...\n");
122 opkg_list_upgradable_packages (package_list_upgradable_callback
, NULL
);
124 err
= opkg_upgrade_all (progress_callback
, "Upgrading all...");
125 printf ("\nopkg_upgrade_all returned %d\n", err
);
130 main (int argc
, char **argv
)
137 printf ("Usage: %s command\n"
139 "\tupdate - Update package lists\n"
140 "\tfind [package] - Print details of the specified package\n"
141 "\tinstall [package] - Install the specified package\n"
142 "\tupgrade [package] - Upgrade the specified package\n"
143 "\tlist upgrades - List the available upgrades\n"
144 "\tlist all - List all available packages\n"
145 "\tlist installed - List all the installed packages\n"
146 "\tremove [package] - Remove the specified package\n"
147 "\trping - Reposiroties ping, check the accessibility of repositories\n"
148 "\ttest - Run test script\n"
149 , basename (argv
[0]));
153 setenv("OFFLINE_ROOT", "/tmp", 0);
156 printf("opkg_new() failed. This sucks.\n");
164 pkg
= opkg_find_package (argv
[2], NULL
, NULL
, NULL
);
170 printf ("Package \"%s\" not found!\n", find_pkg
->name
);
173 err
= opkg_install_package (argv
[2], progress_callback
, "Installing...");
174 printf ("\nopkg_install_package returned %d\n", err
);
178 if (argv
[1][2] == 'd')
180 err
= opkg_update_package_lists (progress_callback
, "Updating...");
181 printf ("\nopkg_update_package_lists returned %d\n", err
);
188 err
= opkg_upgrade_all (progress_callback
, "Upgrading all...");
189 printf ("\nopkg_upgrade_all returned %d\n", err
);
193 err
= opkg_upgrade_package (argv
[2], progress_callback
, "Upgrading...");
194 printf ("\nopkg_upgrade_package returned %d\n", err
);
202 printf ("Please specify one either all, installed or upgrades\n");
209 printf ("Listing upgradable packages...\n");
210 opkg_list_upgradable_packages (package_list_upgradable_callback
, NULL
);
213 printf ("Listing all packages...\n");
214 opkg_list_packages (package_list_callback
, NULL
);
218 printf ("Listing installed packages...\n");
219 opkg_list_packages (package_list_installed_callback
, NULL
);
222 printf ("Unknown list option \"%s\"\n", argv
[2]);
228 if (argv
[1][1] == 'e')
230 err
= opkg_remove_package (argv
[2], progress_callback
, "Removing...");
231 printf ("\nopkg_remove_package returned %d\n", err
);
233 }else if (argv
[1][1] == 'p')
235 err
= opkg_repository_accessibility_check();
236 printf("\nopkg_repository_accessibility_check returned (%d)\n", err
);
241 printf ("Unknown command \"%s\"\n", argv
[1]);