Giter VIP home page Giter VIP logo

termux-exec's Introduction

termux-exec

A execve() wrapper to fix problem with shebangs when running in Termux.

Problem

A lot of Linux software is written with the assumption that /bin/sh, /usr/bin/env and similar file exists. This is not the case on Android where neither /bin/ nor /usr/ exists.

When building packages for Termux those hard-coded assumptions are patched away - but this does not help with installing scripts and programs from other sources than Termux packages.

Solution

Create an execve() wrapper that rewrites calls to execute files under /bin/ and /usr/bin into the matching Termux executables under $PREFIX/bin/ and inject that into processes using LD_PRELOAD.

How to install

  1. Install with pkg install termux-exec.
  2. Exit your current session and start a new one.
  3. From now on shebangs such as /bin/sh and /usr/bin/env python should work.

Where is LD_PRELOAD set?

The $PREFIX/bin/login program which is used to create new Termux sessions checks for $PREFIX/lib/libtermux-exec.so and if so sets up LD_PRELOAD before launching the login shell.

termux-exec's People

Contributors

easyaspi314 avatar fornwall avatar grimler91 avatar ktprograms avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

termux-exec's Issues

termux-exec vs fixedshell

This Project seems to be very similar to https://github.com/its-pointless/fixedshell/. Both are probably based of rkeene's initial programm. But fixedshell is a little more advanced by now. At least it doesn't suffer from #2. Maybe the code of libandroid-fixshebang.c could replace the one from termux-exec.c?

I do like that termux-exec is always active, as opposed to fixedshell's activation script.

kubectl calls not rewritten

Not sure if there's a fix here but thought this was worth noting. In trying to get gcloud and kubectl working in termux, I found that gcloud works fine but not when called by kubectl:

