install.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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]"
  7. exit 1;
  8. fi
  9. h=`sort busybox.links | uniq`
  10. cleanup="0"
  11. noclobber="0"
  12. case "$2" in
  13. --hardlinks) linkopts="-f";;
  14. --symlinks) linkopts="-fs";;
  15. --cleanup) cleanup="1";;
  16. --noclobber) noclobber="1";;
  17. "") h="";;
  18. *) echo "Unknown install option: $2"; exit 1;;
  19. esac
  20. if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
  21. # get the target dir for the libs
  22. # assume it starts with lib
  23. libdir=$($CC -print-file-name=libc.so | \
  24. sed -n 's%^.*\(/lib[^\/]*\)/libc.so%\1%p')
  25. if test -z "$libdir"; then
  26. libdir=/lib
  27. fi
  28. mkdir -p $prefix/$libdir || exit 1
  29. for i in $DO_INSTALL_LIBS; do
  30. rm -f $prefix/$libdir/$i || exit 1
  31. if [ -f $i ]; then
  32. cp -a $i $prefix/$libdir/ || exit 1
  33. chmod 0644 $prefix/$libdir/$i || exit 1
  34. fi
  35. done
  36. fi
  37. if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
  38. inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
  39. sub_shell_it=`
  40. cd "$prefix"
  41. for d in usr/sbin usr/bin sbin bin ; do
  42. pd=$PWD
  43. if [ -d "$d" ]; then
  44. cd $d
  45. ls -iL . | grep "^ *$inode" | awk '{print $2}' | env -i xargs rm -f
  46. fi
  47. cd "$pd"
  48. done
  49. `
  50. fi
  51. rm -f $prefix/bin/busybox || exit 1
  52. mkdir -p $prefix/bin || exit 1
  53. install -m 755 busybox $prefix/bin/busybox || exit 1
  54. for i in $h ; do
  55. appdir=`dirname $i`
  56. mkdir -p $prefix/$appdir || exit 1
  57. if [ "$2" = "--hardlinks" ]; then
  58. bb_path="$prefix/bin/busybox"
  59. else
  60. case "$appdir" in
  61. /)
  62. bb_path="bin/busybox"
  63. ;;
  64. /bin)
  65. bb_path="busybox"
  66. ;;
  67. /sbin)
  68. bb_path="../bin/busybox"
  69. ;;
  70. /usr/bin|/usr/sbin)
  71. bb_path="../../bin/busybox"
  72. ;;
  73. *)
  74. echo "Unknown installation directory: $appdir"
  75. exit 1
  76. ;;
  77. esac
  78. fi
  79. if [ "$noclobber" = "0" ] || [ ! -e "$prefix$i" ]; then
  80. echo " $prefix$i -> $bb_path"
  81. ln $linkopts $bb_path $prefix$i || exit 1
  82. else
  83. echo " $prefix$i already exists"
  84. fi
  85. done
  86. exit 0