#include #include #include #include #include #include #include #include #include #include #include #include #include /** * Install package: * pkgman install * * Remove package: * pkgman remove * * Update: * pkgman update * pkgman update * * Kernel Update: * pkgman kupdate * * Fetch: * pkgman fetch * * Pack: * pkgman pack * * System: * pkgman system install */ void install_usage() { printf("-------------------------------\n"); printf("Package Manager Install Command\n"); printf("command:\n"); printf(" pkgman install ... \n"); } int cmd_install(int argc, char **argv) { if (argc < 1) { install_usage(); return USAGE; } struct pkgman_config pc; pc.dir_tmp = "/tmp/pkgman"; pc.dir_staging = "/var/pkgman"; pc.upstream = "https://packages.0xinfinity.dev"; char *pkg = argv[0]; int ret = pkgman_upstream_check(&pc, pkg); TRY(ret == SUCCESS, ret); ret = pkgman_upstream_integrity_download(&pc, pkg); TRY(ret == SUCCESS, ret); ret = pkgman_install_pkg(&pc, pkg); TRY(ret == SUCCESS, ret); return SUCCESS; } int cmd_build(int argc, char** argv) { // ZSTD_compress("test", 60, "aaa.pkg", 30, 3); printf("NOT IMPLEMENTED: Build command issued!\n"); return SUCCESS; } int cmd_remove(int argc, char** argv) { printf("NOT IMPLEMENTED: Remove command issued!\n"); return SUCCESS; } typedef int (*cmd_fn)(int, char**); struct cmd_entry { struct string_view key; cmd_fn func; }; // First-level command table struct cmd_entry table[] = { { SV("build"), cmd_build }, { SV("install"), cmd_install }, { SV("remove"), cmd_remove }, { SV(NULL), NULL }, }; #define ARRAY_SIZE(x) sizeof((x)) / sizeof((x)[0]) void usage() { printf("-------------------------------\n"); printf("pkgman v0.0.1\n"); printf("-------------------------------\n"); printf("Available commands:\n"); printf(" pkgman install \n"); printf(" pkgman build\n"); printf(" pkgman update \n"); } int main(int argc, char **argv) { if (argc < 2) { usage(); return 0; } cmd_fn cmd_func = NULL; struct string_view argv1 = (struct string_view) {.buf = argv[1], .len = strlen(argv[1])}; for (int i = 0; i < ARRAY_SIZE(table); i++) { if (table[i].key.buf == NULL) break; if (sv_equal(&argv1, &table[i].key)) cmd_func = table[i].func; } if (cmd_func == NULL) { usage(); return 1; } if (net_init() != 0) { fprintf(stderr, "curl: network initialization error!"); return 1; } int ret = 1; if(argv[2] == NULL) ret = cmd_func(0, NULL); else ret = cmd_func(argc - 2, &argv[2]); if(ret != 0) printf("Command '%s' ended with error '%d' and/or usage screen.\n", argv[1], ret); net_shutdown(); return 0; }