2015-08-16 19:59:54 +03:00
|
|
|
#include <stdlib.h>
|
2015-08-16 10:53:30 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <kos32sys.h>
|
2015-08-16 19:59:54 +03:00
|
|
|
#include <sys/kos_io.h>
|
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
#include "getopt.h"
|
2015-08-16 19:59:54 +03:00
|
|
|
#include "package.h"
|
2015-08-16 10:53:30 +03:00
|
|
|
#include "http.h"
|
|
|
|
|
|
|
|
#define BUFFSIZE (64*1024)
|
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
extern char conbuf[256];
|
2015-08-16 10:53:30 +03:00
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
#define OPTION_STD_BASE 150
|
2015-08-16 10:53:30 +03:00
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
enum option_values
|
2015-08-16 11:48:26 +03:00
|
|
|
{
|
2015-08-17 19:23:37 +03:00
|
|
|
OPTION_HELP = OPTION_STD_BASE,
|
|
|
|
OPTION_LIST_PACKAGES,
|
|
|
|
OPTION_LIST_INSTALLED
|
2015-08-16 11:48:26 +03:00
|
|
|
};
|
2015-08-16 10:53:30 +03:00
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
static const struct option longopts[] =
|
2015-08-16 17:12:29 +03:00
|
|
|
{
|
2015-08-17 19:23:37 +03:00
|
|
|
{"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES},
|
|
|
|
{"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED},
|
|
|
|
{NULL,0,NULL,0}
|
2015-08-16 17:12:29 +03:00
|
|
|
};
|
|
|
|
|
2015-08-16 10:53:30 +03:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-08-17 19:23:37 +03:00
|
|
|
LIST_HEAD(server_list);
|
|
|
|
LIST_HEAD(download_list);
|
|
|
|
LIST_HEAD(cache_list);
|
|
|
|
LIST_HEAD(local_list);
|
|
|
|
LIST_HEAD(task_list);
|
|
|
|
|
2015-08-16 10:53:30 +03:00
|
|
|
int count;
|
2015-08-16 11:48:26 +03:00
|
|
|
char *cache_path;
|
2015-08-16 17:12:29 +03:00
|
|
|
char *tmp_path;
|
2015-08-16 10:53:30 +03:00
|
|
|
|
|
|
|
if(http_init())
|
|
|
|
goto err_init;
|
|
|
|
|
2015-08-17 19:23:37 +03:00
|
|
|
set_cwd("/tmp0/1");
|
|
|
|
|
2015-08-17 13:31:03 +03:00
|
|
|
con_init(80, 25, 80, 250, "Kolibri package manager");
|
|
|
|
|
2015-08-16 17:12:29 +03:00
|
|
|
tmp_path = make_tmp_path("packages.xml");
|
2015-08-16 11:48:26 +03:00
|
|
|
|
2015-08-16 17:12:29 +03:00
|
|
|
count = http_load_file(tmp_path, make_url("packages.xml"));
|
2015-08-16 10:53:30 +03:00
|
|
|
|
|
|
|
if(count)
|
2015-08-17 19:23:37 +03:00
|
|
|
build_server_list(&server_list, tmp_path);
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
val = getopt_long_only(argc, argv,"",longopts, &index);
|
|
|
|
|
|
|
|
if(val == -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(val)
|
|
|
|
{
|
|
|
|
case OPTION_LIST_PACKAGES:
|
|
|
|
sprintf(conbuf,"available packages:\n\n");
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
print_pkg_list(&server_list);
|
|
|
|
con_exit(0);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case OPTION_LIST_INSTALLED:
|
|
|
|
sprintf(conbuf,"installed packages:\n\n");
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
print_pkg_list(&local_list);
|
|
|
|
con_exit(0);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#if 0
|
2015-08-16 10:53:30 +03:00
|
|
|
{
|
2015-08-16 17:12:29 +03:00
|
|
|
package_t *pkg;
|
|
|
|
LIST_HEAD(install_list);
|
|
|
|
LIST_HEAD(download_list);
|
2015-08-16 10:53:30 +03:00
|
|
|
|
2015-08-16 17:12:29 +03:00
|
|
|
if(collection && build_install_list(&install_list, collection))
|
2015-08-16 10:53:30 +03:00
|
|
|
{
|
2015-08-16 17:12:29 +03:00
|
|
|
if(build_download_list(&download_list, &install_list))
|
2015-08-16 19:59:54 +03:00
|
|
|
do_download(&download_list);
|
|
|
|
|
|
|
|
if(!list_empty(&download_list))
|
2015-08-16 22:06:43 +03:00
|
|
|
remove_missing_packages(&install_list, &download_list);
|
2015-08-16 19:59:54 +03:00
|
|
|
|
|
|
|
list_for_each_entry(pkg, &install_list, list)
|
2015-08-17 13:31:03 +03:00
|
|
|
{
|
|
|
|
sprintf(conbuf,"install package %s-%s\n", pkg->name, pkg->version);
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
};
|
2015-08-16 22:06:43 +03:00
|
|
|
|
|
|
|
do_install(&install_list);
|
2015-08-16 10:53:30 +03:00
|
|
|
};
|
2015-08-17 13:31:03 +03:00
|
|
|
}
|
2015-08-17 19:23:37 +03:00
|
|
|
#endif
|
2015-08-17 13:31:03 +03:00
|
|
|
|
|
|
|
con_exit(0);
|
2015-08-16 10:53:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_init:
|
|
|
|
printf("HTTP library initialization failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-08-16 19:59:54 +03:00
|
|
|
|
|
|
|
|
2015-08-16 22:06:43 +03:00
|
|
|
|
|
|
|
|