summaryrefslogtreecommitdiffstats
path: root/urunlevel/my_linux/getpkg.c
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/my_linux/getpkg.c')
-rw-r--r--urunlevel/my_linux/getpkg.c240
1 files changed, 240 insertions, 0 deletions
diff --git a/urunlevel/my_linux/getpkg.c b/urunlevel/my_linux/getpkg.c
new file mode 100644
index 0000000..9127c45
--- /dev/null
+++ b/urunlevel/my_linux/getpkg.c
@@ -0,0 +1,240 @@
1/*
2 * Mini getpkg implementation for busybox.
3 *
4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 *
21 */
22
23#include <string.h>
24#include <errno.h>
25#include <unistd.h>
26#include <sys/utsname.h> /* for uname(2) */
27
28#include "busybox.h"
29#include "lib_init_d.h"
30#include "my_linux.h"
31
32
33#define GETPKG_OPT_ALL 1
34#define GETPKG_OPT_FILE 2
35#define GETPKG_OPT_KERNEL 4
36
37
38void init_package(char *temp)
39{
40 if (stat(temp, &path_stat) == 0)
41 {
42 doit(0, "chmod a+x %s 2> /dev/null", temp);
43 bb_printf("Initializing %s\n", temp);
44 doit(0, "%s 2> /dev/null", temp);
45 }
46}
47
48
49static char *DEFAULT_PACKAGES =
50"LIB\n"
51"system\n"
52"baselib\n"
53"term\n"
54"modutil\n"
55"swaputil\n"
56"bash2\n"
57"pthread\n"
58"mc\n"
59"ext2tools\n"
60"sysutil\n"
61"fileutil\n"
62"diskutil\n"
63"modutils\n"
64"portmap\n"
65"openssh\n"
66"links";
67
68static char *DEFAULT_SERVERS =
69"ftp://0.0.0.0/distros/Linux-on-net/Trinux/pkg/\n"
70"ftp://192.168.146.25/distros/Linux-on-net/Trinux/pkg/\n"
71"http://0.0.0.0/ftp/distros/Linux-on-net/Trinux/pkg/\n"
72"http://www.trinux.org/pkg/\n"
73"http://www.io.com/~mdfranz/trinux/pkg/";
74
75static char *DEFAULT_PATHS =
76"/trinux/pkg\n"
77"/trinux/bootpkg\n"
78"/trinux/kpkg\n"
79"/trinux\n"
80"/pkg";
81
82static llist_t *package_head = NULL; /* growable list of packages */
83static llist_t *source_head = NULL; /* growable list of sources */
84
85
86int get_package(int opt, char *source, char *package, const char *KERNEL)
87{
88 int result = 0;
89 int incomplete = 0;
90 char *PACKAGE = 0;
91 char *PRE = 0;
92 char *temp = "";
93
94 if (strcmp(&package[bb_strlen(package) - 4], ".tgz") != 0)
95 temp = ".tgz";
96
97 bb_xasprintf(&PACKAGE, "%s%s%s", KERNEL, package, temp);
98 bb_xasprintf(&PRE, "%s%s", KERNEL, package);
99
100 if (opt & GETPKG_OPT_FILE)
101 {
102 temp = concat_path_file(source, PACKAGE);
103 free(PACKAGE);
104 PACKAGE = temp;
105 bb_printf("Installing %s\n", PACKAGE);
106 }
107 else
108 {
109 char *URL;
110
111 temp = concat_path_file("/tmp", PACKAGE);
112 bb_xasprintf(&URL, "%s%s", source, PACKAGE);
113 free(PACKAGE);
114 PACKAGE = temp;
115
116//bb_printf("Retrieving %s\n", URL);
117 doit(0, "wget -O %s %s", PACKAGE, URL);
118 if (errno)
119 incomplete = 1;
120
121 free(URL);
122 }
123
124 temp = "";
125 if ((incomplete == 0) && (stat(PACKAGE, &path_stat) == 0))
126 {
127 bb_xasprintf(&temp, doit(0, "gunzip -c %s | tar xvf -", PACKAGE));
128 result = 1;
129 if (!(opt & GETPKG_OPT_FILE))
130 remove_file(PACKAGE, FILEUTILS_FORCE);
131 }
132 doit(0, "echo \"%s\" > /var/lib/my_linux/contents/%s", temp, PRE);
133
134 if (result)
135 {
136 free(temp);
137 bb_xasprintf(&temp, "/etc/init.d/%s", PRE);
138 init_package(temp);
139 temp[10] = 'm';
140 init_package(temp);
141 free(temp);
142 bb_xasprintf(&temp, "/etc/pkg/%s", PRE);
143 init_package(temp);
144 }
145
146 free(temp);
147 free(PACKAGE);
148 return result;
149}
150
151
152int getpkg_main(int argc, char **argv)
153{
154 int i;
155 unsigned long opt;
156 char *PACKAGE = 0;
157 char *KERNEL = "";
158 char *SRC = 0;
159 char *token;
160 char *strtok_temp;
161
162 opt = bb_getopt_ulflags(argc, argv, "afk");
163
164 if (argv[optind])
165 PACKAGE = argv[optind++];
166 if (argv[optind])
167 SRC = argv[optind++];
168 if (PACKAGE == 0)
169 opt |= GETPKG_OPT_ALL;
170 if (opt & GETPKG_OPT_KERNEL)
171 {
172 struct utsname name;
173
174 if (uname(&name) == -1)
175 bb_perror_msg_and_die("cannot get system information");
176 bb_xasprintf(&KERNEL, "%s/", name.release);
177 }
178
179 if (opt & GETPKG_OPT_ALL)
180 {
181 if (PACKAGE != 0)
182 {
183 SRC = PACKAGE;
184 PACKAGE = 0;
185 }
186 PACKAGE = quick_read("/var/lib/my_linux/config/pkglist");
187 if ((PACKAGE == 0) || (PACKAGE[0] == '\0'))
188 {
189 PACKAGE = (char *) xmalloc (sizeof (char) * bb_strlen(DEFAULT_PACKAGES) + 1);
190 strcpy(PACKAGE, DEFAULT_PACKAGES);
191 }
192 }
193
194 if (SRC == 0)
195 {
196 SRC = quick_read("/var/lib/my_linux/config/server");
197 if ((SRC == 0) || (SRC[0] == '\0'))
198 {
199 if (opt & GETPKG_OPT_FILE)
200 token = DEFAULT_PATHS;
201 else
202 token = DEFAULT_SERVERS;
203 SRC = (char *) xmalloc (sizeof (char) * bb_strlen(token) + 1);
204 strcpy(SRC, token);
205 }
206 }
207
208 token = strtok_r(PACKAGE, " \r\n", &strtok_temp);
209 for (i = 0; token != NULL; i++)
210 {
211 package_head = llist_add_to_end(package_head, token);
212 token = strtok_r(NULL, " \r\n", &strtok_temp);
213 }
214
215 token = strtok_r(SRC, " \r\n", &strtok_temp);
216 for (i = 0; token != NULL; i++)
217 {
218 source_head = llist_add_to_end(source_head, token);
219 token = strtok_r(NULL, " \r\n", &strtok_temp);
220 }
221
222
223 llist_t *package_current = package_head;
224 while (package_current)
225 {
226 int found = 0;
227 llist_t *source_current = source_head;
228
229 while (source_current)
230 {
231 if ((found = get_package(opt, source_current->data, package_current->data, KERNEL)))
232 break;
233 source_current = source_current->link;
234 }
235
236 package_current = package_current->link;
237 }
238
239 return EXIT_SUCCESS;
240}