3
0

install.sh 2.5 KB

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