aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-08-14 13:35:10 +0100
committerRon Yorston <rmy@pobox.com>2020-08-14 13:35:10 +0100
commitc775e9de197afe1cc0907f559f7cab36d52c93fa (patch)
treee54777d3dee69e72891409c945f76f5e3c95c991
parent41ef232fc522d91f29931ea4ee547432ca8899ee (diff)
downloadbusybox-w32-c775e9de197afe1cc0907f559f7cab36d52c93fa.tar.gz
busybox-w32-c775e9de197afe1cc0907f559f7cab36d52c93fa.tar.bz2
busybox-w32-c775e9de197afe1cc0907f559f7cab36d52c93fa.zip
busybox: add option to install to Unix-style paths
The command 'busybox --install -u' installs links to Unix-style paths in the system drive.
-rw-r--r--applets/applet_tables.c2
-rw-r--r--libbb/appletlib.c45
2 files changed, 35 insertions, 12 deletions
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index 02352113f..ce2037440 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
@@ -190,7 +190,7 @@ int main(int argc, char **argv)
190 printf("};\n\n"); 190 printf("};\n\n");
191#endif 191#endif
192 192
193#if ENABLE_FEATURE_INSTALLER && !ENABLE_PLATFORM_MINGW32 193#if ENABLE_FEATURE_INSTALLER
194 printf("const uint8_t applet_install_loc[] ALIGN1 = {\n"); 194 printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
195 i = 0; 195 i = 0;
196 while (i < NUM_APPLETS) { 196 while (i < NUM_APPLETS) {
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index d2f98567e..35f577b89 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -717,7 +717,6 @@ static void check_suid(int applet_no)
717 717
718 718
719# if ENABLE_FEATURE_INSTALLER 719# if ENABLE_FEATURE_INSTALLER
720# if !ENABLE_PLATFORM_MINGW32
721static const char usr_bin [] ALIGN1 = "/usr/bin/"; 720static const char usr_bin [] ALIGN1 = "/usr/bin/";
722static const char usr_sbin[] ALIGN1 = "/usr/sbin/"; 721static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
723static const char *const install_dir[] = { 722static const char *const install_dir[] = {
@@ -730,6 +729,7 @@ static const char *const install_dir[] = {
730# endif 729# endif
731}; 730};
732 731
732# if !ENABLE_PLATFORM_MINGW32
733/* create (sym)links for each applet */ 733/* create (sym)links for each applet */
734static void install_links(const char *busybox, int use_symbolic_links, 734static void install_links(const char *busybox, int use_symbolic_links,
735 char *custom_install_dir) 735 char *custom_install_dir)
@@ -768,13 +768,24 @@ static void install_links(const char *busybox,
768{ 768{
769 char *fpc; 769 char *fpc;
770 const char *appname = applet_names; 770 const char *appname = applet_names;
771 int rc; 771 const char *sd = custom_install_dir == NULL ? get_system_drive() : NULL;
772 int i, rc;
772 773
773 if (!is_directory(custom_install_dir, FALSE)) 774 if (custom_install_dir && !is_directory(custom_install_dir, FALSE))
774 bb_error_msg_and_die("'%s' is not a directory", custom_install_dir); 775 bb_error_msg_and_die("'%s' is not a directory", custom_install_dir);
775 776
776 while (*appname) { 777 if (custom_install_dir == NULL) {
777 fpc = xasprintf("%s/%s.exe", custom_install_dir, appname); 778 for (i=1; i<ARRAY_SIZE(install_dir); ++i) {
779 fpc = xasprintf("%s%s", sd ?: "", install_dir[i]);
780 bb_make_directory(fpc, 0755, FILEUTILS_RECUR);
781 free(fpc);
782 }
783 }
784
785 for (i = 0; i < ARRAY_SIZE(applet_main); i++) {
786 fpc = xasprintf("%s%s/%s.exe", sd ?: "",
787 custom_install_dir ?: install_dir[APPLET_INSTALL_LOC(i)],
788 appname);
778 rc = link(busybox, fpc); 789 rc = link(busybox, fpc);
779 if (rc != 0 && (errno != EEXIST || 790 if (rc != 0 && (errno != EEXIST ||
780 strcmp("busybox.exe", bb_basename(fpc)) != 0)) { 791 strcmp("busybox.exe", bb_basename(fpc)) != 0)) {
@@ -897,7 +908,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
897 " or: busybox --install [-s] [DIR]\n" 908 " or: busybox --install [-s] [DIR]\n"
898 ) 909 )
899 IF_PLATFORM_MINGW32( 910 IF_PLATFORM_MINGW32(
900 " or: busybox --install [DIR]\n" 911 " or: busybox --install [-u|DIR]\n"
901 " or: busybox --uninstall [-n] file\n" 912 " or: busybox --uninstall [-n] file\n"
902 ) 913 )
903 ) 914 )
@@ -981,6 +992,7 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
981 else 992 else
982 str = " "; 993 str = " ";
983 full_write2_str(str); 994 full_write2_str(str);
995 full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
984 } 996 }
985# endif 997# endif
986 full_write2_str(a); 998 full_write2_str(a);
@@ -1015,12 +1027,23 @@ int busybox_main(int argc UNUSED_PARAM, char **argv)
1015 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv); 1027 use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
1016 install_links(busybox, use_symbolic_links, argv[2]); 1028 install_links(busybox, use_symbolic_links, argv[2]);
1017#else 1029#else
1018 /* busybox --install [DIR] 1030 char *target = NULL;
1019 * where DIR is the directory to install to. If DIR is not 1031
1020 * provided put the links in the same directory as busybox. 1032 /* busybox --install [-u|DIR]
1033 * -u: install to Unix-style directories in system drive
1034 * DIR: directory to install links to
1035 * If no argument is provided put the links in the same directory
1036 * as busybox.
1021 */ 1037 */
1022 install_links(bb_busybox_exec_path, FALSE, argv[2] ? argv[2] : 1038 if (argv[2]) {
1023 dirname(xstrdup(bb_busybox_exec_path))); 1039 if (strcmp(argv[2], "-u") != 0)
1040 target = argv[2];
1041 }
1042 else {
1043 target = dirname(xstrdup(bb_busybox_exec_path));
1044 }
1045 /* NULL target -> install to Unix-style dirs */
1046 install_links(bb_busybox_exec_path, FALSE, target);
1024#endif 1047#endif
1025 return 0; 1048 return 0;
1026 } 1049 }