$ which gcloud
/data/data/com.termux/files/usr/google-cloud-sdk/bin/gcloud
$ head -n1 /data/data/com.termux/files/usr/google-cloud-sdk/bin/gcloud
#!/bin/sh
$ gcloud config config-helper --format=json
{
  "configuration": {
    "active_configuration": "default",
...
$ kubectl get pod
Unable to connect to the server: error executing access token command "/data/data/com.termux/files/usr/google-cloud
-sdk/bin/gcloud config config-helper --format=json": err=fork/exec /data/data/com.termux/files/usr/google-cloud-sdk
/bin/gcloud: no such file or directory output= stderr=

If the hashbang in the gcloud script is changed to /data/data/com.termux/files/usr/bin/sh then the kubectl command works.

Note that this is the binary for kubectl at https://storage.googleapis.com/kubernetes-release/release/v1.10.5/bin/linux/amd64/kubectl (amd64 since I'm on a Chromebook). I haven't tried compiling it locally yet.

segfault on Android 6

I've just installed the latest termux from the play store and it is working fine on my Android 6 smartphone

Btw the preinstalled termux-exec package does not seem to work:
the LD_PRELOAD envvar is not set at login and if i set it manually i get segfauls when i try to run a shellscript...

"CANNOT LINK EXECUTABLE" error running other programs

After installing termux-exec, I get an error while running other programs (in this case aapt):

CANNOT LINK EXECUTABLE: "/data/data/com.termux/files/usr/lib/libtermux-exec.so" is 64-bit instead of 32-bit
page record for 0xf77a604c was not found (block_size=64)

Here's some system information if needed:

# os.arch
aarch64

$ getprop | grep cpu
[ro.product.cpu.abi]: [arm64-v8a]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: [arm64-v8a]

$ uname -a
Linux localhost 3.18.20-perf+ #1 SMP PREEMPT Fri Nov 18 20:06:08 CST 2016 aarch64 Android

Is it possible to support C99-style shebang-like interpreter directives?

There are a few languages that use only C/C++-style comments but doesn't fully support using shebangs such as Go.

Instead they use the first commented line as the interpreter directive.

Example

Go

//usr/bin/env go run "$0" "$@";exit $?

I'm using JBang which allows scripting in Java using the same syntax.

//usr/bin/env jbang "$0" "$@";exit $?

I tried editing the file but that didn't work.

termux-exec breaks proot

Proot usage is broken by the termux-exec injection mechanism.
This is reproducible by simply trying to use proot, as it complains that it cannot find "/bin/sh".
Also launching proot to some other shell not in /bin seems to work (still all /bin commands won't work).
There should be an environment variable or some other way to disable termux-exec when not needed.

Visibility of files created/managed by Termux to other applications such like Kodi

Hi!
I'm installing rclone on my Nvidia Shield TV with this Magisk Module:
https://github.com/Magisk-Modules-Repo/com.piyushgarg.rclone

Finally I could execute it (despite it's a 32bits arch) and I thought that I won when I saw the GDrive directories doing an "ls" command
image

But later, in Kodi I discovered that it has no visibility of anyone:
image

I tried a "chmod", and I was thinking with a "chown", because it seems like a permissions issue (as root is the owner of this folders as image shows:)
image
(by the way, interesting these "total 0" isn't it?)

But if I want to know the user that executes kodi, with an "ps aux | grep kodi" nothing is showed (and it seems here is not showing all the process of the Android System).
image

I'm a little lost at this point, so I was wondering If I could get some recomendation from your expertise.
Thanks a lot for advance and have a nice day!

Exec(...) Permission denied

Hey,
I installed node-red on my phone. I can run it with the command node-red. Now I want to start it by a widget or after booting. I created a file which says node-red in the .shortcuts directory but after I tabed on the widget this error message popped up
exec("/data/data/com.termux/files/home/.shortcuts/node-red"): Permission denied [Process completed (code 1) - press Enter]
The programming mosquitto worked with this method, whiteout problems.
Where is the problem and how can I solve it? Or is there another way to run node red after booting?
Sorry for my bad English, I am a student from Germany...

How to debug

I have the package installed (version 1:0.8) but when I try to call Ruby's bundle command I'm getting:

zsh: /data/data/com.termux/files/home/.rbenv/shims/bundle: bad interpreter: /usr/bin/env: no such file or directory

So I guess something is weird in my config.

Is there something like termux-exec doctor equivalent? ๐Ÿ˜‰
Are there any environment variables that I should check?

PS: Thank you for your work!

Removes arguments from all scripts

$ cat test
#!/data/data/com.termux/files/usr/bin/sh
echo "$1"
$ ./test "Hello World"
Hello World
$ apt install termux-exec
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  termux-exec
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 2200 B of archives.
After this operation, 36.9 kB of additional disk space will be used.
Get:1 http://termux.net stable/main aarch64 termux-exec aarch64 0.1 [2200 B]
Fetched 2200 B in 0s (22.9 kB/s)
Selecting previously unselected package termux-exec.
(Reading database ... 58497 files and directories currently installed.)
Preparing to unpack .../termux-exec_0.1_aarch64.deb ...
Unpacking termux-exec (0.1) ...
Setting up termux-exec (0.1) ...
$ login
$ ./test "Hello World"

$ 

termux-exec not found

$ pkg install termux-exec
Reading package lists... Done Building dependency tree
Reading state information... Done termux-exec is already the newest version (0.4-1). 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
$ termux-exec
No command termux-exec found, did you mean: Command termux-open in package termux-tools
$ termux-info
Packages CPU architecture:
arm Subscribed repositories:

sources.list

deb https://termux.org/packages/ stable main

science-repo (sources.list.d/science.list)

deb https://dl.bintray.com/grimler/science-packages-24 science stable

sources.list.d/pointless.list deb https://its-pointless.github.io/files/24 termux extras

game-repo (sources.list.d/game.list)

deb https://dl.bintray.com/grimler/game-packages-24 games stable
Updatable packages:
All packages up to date
Android version:
9
Kernel build information:
Linux localhost 4.4.111-16046393 #1 SMP PREEMPT Wed Oct 9 14:44:51 KST 2019 armv8l Android
Device manufacturer:
samsung
Device model:
SM-A105FN

CANNOT LINK EXECUTABLE when using su.

$ su -c input keyevent 26
CANNOT LINK EXECUTABLE "/system/bin/dex2oat": "/data/data/com.termux/files/usr/lib/libtermux-exec.so" is 64-bit instead of 32-bit

Maybe LD_PRELOAD needs to be cleared by su?

Altough I am not sure clearing that variable is the best solution, as it is also used by various other programs. Most notably torsocks, tsocks and proxychains. Maybe we need to remove termux-exec from the variable while leaving other paths behind.

Termux-exec allows execution of programs lacking permissions

Termux-exec ignores missing permissions of a file. It allows files that don't have executive permissions to be executed anyway. This only happens when the file has a shebang that requires termux-exec. Normal termux-shebangs still give the correct 'permission denied'.

$ cat test.sh
#!/bin/sh
echo Hello World
$ ./test.sh
Hello World
$ chmod -x test.sh
$ ./test.sh
Hello World
$ ls -l test.sh
-rw------- 1 u0_a401 u0_a401 27 Sep 28 10:48 test.sh
$ termux-fix-shebang test.sh
$ ./test.sh
zsh: permission denied: ./test.s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.