+ busybox --install [-s]
authorJohn Beppu <beppu@lbox.org>
Tue, 27 Jun 2000 04:50:02 +0000 (04:50 -0000)
committerJohn Beppu <beppu@lbox.org>
Tue, 27 Jun 2000 04:50:02 +0000 (04:50 -0000)
  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.

applets/busybox.c
busybox.c
busybox.def.h

index 84629d2..78f07e3 100644 (file)
@@ -358,6 +358,60 @@ const struct BB_applet applets[] = {
 };
 
 
+#ifdef BB_FEATURE_INSTALLER
+/* 
+ * directory table
+ *      this should be consistent w/ the enum, internal.h::Location,
+ *      or else...
+ */
+static char* install_dir[] = {
+    "/",
+    "/bin",
+    "/sbin",
+    "/usr/bin",
+    "/usr/sbin",
+       NULL
+};
+
+/* abstract link() */
+typedef int (*__link_f)(const char *, const char *);
+
+/* create (sym)links for each applet */
+int install_links(const char *busybox, int use_symbolic_links)
+{
+    __link_f Link = link;
+
+    char       command[256];
+       int             i;
+       int             rc = 0;
+
+       if (use_symbolic_links) Link = symlink;
+
+    for (i = 0; applets[i].name != NULL; i++) {
+        sprintf (
+                       command, 
+                       "%s/%s", 
+                       install_dir[applets[i].location], 
+                       applets[i].name
+               );
+#if 0
+        rc |= Link(busybox, command);
+#else
+        puts(command);
+#endif
+               if (rc) {
+                       fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
+                       break;
+               }
+    }
+       return rc;
+}
+
+#if 0
+int uninstall_links() ?
+#endif
+#endif /* BB_FEATURE_INSTALLER */
+
 
 int main(int argc, char **argv)
 {
@@ -365,6 +419,26 @@ int main(int argc, char **argv)
        char                            *name;
        const struct BB_applet  *a              = applets;
 
+#ifdef BB_FEATURE_INSTALLER    
+       if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
+               int use_symbolic_links = 0;
+
+               /* to use symlinks, or to not use symlinks... */
+               if (argc > 2) {
+                       if ((strcmp(argv[2], "-s") == 0)) { 
+                               use_symbolic_links = 1; 
+                       }
+               }
+               /* 
+                * FIXME : 
+                * I need a clever unix trick that'll tell
+                * me where to find the currently running
+                * busybox binary
+                */
+               return install_links("/bin/busybox", use_symbolic_links);
+       }
+#endif /* BB_FEATURE_INSTALLER */
+
        for (s = name = argv[0]; *s != '\0';) {
                if (*s++ == '/')
                        name = s;
index 84629d2..78f07e3 100644 (file)
--- a/busybox.c
+++ b/busybox.c
@@ -358,6 +358,60 @@ const struct BB_applet applets[] = {
 };
 
 
+#ifdef BB_FEATURE_INSTALLER
+/* 
+ * directory table
+ *      this should be consistent w/ the enum, internal.h::Location,
+ *      or else...
+ */
+static char* install_dir[] = {
+    "/",
+    "/bin",
+    "/sbin",
+    "/usr/bin",
+    "/usr/sbin",
+       NULL
+};
+
+/* abstract link() */
+typedef int (*__link_f)(const char *, const char *);
+
+/* create (sym)links for each applet */
+int install_links(const char *busybox, int use_symbolic_links)
+{
+    __link_f Link = link;
+
+    char       command[256];
+       int             i;
+       int             rc = 0;
+
+       if (use_symbolic_links) Link = symlink;
+
+    for (i = 0; applets[i].name != NULL; i++) {
+        sprintf (
+                       command, 
+                       "%s/%s", 
+                       install_dir[applets[i].location], 
+                       applets[i].name
+               );
+#if 0
+        rc |= Link(busybox, command);
+#else
+        puts(command);
+#endif
+               if (rc) {
+                       fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
+                       break;
+               }
+    }
+       return rc;
+}
+
+#if 0
+int uninstall_links() ?
+#endif
+#endif /* BB_FEATURE_INSTALLER */
+
 
 int main(int argc, char **argv)
 {
@@ -365,6 +419,26 @@ int main(int argc, char **argv)
        char                            *name;
        const struct BB_applet  *a              = applets;
 
+#ifdef BB_FEATURE_INSTALLER    
+       if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
+               int use_symbolic_links = 0;
+
+               /* to use symlinks, or to not use symlinks... */
+               if (argc > 2) {
+                       if ((strcmp(argv[2], "-s") == 0)) { 
+                               use_symbolic_links = 1; 
+                       }
+               }
+               /* 
+                * FIXME : 
+                * I need a clever unix trick that'll tell
+                * me where to find the currently running
+                * busybox binary
+                */
+               return install_links("/bin/busybox", use_symbolic_links);
+       }
+#endif /* BB_FEATURE_INSTALLER */
+
        for (s = name = argv[0]; *s != '\0';) {
                if (*s++ == '/')
                        name = s;
index 9742241..4c74910 100644 (file)
 //#define BB_FEATURE_INSMOD_VERSION_CHECKING
 //
 //
+// Enable busybox --install [-s]
+// to create links (or symlinks) for all the commands that are 
+// compiled into the binary.
+#define BB_FEATURE_INSTALLER
+//
 // End of Features List
 //
 //