X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/293296c44f7621fce86caaf577f9f9437e6c8bc2..e912ee0f1ba2a77b53be6d50fe0619146c982fd4:/packages/proot/termux-chroot diff --git a/packages/proot/termux-chroot b/packages/proot/termux-chroot index 0e2c560a..7e49a42c 100755 --- a/packages/proot/termux-chroot +++ b/packages/proot/termux-chroot @@ -1,12 +1,24 @@ #!/bin/sh -if [ $# != 0 ]; then +SCRIPTNAME=termux-chroot +show_usage () { + echo "Usage: $SCRIPTNAME [command]" echo "termux-chroot: Setup a chroot to mimic a normal Linux file system" echo "" - echo "Execute without arguments to run a chroot with traditional file system" - echo "hierarchy (having e.g. the folders /bin, /etc and /usr) within Termux." - exit -fi + echo "Execute a command in a chroot with traditional file system hierarchy" + echo "(having e.g. the folders /bin, /etc and /usr) within Termux." + echo "If run without argument, the default shell will be executed" + exit 0 +} + +while getopts :h option +do + case "$option" in + h) show_usage;; + ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1; + esac +done +shift $(($OPTIND-1)) # For the /system/bin/linker(64) to be found: ARGS="-b /system:/system" @@ -19,8 +31,11 @@ ARGS="$ARGS -b /vendor:/vendor" # and $HOME so that Termux programs with hard-coded paths continue to work: ARGS="$ARGS -b /data:/data" -# Used by getprop (see https://github.com/termux/termux-packages/issues/1076): -ARGS="$ARGS -b /property_contexts:/property_contexts" +if [ -f /property_contexts ]; then + # Used by getprop (see https://github.com/termux/termux-packages/issues/1076) + # but does not exist on Android 8. + ARGS="$ARGS -b /property_contexts:/property_contexts" +fi # Expose external and internal storage: if [ -d /storage ]; then @@ -46,12 +61,23 @@ ARGS="$ARGS --cwd=/home" # Root of the file system: ARGS="$ARGS -r $PREFIX/.." -# Program to execute: +export HOME=/home + +# Shell to execute: PROGRAM=/bin/bash if [ -x $HOME/.termux/shell ]; then PROGRAM=`readlink -f $HOME/.termux/shell` fi -ARGS="$ARGS $PROGRAM -l" - -export HOME=/home -$PREFIX/bin/proot $ARGS +# Execute shell if no command has been supplied +if [ -z "$1" ];then + ARGS="$ARGS $PROGRAM -l" + exec $PREFIX/bin/proot $ARGS +else + # When a command is executed directly instead of opening a shell run + # the command in the current working directory instead of in /home + ARGS="$ARGS --cwd=." + # Start supplied command with "sh -c" so things like these work: + # termux-chroot "make;make install" + # termux-chroot "SOME_CONFIG=value ./configure" + exec $PREFIX/bin/proot $ARGS sh -c "$*" +fi