Rev 5737 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5737 | Rev 5809 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
5 | #include |
6 | 6 | ||
7 | #include "getopt.h" |
7 | #include "getopt.h" |
8 | #include "package.h" |
8 | #include "package.h" |
9 | #include "http.h" |
9 | #include "http.h" |
10 | 10 | ||
11 | #define BUFFSIZE (64*1024) |
11 | void process_task(list_t *task); |
12 | 12 | ||
13 | extern char conbuf[256]; |
13 | #define BUFFSIZE (64*1024) |
14 | 14 | ||
15 | #define OPTION_STD_BASE 150 |
15 | #define OPTION_STD_BASE 150 |
16 | 16 | ||
17 | enum option_values |
17 | enum option_values |
18 | { |
18 | { |
19 | OPTION_HELP = OPTION_STD_BASE, |
19 | OPTION_HELP = OPTION_STD_BASE, |
20 | OPTION_LIST_PACKAGES, |
20 | OPTION_LIST_PACKAGES, |
21 | OPTION_LIST_INSTALLED |
21 | OPTION_LIST_INSTALLED, |
- | 22 | OPTION_INSTALL_ALL |
|
22 | }; |
23 | }; |
23 | 24 | ||
24 | static const struct option longopts[] = |
25 | static const struct option longopts[] = |
25 | { |
26 | { |
26 | {"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES}, |
27 | {"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES}, |
27 | {"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED}, |
28 | {"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED}, |
- | 29 | {"install-all",no_argument, NULL, OPTION_INSTALL_ALL}, |
|
28 | {NULL,0,NULL,0} |
30 | {NULL,0,NULL,0} |
29 | }; |
31 | }; |
- | 32 | ||
- | 33 | static void show_usage () |
|
- | 34 | { |
|
- | 35 | sprintf (conbuf, "Usage: kpm [option...]\n"); |
|
- | 36 | con_write_asciiz(conbuf); |
|
- | 37 | ||
- | 38 | sprintf (conbuf, ("\ |
|
- | 39 | Options:\n\ |
|
- | 40 | --list-packages\n\ |
|
- | 41 | show available packages\n")); |
|
- | 42 | con_write_asciiz(conbuf); |
|
- | 43 | ||
- | 44 | sprintf (conbuf, ("\ |
|
- | 45 | --list-installed\n\ |
|
- | 46 | show available packages\n")); |
|
- | 47 | con_write_asciiz(conbuf); |
|
- | 48 | ||
- | 49 | sprintf (conbuf, ("\ |
|
- | 50 | --install all\n\ |
|
- | 51 | install all packages\n")); |
|
- | 52 | con_write_asciiz(conbuf); |
|
- | 53 | }; |
|
30 | 54 | ||
31 | int main(int argc, char *argv[]) |
55 | int main(int argc, char *argv[]) |
32 | { |
56 | { |
33 | LIST_HEAD(server_list); |
57 | LIST_HEAD(server_list); |
34 | LIST_HEAD(download_list); |
58 | LIST_HEAD(download_list); |
35 | LIST_HEAD(cache_list); |
59 | LIST_HEAD(cache_list); |
36 | LIST_HEAD(local_list); |
60 | LIST_HEAD(local_list); |
37 | LIST_HEAD(task_list); |
61 | LIST_HEAD(task_list); |
38 | 62 | ||
39 | int count; |
63 | int count; |
40 | char *cache_path; |
64 | char *cache_path; |
41 | char *tmp_path; |
65 | char *tmp_path; |
- | 66 | int act = 1; |
|
42 | 67 | ||
43 | if(http_init()) |
68 | if(http_init()) |
44 | goto err_init; |
69 | goto err_init; |
45 | 70 | ||
46 | set_cwd("/tmp0/1"); |
71 | set_cwd("/tmp0/1"); |
47 | 72 | ||
48 | con_init(80, 25, 80, 250, "Kolibri package manager"); |
73 | con_init(80, 25, 80, 250, "Kolibri package manager"); |
49 | 74 | ||
50 | tmp_path = make_tmp_path("packages.xml"); |
75 | tmp_path = make_tmp_path("packages.xml"); |
51 | 76 | ||
52 | count = http_load_file(tmp_path, make_url("packages.xml")); |
77 | count = http_load_file(tmp_path, make_url("packages.xml")); |
53 | 78 | ||
54 | if(count) |
79 | if(count) |
55 | build_server_list(&server_list, tmp_path); |
80 | build_server_list(&server_list, tmp_path); |
56 | 81 | ||
57 | while(1) |
82 | while(act) |
58 | { |
83 | { |
59 | int val; |
84 | int val; |
60 | int index; |
85 | int index; |
61 | 86 | ||
62 | val = getopt_long_only(argc, argv,"",longopts, &index); |
87 | val = getopt_long_only(argc, argv,"",longopts, &index); |
63 | - | ||
64 | if(val == -1) |
- | |
65 | break; |
- | |
66 | 88 | ||
67 | switch(val) |
89 | switch(val) |
68 | { |
90 | { |
69 | case OPTION_LIST_PACKAGES: |
91 | case OPTION_LIST_PACKAGES: |
70 | sprintf(conbuf,"available packages:\n\n"); |
92 | sprintf(conbuf,"available packages:\n\n"); |
71 | con_write_asciiz(conbuf); |
93 | con_write_asciiz(conbuf); |
72 | print_pkg_list(&server_list); |
94 | print_pkg_list(&server_list); |
73 | con_exit(0); |
95 | act = 0; |
74 | return 0; |
96 | break; |
75 | 97 | ||
76 | case OPTION_LIST_INSTALLED: |
98 | case OPTION_LIST_INSTALLED: |
77 | sprintf(conbuf,"installed packages:\n\n"); |
99 | sprintf(conbuf,"installed packages:\n\n"); |
78 | con_write_asciiz(conbuf); |
100 | con_write_asciiz(conbuf); |
79 | print_pkg_list(&local_list); |
101 | print_pkg_list(&local_list); |
80 | con_exit(0); |
- | |
81 | return 0; |
102 | act = 0; |
82 | - | ||
83 | default: |
- | |
84 | break; |
103 | break; |
85 | } |
- | |
86 | }; |
- | |
87 | - | ||
88 | #if 0 |
- | |
89 | { |
- | |
90 | package_t *pkg; |
- | |
91 | LIST_HEAD(install_list); |
- | |
92 | LIST_HEAD(download_list); |
- | |
93 | - | ||
94 | if(collection && build_install_list(&install_list, collection)) |
- | |
95 | { |
- | |
96 | if(build_download_list(&download_list, &install_list)) |
- | |
97 | do_download(&download_list); |
- | |
98 | 104 | ||
99 | if(!list_empty(&download_list)) |
105 | case OPTION_INSTALL_ALL: |
100 | remove_missing_packages(&install_list, &download_list); |
- | |
101 | 106 | copy_list(&task_list, &server_list); |
|
102 | list_for_each_entry(pkg, &install_list, list) |
107 | process_task(&task_list); |
103 | { |
- | |
104 | sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version); |
- | |
105 | con_write_asciiz(conbuf); |
108 | act = 0; |
- | 109 | break; |
|
106 | }; |
110 | |
107 | 111 | default: |
|
108 | do_install(&install_list); |
112 | show_usage(); |
109 | }; |
113 | act = 0; |
110 | } |
114 | } |
111 | #endif |
115 | }; |
112 | 116 | ||
113 | con_exit(0); |
117 | con_exit(0); |
114 | 118 | ||
115 | return 0; |
119 | return 0; |
116 | 120 | ||
117 | err_init: |
121 | err_init: |
118 | printf("HTTP library initialization failed\n"); |
122 | printf("HTTP library initialization failed\n"); |
119 | return -1; |
123 | return -1; |
120 | } |
124 | } |
121 | - | ||
122 | - | ||
123 | - |