3
0

install.sh 3.2 KB

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