1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <zstd.h>
#include <stdio.h>
#include <sodium.h>
#include <pkgman.h>
#include <um.h>
#include <err.h>
#include <parser.h>
#include <lib/sv.h>
#include <net.h>
#include <lib/url.h>
/**
* Install package:
* pkgman install <package_name>
*
* Remove package:
* pkgman remove <package_name>
*
* Update:
* pkgman update
* pkgman update <package_name>
*
* Kernel Update:
* pkgman kupdate
*
* Fetch:
* pkgman fetch <query>
*
* Pack:
* pkgman pack <directory>
*
* System:
* pkgman system install
*/
void install_usage()
{
printf("-------------------------------\n");
printf("Package Manager Install Command\n");
printf("command:\n");
printf(" pkgman install <pkg1> ... <pkgn>\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 <pkg>\n");
printf(" pkgman build\n");
printf(" pkgman update <pkg?>\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;
}
|