Last active
August 10, 2016 10:51
-
-
Save szepeviktor/9516285 to your computer and use it in GitHub Desktop.
nginx Chroot Helper Script To Copy Libs To /lib64 and /usr/lib64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Use this script to copy shared (libs) files to nginx chrooted | |
# jail server. This is tested on 64 bit Linux (Redhat and Friends only) | |
# ---------------------------------------------------------------------------- | |
# Original Written by Vivek Gite <http://www.cyberciti.biz/> | |
# (c) 2006 nixCraft under GNU GPL v2.0+ | |
# ---------------------------------------------------------------------------- | |
# See url for usage: | |
# http://www.cyberciti.biz/faq/howto-run-nginx-in-a-chroot-jail/ | |
# ---------------------------------------------------------------------------- | |
sync_dependencies() { | |
local JAILROOT="$1" | |
local pFILE="$2" | |
local files="" | |
local _cp="/bin/cp" | |
files="$(ldd "$pFILE" | sed 's|^\s*\(.* => \)*\(.*\) (0x[0-9a-f]\+)$|\2|')" | |
for LIB in $files | |
do | |
LIBDIR="$(dirname "$LIB")" | |
[ -d "${JAILROOT}${LIBDIR}" ] || mkdir -vp "${JAILROOT}${LIBDIR}" | |
"${_cp}" -vf "$LIB" "${JAILROOT}${LIBDIR}" | |
done | |
# Works with 32 and 64 bit ld-linux | |
sldl="$(ldd "$pFILE" | grep 'ld-linux' | awk '{ print $1}')" | |
sldlsubdir="$(dirname "${sldl}")" | |
[ -d "${JAILROOT}${sldlsubdir}" ] || mkdir -vp "${JAILROOT}${sldlsubdir}" | |
[ -f "${JAILROOT}${sldl}" ] || "${_cp}" -vf "${sldl}" "${JAILROOT}${sldlsubdir}" | |
} | |
usage() { | |
echo "Syntax : $0 /var/chroot /usr/local/nginx/sbin/nginx" >&2 | |
echo "Example: $0 /home/user /usr/bin/php5-cgi" >&2 | |
exit 1 | |
} | |
[ $# = 2 ] || usage | |
BASE="$1" | |
BINARY="$2" | |
[ -d "$BASE" ] || usage | |
[ -f "$BINARY" ] || usage | |
sync_dependencies "$BASE" "$BINARY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment