8 int opkg_state_changed
;
9 pkg_t
*find_pkg
= NULL
;
11 #define TEST_PACKAGE "aspell"
13 void 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
);
26 void package_list_installed_callback(pkg_t
* pkg
, void *data
)
28 if (pkg
->state_status
== SS_INSTALLED
)
32 void package_list_callback(pkg_t
* pkg
, void *data
)
34 static int install_count
= 0;
35 static int total_count
= 0;
37 if (pkg
->state_status
== SS_INSTALLED
)
42 printf("\rPackage count: %d Installed, %d Total Available",
43 install_count
, total_count
);
47 /* store the first package to print out later */
52 void package_list_upgradable_callback(pkg_t
* pkg
, void *data
)
57 void print_package(pkg_t
* pkg
)
59 char *v
= pkg_version_str_alloc(pkg
);
60 const char *tags
= pkg_get_string(pkg
, PKG_TAGS
);
73 pkg_get_string(pkg
, PKG_ARCHITECTURE
),
74 pkg_get_string(pkg
, PKG_DESCRIPTION
),
75 tags
? tags
: "", pkg
->size
, pkg
->state_status
);
84 err
= opkg_update_package_lists(progress_callback
, "Updating...");
85 printf("\nopkg_update_package_lists returned %d\n", err
);
87 opkg_list_packages(package_list_callback
, NULL
);
91 printf("Finding package \"%s\"\n", find_pkg
->name
);
93 opkg_find_package(find_pkg
->name
,
94 pkg_get_string(find_pkg
, PKG_VERSION
),
95 pkg_get_string(find_pkg
, PKG_ARCHITECTURE
),
100 printf("Package \"%s\" not found!\n", find_pkg
->name
);
102 printf("No package available to test find_package.\n");
105 opkg_install_package(TEST_PACKAGE
, progress_callback
,
107 printf("\nopkg_install_package returned %d\n", err
);
110 opkg_upgrade_package(TEST_PACKAGE
, progress_callback
,
112 printf("\nopkg_upgrade_package returned %d\n", err
);
115 opkg_remove_package(TEST_PACKAGE
, progress_callback
, "Removing...");
116 printf("\nopkg_remove_package returned %d\n", err
);
118 printf("Listing upgradable packages...\n");
119 opkg_list_upgradable_packages(package_list_upgradable_callback
, NULL
);
121 err
= opkg_upgrade_all(progress_callback
, "Upgrading all...");
122 printf("\nopkg_upgrade_all returned %d\n", err
);
126 int main(int argc
, char **argv
)
132 printf("Usage: %s command\n"
134 "\tupdate - Update package lists\n"
135 "\tfind [package] - Print details of the specified package\n"
136 "\tinstall [package] - Install the specified package\n"
137 "\tupgrade [package] - Upgrade the specified package\n"
138 "\tlist upgrades - List the available upgrades\n"
139 "\tlist all - List all available packages\n"
140 "\tlist installed - List all the installed packages\n"
141 "\tremove [package] - Remove the specified package\n"
142 "\trping - Reposiroties ping, check the accessibility of repositories\n"
143 "\ttest - Run test script\n", basename(argv
[0]));
147 setenv("OFFLINE_ROOT", "/tmp", 0);
150 printf("opkg_new() failed. This sucks.\n");
155 switch (argv
[1][0]) {
157 pkg
= opkg_find_package(argv
[2], NULL
, NULL
, NULL
);
161 printf("Package \"%s\" not found!\n", find_pkg
->name
);
165 opkg_install_package(argv
[2], progress_callback
,
167 printf("\nopkg_install_package returned %d\n", err
);
171 if (argv
[1][2] == 'd') {
173 opkg_update_package_lists(progress_callback
,
175 printf("\nopkg_update_package_lists returned %d\n",
181 opkg_upgrade_all(progress_callback
,
183 printf("\nopkg_upgrade_all returned %d\n", err
);
186 opkg_upgrade_package(argv
[2],
189 printf("\nopkg_upgrade_package returned %d\n",
198 ("Please specify one either all, installed or upgrades\n");
200 switch (argv
[2][0]) {
202 printf("Listing upgradable packages...\n");
203 opkg_list_upgradable_packages
204 (package_list_upgradable_callback
, NULL
);
207 printf("Listing all packages...\n");
208 opkg_list_packages(package_list_callback
, NULL
);
212 printf("Listing installed packages...\n");
214 (package_list_installed_callback
, NULL
);
217 printf("Unknown list option \"%s\"\n", argv
[2]);
223 if (argv
[1][1] == 'e') {
225 opkg_remove_package(argv
[2], progress_callback
,
227 printf("\nopkg_remove_package returned %d\n", err
);
229 } else if (argv
[1][1] == 'p') {
230 err
= opkg_repository_accessibility_check();
232 ("\nopkg_repository_accessibility_check returned (%d)\n",
238 printf("Unknown command \"%s\"\n", argv
[1]);