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
)
63 char *v
= pkg_version_str_alloc(pkg
);
78 pkg
->tags
? pkg
->tags
: "",
91 err
= opkg_update_package_lists (progress_callback
, "Updating...");
92 printf ("\nopkg_update_package_lists returned %d\n", err
);
94 opkg_list_packages (package_list_callback
, NULL
);
99 printf ("Finding package \"%s\"\n", find_pkg
->name
);
100 pkg
= opkg_find_package (find_pkg
->name
, find_pkg
->version
, find_pkg
->architecture
, find_pkg
->src
->name
);
106 printf ("Package \"%s\" not found!\n", find_pkg
->name
);
109 printf ("No package available to test find_package.\n");
111 err
= opkg_install_package (TEST_PACKAGE
, progress_callback
, "Installing...");
112 printf ("\nopkg_install_package returned %d\n", err
);
114 err
= opkg_upgrade_package (TEST_PACKAGE
, progress_callback
, "Upgrading...");
115 printf ("\nopkg_upgrade_package returned %d\n", err
);
117 err
= opkg_remove_package (TEST_PACKAGE
, progress_callback
, "Removing...");
118 printf ("\nopkg_remove_package returned %d\n", err
);
120 printf ("Listing upgradable packages...\n");
121 opkg_list_upgradable_packages (package_list_upgradable_callback
, NULL
);
123 err
= opkg_upgrade_all (progress_callback
, "Upgrading all...");
124 printf ("\nopkg_upgrade_all returned %d\n", err
);
129 main (int argc
, char **argv
)
136 printf ("Usage: %s command\n"
138 "\tupdate - Update package lists\n"
139 "\tfind [package] - Print details of the specified package\n"
140 "\tinstall [package] - Install the specified package\n"
141 "\tupgrade [package] - Upgrade the specified package\n"
142 "\tlist upgrades - List the available upgrades\n"
143 "\tlist all - List all available packages\n"
144 "\tlist installed - List all the installed packages\n"
145 "\tremove [package] - Remove the specified package\n"
146 "\trping - Reposiroties ping, check the accessibility of repositories\n"
147 "\ttest - Run test script\n"
148 , basename (argv
[0]));
152 setenv("OFFLINE_ROOT", "/tmp", 0);
155 printf("opkg_new() failed. This sucks.\n");
163 pkg
= opkg_find_package (argv
[2], NULL
, NULL
, NULL
);
169 printf ("Package \"%s\" not found!\n", find_pkg
->name
);
172 err
= opkg_install_package (argv
[2], progress_callback
, "Installing...");
173 printf ("\nopkg_install_package returned %d\n", err
);
177 if (argv
[1][2] == 'd')
179 err
= opkg_update_package_lists (progress_callback
, "Updating...");
180 printf ("\nopkg_update_package_lists returned %d\n", err
);
187 err
= opkg_upgrade_all (progress_callback
, "Upgrading all...");
188 printf ("\nopkg_upgrade_all returned %d\n", err
);
192 err
= opkg_upgrade_package (argv
[2], progress_callback
, "Upgrading...");
193 printf ("\nopkg_upgrade_package returned %d\n", err
);
201 printf ("Please specify one either all, installed or upgrades\n");
208 printf ("Listing upgradable packages...\n");
209 opkg_list_upgradable_packages (package_list_upgradable_callback
, NULL
);
212 printf ("Listing all packages...\n");
213 opkg_list_packages (package_list_callback
, NULL
);
217 printf ("Listing installed packages...\n");
218 opkg_list_packages (package_list_installed_callback
, NULL
);
221 printf ("Unknown list option \"%s\"\n", argv
[2]);
227 if (argv
[1][1] == 'e')
229 err
= opkg_remove_package (argv
[2], progress_callback
, "Removing...");
230 printf ("\nopkg_remove_package returned %d\n", err
);
232 }else if (argv
[1][1] == 'p')
234 err
= opkg_repository_accessibility_check();
235 printf("\nopkg_repository_accessibility_check returned (%d)\n", err
);
240 printf ("Unknown command \"%s\"\n", argv
[1]);