install.sh 2.4 KB

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