aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Beppu <beppu@lbox.org>2000-06-27 04:50:02 +0000
committerJohn Beppu <beppu@lbox.org>2000-06-27 04:50:02 +0000
commit8f425dbf9a8af9d3ee9848a18a641a93d9fe039b (patch)
tree923bb7b84d2d450eb0c2a0598e4cbb0e6163fad7
parent83a949cb225e5f327929c8911010cd947ffd08d5 (diff)
downloadbusybox-w32-8f425dbf9a8af9d3ee9848a18a641a93d9fe039b.tar.gz
busybox-w32-8f425dbf9a8af9d3ee9848a18a641a93d9fe039b.tar.bz2
busybox-w32-8f425dbf9a8af9d3ee9848a18a641a93d9fe039b.zip
+ busybox --install [-s]
is almost good to go. Here is my work in progress. + Look at the FIXME in busybox.c to see what I need. The actual (sym)linking is disabled for now, although I'm sure it works ;) (Am I going to have to dig through /proc to find out where the currently running busybox is sitting?) + I put an #ifdef BB_FEATURE_INSTALLER around the new bits of code in busybox.c, and I have a #define BB_FEATURE_INSTALLER in busybox.def.h towards the bottom.
-rw-r--r--applets/busybox.c74
-rw-r--r--busybox.c74
-rw-r--r--busybox.def.h5
3 files changed, 153 insertions, 0 deletions
diff --git a/applets/busybox.c b/applets/busybox.c
index 84629d218..78f07e338 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -358,6 +358,60 @@ const struct BB_applet applets[] = {
358}; 358};
359 359
360 360
361#ifdef BB_FEATURE_INSTALLER
362/*
363 * directory table
364 * this should be consistent w/ the enum, internal.h::Location,
365 * or else...
366 */
367static char* install_dir[] = {
368 "/",
369 "/bin",
370 "/sbin",
371 "/usr/bin",
372 "/usr/sbin",
373 NULL
374};
375
376/* abstract link() */
377typedef int (*__link_f)(const char *, const char *);
378
379/* create (sym)links for each applet */
380int install_links(const char *busybox, int use_symbolic_links)
381{
382 __link_f Link = link;
383
384 char command[256];
385 int i;
386 int rc = 0;
387
388 if (use_symbolic_links) Link = symlink;
389
390 for (i = 0; applets[i].name != NULL; i++) {
391 sprintf (
392 command,
393 "%s/%s",
394 install_dir[applets[i].location],
395 applets[i].name
396 );
397#if 0
398 rc |= Link(busybox, command);
399#else
400 puts(command);
401#endif
402 if (rc) {
403 fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
404 break;
405 }
406 }
407 return rc;
408}
409
410#if 0
411int uninstall_links() ?
412#endif
413#endif /* BB_FEATURE_INSTALLER */
414
361 415
362int main(int argc, char **argv) 416int main(int argc, char **argv)
363{ 417{
@@ -365,6 +419,26 @@ int main(int argc, char **argv)
365 char *name; 419 char *name;
366 const struct BB_applet *a = applets; 420 const struct BB_applet *a = applets;
367 421
422#ifdef BB_FEATURE_INSTALLER
423 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
424 int use_symbolic_links = 0;
425
426 /* to use symlinks, or to not use symlinks... */
427 if (argc > 2) {
428 if ((strcmp(argv[2], "-s") == 0)) {
429 use_symbolic_links = 1;
430 }
431 }
432 /*
433 * FIXME :
434 * I need a clever unix trick that'll tell
435 * me where to find the currently running
436 * busybox binary
437 */
438 return install_links("/bin/busybox", use_symbolic_links);
439 }
440#endif /* BB_FEATURE_INSTALLER */
441
368 for (s = name = argv[0]; *s != '\0';) { 442 for (s = name = argv[0]; *s != '\0';) {
369 if (*s++ == '/') 443 if (*s++ == '/')
370 name = s; 444 name = s;
diff --git a/busybox.c b/busybox.c
index 84629d218..78f07e338 100644
--- a/busybox.c
+++ b/busybox.c
@@ -358,6 +358,60 @@ const struct BB_applet applets[] = {
358}; 358};
359 359
360 360
361#ifdef BB_FEATURE_INSTALLER
362/*
363 * directory table
364 * this should be consistent w/ the enum, internal.h::Location,
365 * or else...
366 */
367static char* install_dir[] = {
368 "/",
369 "/bin",
370 "/sbin",
371 "/usr/bin",
372 "/usr/sbin",
373 NULL
374};
375
376/* abstract link() */
377typedef int (*__link_f)(const char *, const char *);
378
379/* create (sym)links for each applet */
380int install_links(const char *busybox, int use_symbolic_links)
381{
382 __link_f Link = link;
383
384 char command[256];
385 int i;
386 int rc = 0;
387
388 if (use_symbolic_links) Link = symlink;
389
390 for (i = 0; applets[i].name != NULL; i++) {
391 sprintf (
392 command,
393 "%s/%s",
394 install_dir[applets[i].location],
395 applets[i].name
396 );
397#if 0
398 rc |= Link(busybox, command);
399#else
400 puts(command);
401#endif
402 if (rc) {
403 fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
404 break;
405 }
406 }
407 return rc;
408}
409
410#if 0
411int uninstall_links() ?
412#endif
413#endif /* BB_FEATURE_INSTALLER */
414
361 415
362int main(int argc, char **argv) 416int main(int argc, char **argv)
363{ 417{
@@ -365,6 +419,26 @@ int main(int argc, char **argv)
365 char *name; 419 char *name;
366 const struct BB_applet *a = applets; 420 const struct BB_applet *a = applets;
367 421
422#ifdef BB_FEATURE_INSTALLER
423 if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
424 int use_symbolic_links = 0;
425
426 /* to use symlinks, or to not use symlinks... */
427 if (argc > 2) {
428 if ((strcmp(argv[2], "-s") == 0)) {
429 use_symbolic_links = 1;
430 }
431 }
432 /*
433 * FIXME :
434 * I need a clever unix trick that'll tell
435 * me where to find the currently running
436 * busybox binary
437 */
438 return install_links("/bin/busybox", use_symbolic_links);
439 }
440#endif /* BB_FEATURE_INSTALLER */
441
368 for (s = name = argv[0]; *s != '\0';) { 442 for (s = name = argv[0]; *s != '\0';) {
369 if (*s++ == '/') 443 if (*s++ == '/')
370 name = s; 444 name = s;
diff --git a/busybox.def.h b/busybox.def.h
index 9742241c2..4c74910d7 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -230,6 +230,11 @@
230//#define BB_FEATURE_INSMOD_VERSION_CHECKING 230//#define BB_FEATURE_INSMOD_VERSION_CHECKING
231// 231//
232// 232//
233// Enable busybox --install [-s]
234// to create links (or symlinks) for all the commands that are
235// compiled into the binary.
236#define BB_FEATURE_INSTALLER
237//
233// End of Features List 238// End of Features List
234// 239//
235// 240//