Guest User

Untitled

a guest
Apr 25th, 2011
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.91 KB | None | 0 0
  1. CHROOT=/var/www/vhosts/chroot/
  2. CHROOTMNG=/usr/local/psa/admin/sbin/chrootmng
  3.  
  4. # check configuration
  5. if [ ! -d "${CHROOT}" ]
  6. then
  7.         echo "Error: chroot does not exist, check configuration."
  8.         exit 1
  9. fi
  10.  
  11. if [ ! -f "${CHROOTMNG}" ]
  12. then
  13.         echo "Error: chrootmng not found, check configuration."
  14.         exit 1
  15. fi
  16.  
  17. # make sure binary is given
  18. if [ -z "$1" ]
  19. then
  20.         echo "usage: $(basename $0) <program> [target]"
  21.         exit 1
  22. fi
  23.  
  24. # check for target specification
  25. if [ -n "$2" ]
  26. then
  27.         TARGET=$2
  28.  
  29.         if [ ! -d "${TARGET}" ]
  30.         then
  31.                 echo "Error: not a valid target."
  32.                 exit 1
  33.         fi
  34. else
  35.         TARGET=${CHROOT}
  36. fi
  37.  
  38. # check whether path or name of binary was given
  39. if [ -f "$1" ]
  40. then
  41.         BINARY=$1
  42. else
  43.         BINARY=$(which $1)
  44. fi
  45.  
  46. # make sure binary exists
  47. if [ ! -f "${BINARY}" ]
  48. then
  49.         echo "Error: Could not find binary."
  50.         exit 1
  51. fi
  52.  
  53. # status
  54. echo "Binary: ${BINARY}"
  55. echo "Target: ${TARGET}"
  56.  
  57. # there is no specific target, remove all current chroot environments,
  58. # modify the skeleton, and recreate them
  59. if [ -z "$2" ]
  60. then
  61.         echo "Removing current chroot environments..."
  62.         ${CHROOTMNG} --remove --source=${CHROOT} --target=all
  63. fi
  64.  
  65. # copy the binary
  66.  
  67. echo "Adding binary to chroot..."
  68.  
  69. echo "  ${BINARY}"
  70. cp -p ${BINARY} ${TARGET}/${BINARY}
  71.  
  72. # copy necessary shared libraries
  73.  
  74. echo "Adding shared libraries to chroot..."
  75.  
  76. ldd ${BINARY} | sed -e "s/\S* => //" | awk '{print $1}' | while read LIB
  77. do
  78.         if [ -f "${LIB}" ]
  79.         then
  80.                 echo "  ${LIB}"
  81.                 cp -p ${LIB} ${TARGET}/${LIB}
  82.         fi
  83. done
  84.  
  85. # if the target is all, recreate all chroot environments
  86. if [ -z "$2" ]
  87. then
  88.         echo "Recreating chroot environments..."
  89.  
  90.         ${CHROOTMNG} --create --source=${CHROOT} --target=all
  91. fi
  92.  
  93. # binary added
  94. echo "Done."
Advertisement
Add Comment
Please, Sign In to add comment