ns-chroot (1074B)
1 #!/bin/sh 2 3 basen="$(basename "$0")" 4 dounprepare=0 5 6 if [ "$basen" != "ns-chroot" ]; 7 then 8 nsrootn="$basen" 9 [ $# -gt 1 ] && [ "$1" = "-u" ] && dounprepare=1 && shift 1 10 else 11 if [ $# -lt 1 ]; 12 then 13 printf "usage: %s [-u] ns [cmd]\n" "$(basename $0)" >&2 14 exit 1 15 fi 16 [ $# -gt 1 ] && [ "$1" = "-u" ] && dounprepare=1 && shift 1 17 18 nsrootn="$1" 19 shift 1 20 fi 21 22 if [ -z "$nsrootn" ]; 23 then 24 printf "usage: %s [-u] ns [cmd]\n" "$(basename $0)" >&2 25 exit 1 26 fi 27 28 curdir="$(pwd)" 29 30 nsroot="$(ns-root "$nsrootn")" 31 [ $? -gt 0 ] && exit $? 32 33 [ -e "$nsroot/.ns/rc.conf" ] && . "$nsroot/.ns/rc.conf" 34 if [ -n "$SHBIN" ]; 35 then 36 cmd="$SHBIN" 37 else 38 cmd="/bin/sh" 39 fi 40 [ $# -gt 0 ] && cmd="$1" && shift 1 41 42 ns-prepare "$nsroot" 43 [ $? -gt 0 ] && exit 1 44 45 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin" 46 if [ ! -d "${nsroot}${curdir}" ]; 47 then 48 capchroot "$nsroot" $cmd -- "$@" 49 else 50 capchroot -d "$curdir" "$nsroot" $cmd -- "$@" 51 fi 52 53 if [ $dounprepare -eq 1 ]; 54 then 55 ns-unprepare "$nsroot" 56 else 57 lsof "$nsroot" >/dev/null 2>&1 58 [ $? -gt 0 ] && ns-unprepare "$nsroot" 59 fi 60 61 exit 0 62