nodejs-current: Update from 9.7.1 to 9.8.0
[termux-packages] / packages / proot / termux-chroot
CommitLineData
5a979ce6
FF
1#!/bin/sh
2
2f90522a
OS
3SCRIPTNAME=termux-chroot
4show_usage () {
5 echo "Usage: $SCRIPTNAME [command]"
5a979ce6
FF
6 echo "termux-chroot: Setup a chroot to mimic a normal Linux file system"
7 echo ""
2f90522a
OS
8 echo "Execute a command in a chroot with traditional file system hierarchy"
9 echo "(having e.g. the folders /bin, /etc and /usr) within Termux."
10 echo "If run without argument, the default shell will be executed"
11 exit 0
12}
13
14while getopts :h option
15do
16 case "$option" in
17 h) show_usage;;
18 ?) echo "$SCRIPTNAME: illegal option -$OPTARG"; exit 1;
19 esac
20done
21shift $(($OPTIND-1))
5a979ce6
FF
22
23# For the /system/bin/linker(64) to be found:
24ARGS="-b /system:/system"
25
4480f511 26# On some devices /vendor is required for termux packages to work correctly
27# See https://github.com/termux/proot/issues/2#issuecomment-303995382
28ARGS="$ARGS -b /vendor:/vendor"
29
293296c4
FF
30# Bind /data to include system folders such as /data/misc. Also $PREFIX
31# and $HOME so that Termux programs with hard-coded paths continue to work:
32ARGS="$ARGS -b /data:/data"
33
d32d5a28
FF
34if [ -f /property_contexts ]; then
35 # Used by getprop (see https://github.com/termux/termux-packages/issues/1076)
36 # but does not exist on Android 8.
37 ARGS="$ARGS -b /property_contexts:/property_contexts"
38fi
5a979ce6 39
c491cc49
FF
40# Expose external and internal storage:
41if [ -d /storage ]; then
42 ARGS="$ARGS -b /storage:/storage"
43fi
44
5a979ce6
FF
45# Mimic traditional Linux file system hierarchy - /usr:
46ARGS="$ARGS -b $PREFIX:/usr"
47
48# Mimic traditional Linux file system hierarchy - other Termux dirs:
49for f in bin etc lib share tmp var; do
50 ARGS="$ARGS -b $PREFIX/$f:/$f"
51done
52
53# Mimic traditional Linux file system hierarchy- system dirs:
54for f in dev proc; do
55 ARGS="$ARGS -b /$f:/$f"
56done
57
58# Set /home as current directory:
59ARGS="$ARGS --cwd=/home"
60
61# Root of the file system:
62ARGS="$ARGS -r $PREFIX/.."
63
2f90522a
OS
64export HOME=/home
65
66# Shell to execute:
5a979ce6
FF
67PROGRAM=/bin/bash
68if [ -x $HOME/.termux/shell ]; then
69 PROGRAM=`readlink -f $HOME/.termux/shell`
70fi
2f90522a
OS
71# Execute shell if no command has been supplied
72if [ -z "$1" ];then
73 ARGS="$ARGS $PROGRAM -l"
74 exec $PREFIX/bin/proot $ARGS
75else
76 # When a command is executed directly instead of opening a shell run
77 # the command in the current working directory instead of in /home
78 ARGS="$ARGS --cwd=."
79 # Start supplied command with "sh -c" so things like these work:
80 # termux-chroot "make;make install"
81 # termux-chroot "SOME_CONFIG=value ./configure"
82 exec $PREFIX/bin/proot $ARGS sh -c "$*"
83fi