install.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/bin/sh
  2. export LC_ALL=POSIX
  3. export LC_CTYPE=POSIX
  4. prefix=$1
  5. if [ -z "$prefix" ]; then
  6. echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
  7. exit 1
  8. fi
  9. # Source the configuration
  10. . ./.config
  11. h=`sort busybox.links | uniq`
  12. sharedlib_dir="0_lib"
  13. linkopts=""
  14. scriptwrapper="n"
  15. binaries="n"
  16. cleanup="0"
  17. noclobber="0"
  18. case "$2" in
  19. --hardlinks) linkopts="-f";;
  20. --symlinks) linkopts="-fs";;
  21. --binaries) binaries="y";;
  22. --scriptwrapper) scriptwrapper="y";swrapall="y";;
  23. --sw-sh-hard) scriptwrapper="y";linkopts="-f";;
  24. --sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
  25. --cleanup) cleanup="1";;
  26. --noclobber) noclobber="1";;
  27. "") h="";;
  28. *) echo "Unknown install option: $2"; exit 1;;
  29. esac
  30. if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
  31. # get the target dir for the libs
  32. # assume it starts with lib
  33. libdir=$($CC -print-file-name=libc.so | \
  34. sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
  35. if test -z "$libdir"; then
  36. libdir=/lib
  37. fi
  38. mkdir -p "$prefix/$libdir" || exit 1
  39. for i in $DO_INSTALL_LIBS; do
  40. rm -f "$prefix/$libdir/$i" || exit 1
  41. if [ -f "$i" ]; then
  42. echo " Installing $i to the target at $prefix/$libdir/"
  43. cp -pPR "$i" "$prefix/$libdir/" || exit 1
  44. chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
  45. fi
  46. done
  47. fi
  48. if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
  49. inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
  50. sub_shell_it=`
  51. cd "$prefix"
  52. for d in usr/sbin usr/bin sbin bin; do
  53. pd=$PWD
  54. if [ -d "$d" ]; then
  55. cd "$d"
  56. ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
  57. fi
  58. cd "$pd"
  59. done
  60. `
  61. exit 0
  62. fi
  63. rm -f "$prefix/bin/busybox" || exit 1
  64. mkdir -p "$prefix/bin" || exit 1
  65. install -m 755 busybox "$prefix/bin/busybox" || exit 1
  66. for i in $h; do
  67. appdir=`dirname "$i"`
  68. app=`basename "$i"`
  69. mkdir -p "$prefix/$appdir" || exit 1
  70. if [ "$scriptwrapper" = "y" ]; then
  71. if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
  72. ln $linkopts busybox "$prefix/$i" || exit 1
  73. else
  74. rm -f "$prefix/$i"
  75. echo "#!/bin/busybox" >"$prefix/$i"
  76. chmod +x "$prefix/$i"
  77. fi
  78. echo " $prefix/$i"
  79. elif [ "$binaries" = "y" ]; then
  80. # Copy the binary over rather
  81. if [ -e $sharedlib_dir/$app ]; then
  82. if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
  83. echo " Copying $sharedlib_dir/$app to $prefix/$i"
  84. cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
  85. else
  86. echo " $prefix/$i already exists"
  87. fi
  88. else
  89. echo "Error: Could not find $sharedlib_dir/$app"
  90. exit 1
  91. fi
  92. else
  93. if [ "$2" = "--hardlinks" ]; then
  94. bb_path="$prefix/bin/busybox"
  95. else
  96. case "$appdir" in
  97. /)
  98. bb_path="bin/busybox"
  99. ;;
  100. /bin)
  101. bb_path="busybox"
  102. ;;
  103. /sbin)
  104. bb_path="../bin/busybox"
  105. ;;
  106. /usr/bin | /usr/sbin)
  107. bb_path="../../bin/busybox"
  108. ;;
  109. *)
  110. echo "Unknown installation directory: $appdir"
  111. exit 1
  112. ;;
  113. esac
  114. fi
  115. if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
  116. echo " $prefix/$i -> $bb_path"
  117. ln $linkopts "$bb_path" "$prefix/$i" || exit 1
  118. else
  119. echo " $prefix/$i already exists"
  120. fi
  121. fi
  122. done
  123. exit 0