-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdevpkg.c
153 lines (123 loc) · 3.49 KB
/
devpkg.c
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
/*
This program assists in fetching, building, and installing software packages
Copyright (C) 2014 Zed A. Shaw
2014 Guus Bonnema Copied program in Jan 2014 from Zed Shaw
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <apr_general.h>
#include <apr_getopt.h>
#include <apr_strings.h>
#include <apr_lib.h>
#include "dbg.h"
#include "db.h"
#include "commands.h"
int main(int argc, const char const *argv[])
{
apr_pool_t *p = NULL;
apr_pool_initialize();
apr_pool_create(&p, NULL);
apr_getopt_t *opt;
apr_status_t rv;
int rc = 0;
char ch = '\0';
const char *optarg = NULL;
const char *config_opts = NULL;
const char *install_opts = NULL;
const char *make_opts = NULL;
const char *prebuild = NULL;
const char *url = NULL;
enum CommandType request = COMMAND_NONE;
rv = apr_getopt_init(&opt, p, argc, argv);
while((rv = apr_getopt(opt, "I:Lc:m:i:p:d:SF:B:", &ch, &optarg)) == APR_SUCCESS) {
switch (ch) {
case 'I':
request = COMMAND_INSTALL;
url = optarg;
break;
case 'L':
request = COMMAND_LIST;
break;
case 'c':
config_opts = optarg;
break;
case 'm':
make_opts = optarg;
break;
case 'i':
install_opts = optarg;
break;
case 'p':
prebuild = optarg;
break;
case 'S':
request = COMMAND_INIT;
break;
case 'F':
request = COMMAND_FETCH;
url = optarg;
break;
case 'B':
request = COMMAND_BUILD;
url = optarg;
break;
}
}
check(rv == APR_EOF, "Unknown parameters provided.");
switch(request) {
case COMMAND_INSTALL:
check(url, "You must at least give a URL.");
rc = Command_install(p, url, config_opts, make_opts, install_opts, prebuild);
check(rc == 0, "Failed to install the software.");
break;
case COMMAND_LIST:
rc = DB_list();
break;
case COMMAND_FETCH:
check(url, "You must give a URL.");
rc = Command_fetch(p, url, 1);
check(rc == 0, "Failed to fetch the software.");
log_info("Downloaded to %s and in /tmp/", BUILD_DIR);
break;
case COMMAND_BUILD:
check(url, "You must at least give a URL.");
rc = Command_build(p, url, config_opts, make_opts, install_opts, prebuild);
check(rc == 0, "Failed to build the software.");
break;
case COMMAND_INIT:
rv = DB_init();
check(rv == 0, "Failed to make the database.");
break;
default:
sentinel("\nUSAGE: devpkg <command> [<options>]"
"\n"
"\n\tCommands:"
"\n\t-I <url> \tInstall package from <url>"
"\n\t-L\t\tList installed packages"
"\n\t-S\t\tInitialize package database"
"\n\t-F <url>\tFetch package from <url>"
"\n\t-B <url>\tBuild package from <url>"
"\n\n\tinstall options:"
"\n\t-c <config-opts>"
"\n\t-m <make-opts>"
"\n\t-i <install-opts>"
"\n\t-p <prebuild-scriptname>"
"\n\t-d # Not implemented yet"
"\n"
);
}
apr_pool_terminate();
return 0;
error:
apr_pool_terminate();
return -1;
}