2015-08-16 18:59:54 +02:00
|
|
|
#include <stdlib.h>
|
2015-08-16 09:53:30 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <kos32sys.h>
|
2015-08-16 18:59:54 +02:00
|
|
|
#include <sys/kos_io.h>
|
|
|
|
|
2015-08-17 18:23:37 +02:00
|
|
|
#include "getopt.h"
|
2015-08-16 18:59:54 +02:00
|
|
|
#include "package.h"
|
2015-08-16 09:53:30 +02:00
|
|
|
#include "http.h"
|
|
|
|
|
2015-09-06 12:18:55 +02:00
|
|
|
void process_task(list_t *task);
|
2015-08-16 09:53:30 +02:00
|
|
|
|
2015-09-06 12:18:55 +02:00
|
|
|
#define BUFFSIZE (64*1024)
|
2015-08-16 09:53:30 +02:00
|
|
|
|
2015-08-17 18:23:37 +02:00
|
|
|
#define OPTION_STD_BASE 150
|
2015-08-16 09:53:30 +02:00
|
|
|
|
2015-08-17 18:23:37 +02:00
|
|
|
enum option_values
|
2015-08-16 10:48:26 +02:00
|
|
|
{
|
2015-08-17 18:23:37 +02:00
|
|
|
OPTION_HELP = OPTION_STD_BASE,
|
|
|
|
OPTION_LIST_PACKAGES,
|
2015-09-06 12:18:55 +02:00
|
|
|
OPTION_LIST_INSTALLED,
|
|
|
|
OPTION_INSTALL_ALL
|
2015-08-16 10:48:26 +02:00
|
|
|
};
|
2015-08-16 09:53:30 +02:00
|
|
|
|
2015-08-17 18:23:37 +02:00
|
|
|
static const struct option longopts[] =
|
2015-08-16 16:12:29 +02:00
|
|
|
{
|
2015-08-17 18:23:37 +02:00
|
|
|
{"list-packages", no_argument, NULL, OPTION_LIST_PACKAGES},
|
|
|
|
{"list-installed",no_argument, NULL, OPTION_LIST_INSTALLED},
|
2015-09-06 12:18:55 +02:00
|
|
|
{"install-all",no_argument, NULL, OPTION_INSTALL_ALL},
|
2015-08-17 18:23:37 +02:00
|
|
|
{NULL,0,NULL,0}
|
2015-08-16 16:12:29 +02:00
|
|
|
};
|
|
|
|
|
2015-09-06 12:18:55 +02:00
|
|
|
static void show_usage ()
|
|
|
|
{
|
|
|
|
sprintf (conbuf, "Usage: kpm [option...]\n");
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
|
|
|
|
sprintf (conbuf, ("\
|
|
|
|
Options:\n\
|
|
|
|
--list-packages\n\
|
|
|
|
show available packages\n"));
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
|
|
|
|
sprintf (conbuf, ("\
|
|
|
|
--list-installed\n\
|
|
|
|
show available packages\n"));
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
|
|
|
|
sprintf (conbuf, ("\
|
|
|
|
--install all\n\
|
|
|
|
install all packages\n"));
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
};
|
|
|
|
|
2015-08-16 09:53:30 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-08-17 18:23:37 +02:00
|
|
|
LIST_HEAD(server_list);
|
|
|
|
LIST_HEAD(download_list);
|
|
|
|
LIST_HEAD(cache_list);
|
|
|
|
LIST_HEAD(local_list);
|
|
|
|
LIST_HEAD(task_list);
|
|
|
|
|
2015-08-16 09:53:30 +02:00
|
|
|
int count;
|
2015-08-16 10:48:26 +02:00
|
|
|
char *cache_path;
|
2015-08-16 16:12:29 +02:00
|
|
|
char *tmp_path;
|
2015-09-06 12:18:55 +02:00
|
|
|
int act = 1;
|
2015-08-16 09:53:30 +02:00
|
|
|
|
|
|
|
if(http_init())
|
|
|
|
goto err_init;
|
|
|
|
|
2015-08-17 18:23:37 +02:00
|
|
|
set_cwd("/tmp0/1");
|
|
|
|
|
2015-08-17 12:31:03 +02:00
|
|
|
con_init(80, 25, 80, 250, "Kolibri package manager");
|
|
|
|
|
2015-08-16 16:12:29 +02:00
|
|
|
tmp_path = make_tmp_path("packages.xml");
|
2015-08-16 10:48:26 +02:00
|
|
|
|
2015-08-16 16:12:29 +02:00
|
|
|
count = http_load_file(tmp_path, make_url("packages.xml"));
|
2015-08-16 09:53:30 +02:00
|
|
|
|
|
|
|
if(count)
|
2015-08-17 18:23:37 +02:00
|
|
|
build_server_list(&server_list, tmp_path);
|
|
|
|
|
2015-09-06 12:18:55 +02:00
|
|
|
while(act)
|
2015-08-17 18:23:37 +02:00
|
|
|
{
|
|
|
|
int val;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
val = getopt_long_only(argc, argv,"",longopts, &index);
|
|
|
|
|
|
|
|
switch(val)
|
|
|
|
{
|
|
|
|
case OPTION_LIST_PACKAGES:
|
|
|
|
sprintf(conbuf,"available packages:\n\n");
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
print_pkg_list(&server_list);
|
2015-09-06 12:18:55 +02:00
|
|
|
act = 0;
|
|
|
|
break;
|
2015-08-17 18:23:37 +02:00
|
|
|
|
|
|
|
case OPTION_LIST_INSTALLED:
|
|
|
|
sprintf(conbuf,"installed packages:\n\n");
|
|
|
|
con_write_asciiz(conbuf);
|
|
|
|
print_pkg_list(&local_list);
|
2015-09-06 12:18:55 +02:00
|
|
|
act = 0;
|
|
|
|
break;
|
2015-08-17 18:23:37 +02:00
|
|
|
|
2015-09-06 12:18:55 +02:00
|
|
|
case OPTION_INSTALL_ALL:
|
|
|
|
copy_list(&task_list, &server_list);
|
|
|
|
process_task(&task_list);
|
|
|
|
act = 0;
|
2015-08-17 18:23:37 +02:00
|
|
|
break;
|
2015-09-06 12:18:55 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
show_usage();
|
|
|
|
act = 0;
|
2015-08-17 18:23:37 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-17 12:31:03 +02:00
|
|
|
con_exit(0);
|
2015-08-16 09:53:30 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_init:
|
|
|
|
printf("HTTP library initialization failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2015-08-16 18:59:54 +02:00
|
|
|
|