Skip to content

Commit 83d6dc2

Browse files
Added: Add site, docs and old changelog files under MIT license
Related commit 24f60904
1 parent 8429bfb commit 83d6dc2

File tree

23 files changed

+1257
-81
lines changed

23 files changed

+1257
-81
lines changed

LICENSE

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ Files:
77
Comment:
88
The `termux-exec` repository is released under the `Apache-2.0` license, unless specified
99
differently in a file/directory or in any additional `Files` sections below.
10-
License: [Apache-2.0](licenses/termux__termux-exec-package__Apache-2.0.md)
10+
License: [Apache-2.0](licenses/termux__termux-exec-package__Aache-2.0.md)
11+
12+
Files:
13+
site/*
14+
License: [MIT](licenses/termux__termux-exec-package__MIT.md)

README.md

+10-80
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,23 @@
1-
# termux-exec
2-
A `execve()` wrapper to fix two problems with exec-ing files in Termux.
1+
# termux-exec-package
32

4-
# Problem 1: Cannot execute files not part of the APK
5-
Android 10 started blocking executing files under the app data directory, as
6-
that is a [W^X](https://en.wikipedia.org/wiki/W%5EX) violation - files should be either
7-
writeable or executable, but not both. Resources:
3+
The [`termux-exec`](https://github.com/termux/termux-exec) package provides a shared library that is meant to be preloaded with [`LD_PRELOAD`](https://man7.org/linux/man-pages/man8/ld.so.8.html) for proper functioning of the Termux execution environment.
84

9-
- [Google Android issue](https://issuetracker.google.com/issues/128554619)
10-
- [Termux: No more exec from data folder on targetAPI >= Android Q](https://github.com/termux/termux-app/issues/1072)
11-
- [Termux: Revisit the Android W^X problem](https://github.com/termux/termux-app/issues/2155)
5+
### Contents
126

13-
While there is merit in that general principle, this prevents using Termux and Android
14-
as a general computing device, where it should be possible for users to create executable
15-
scripts and binaries.
7+
- [Project](#project)
168

17-
# Solution 1: Cannot execute files not part of the APK
18-
Create an `exec` interceptor using [LD_PRELOAD](https://en.wikipedia.org/wiki/DLL_injection#Approaches_on_Unix-like_systems),
19-
that instead of executing an ELF file directly, executes `/system/bin/linker64 /path/to/elf`.
20-
Explanation follows below.
9+
---
2110

22-
On Linux, the kernel is normally responsible for loading both the executable and the
23-
[dynamic linker](https://en.wikipedia.org/wiki/Dynamic_linker). The executable is invoked
24-
by file path with the [execve system call](https://en.wikipedia.org/wiki/Exec_(system_call)).
25-
The kernel loads the executable into the process, and looks for a `PT_INTERP` entry in
26-
its [ELF program header table](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#Program_header)
27-
of the file - this specifies the path to the dynamic linker (`/system/bin/linker64` for 64-bit Android).
11+
 
2812

29-
There is another way to load the two ELF objects:
30-
[since 2018](https://android.googlesource.com/platform/bionic/+/8f639a40966c630c64166d2657da3ee641303194)
31-
the dynamic linker can be invoked directly with `exec`.
32-
If passed the filename of an executable, the dynamic linker will load and run the executable itself.
33-
So, instead of executing `path/to/mybinary`, it's possible to execute
34-
`/system/bin/linker64 /absolute/path/to/mybinary` (the linker needs an absolute path).
3513

36-
This is what `termux-exec` does to circumvent the block on executing files in the data
37-
directory - the kernel sees only `/system/bin/linker64` being executed.
3814

39-
This also means that we need to extract [shebangs](https://en.wikipedia.org/wiki/Shebang_(Unix)). So for example, a call to execute:
4015

41-
```sh
42-
./path/to/myscript.sh <args>
43-
```
4416

45-
where the script has a `#!/path/to/interpreter` shebang, is replaced with:
17+
## Project
4618

47-
```sh
48-
/system/bin/linker64 /path/to/interpreter ./path/to/myscript.sh <args>
49-
```
19+
**Check the `termux-exec` project info [here](site/pages/en/projects/index.md), including `docs` and `releases` info.**
5020

51-
Implications:
21+
---
5222

53-
- It's important that `LD_PRELOAD` is kept - see e.g. [this change in sshd](https://github.com/termux/termux-packages/pull/18069).
54-
We could also consider patching this exec interception into the build process of termux packages, so `LD_PRELOAD` would not be necessary for packages built by the termux-packages repository.
55-
56-
- The executable will be `/system/bin/linker64`. So some programs that inspects the executable name (on itself or other programs) using `/proc/${PID}/exec` or `/proc/${PID}/comm` (where `$(PID}` could be `self`, for the current process) needs to be changed to instead inspect `argv0` of the process instead. See [this llvm driver change](https://github.com/termux/termux-packages/pull/18074) and [this pgrep/pkill change](https://github.com/termux/termux-packages/pull/18075).
57-
58-
- Statically linked binaries will not work. These are rare in Android and Termux, but zig currently produces statically linked binaries against musl libc.
59-
60-
- The interception using `LD_PRELOAD` will only work for programs using the [C library wrappers](https://linux.die.net/man/3/execve) for executing a new process, not when using the `execve` system call directly. Luckily most programs do use this. Programs using raw system calls needs to be patched or be run under [proot](https://wiki.termux.com/wiki/PRoot).
61-
62-
**NOTE**: The above example used `/system/bin/linker64` - on 32-bit systems, the corresponding
63-
path is `/system/bin/linker`.
64-
65-
**NOTE**: While this circumvents the technical restriction, it still might be considered
66-
violating [Google Play policy](https://support.google.com/googleplay/android-developer/answer/9888379).
67-
So this workaround is not guaranteed to enable Play store distribution of Termux - but it's
68-
worth an attempt, and regardless of Play store distribution, updating the targetSdk is necessary.
69-
70-
# Problem 2: Shebang paths
71-
A lot of Linux software is written with the assumption that `/bin/sh`, `/usr/bin/env`
72-
and similar file exists. This is not the case on Android where neither `/bin/` nor `/usr/`
73-
exists.
74-
75-
When building packages for Termux those hard-coded assumptions are patched away - but this
76-
does not help with installing scripts and programs from other sources than Termux packages.
77-
78-
# Solution 2: Shebang paths
79-
Create an `execve()` wrapper that rewrites calls to execute files under `/bin/` and `/usr/bin`
80-
into the matching Termux executables under `$PREFIX/bin/` and inject that into processes
81-
using `LD_PRELOAD`.
82-
83-
# How to install
84-
1. Install with `pkg install termux-exec`.
85-
2. Exit your current session and start a new one.
86-
3. From now on shebangs such as `/bin/sh` and `/usr/bin/env python` should work.
87-
88-
# Where is LD_PRELOAD set?
89-
The `$PREFIX/bin/login` program which is used to create new Termux sessions checks for
90-
`$PREFIX/lib/libtermux-exec.so` and if so sets up `LD_PRELOAD` before launching the login shell.
91-
92-
Soon, when making a switch to target Android 10+, this will be setup by the Termux app even before
93-
launching any process, as `LD_PRELOAD` will be necessary for anything non-system to execute.
23+
&nbsp;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MIT License
2+
3+
Copyright (c) 2023 termux
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+
- https://opensource.org/licenses/MIT
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
page_ref: "@ARK_PROJECT__VARIANT@/termux/termux-exec-package/docs/@ARK_DOC__VERSION@/developer/build/index.md"
3+
---
4+
5+
# termux-exec-package Build Docs
6+
7+
<!-- @ARK_DOCS__HEADER_PLACEHOLDER@ -->
8+
9+
The [`termux-exec`](https://github.com/termux/termux-exec) build instructions are available below. For install instructions, check [`install`](../../install/index.md) docs.
10+
11+
### Contents
12+
13+
- [Build Methods](#build-methods)
14+
15+
---
16+
17+
&nbsp;
18+
19+
20+
21+
22+
23+
## Build Methods
24+
25+
The `termux-exec` package provided by Termux is built from the [`termux/termux-exec`](https://github.com/termux/termux-exec) repository. It can be built with the following methods.
26+
27+
- [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure)
28+
- [On Device With `make`](#on-device-with-make)
29+
30+
**The [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure) is the recommended way to build `termux-exec`.** If the `termux-exec` package is built with the [Termux Packages Build Infrastructure](#termux-packages-build-infrastructure), then the Termux variable values in the `Makefile` are dynamically set to the values defined in the [`properties.sh`] file of the build infrastructure by passing them to `make` via the `$TERMUX_PKG_EXTRA_MAKE_ARGS` variable set in the [`packages/termux-exec/build.sh`] file. If `termux-exec` is built with `make` instead, then the hardcoded fallback/default Termux variable values in the `Makefile` will get used during build time, which may affect or break `termux-exec` at runtime if current app/environment is different from the Termux default one (`TERMUX_APP__PACKAGE_NAME=com.termux` and `TERMUX__ROOTFS=/data/data/com.termux/files`). However, if `make` must be used for some reason, and building for a different app/environment than the Termux default, like for a Termux fork or alternate package name/rootfs, then manually update the hardcoded values in the `Makefile` or manually pass the alternate values to the `make` command.
31+
32+
## &nbsp;
33+
34+
&nbsp;
35+
36+
37+
38+
### Termux Packages Infrastructure
39+
40+
To build the `termux-exec` package with the [`termux-packages`](https://github.com/termux/termux-packages) build infrastructure, the provided [`build-package.sh`](https://github.com/termux/termux-packages/blob/master/build-package.sh) script can be used. Check the [Build environment](https://github.com/termux/termux-packages/wiki/Build-environment) and [Building packages](https://github.com/termux/termux-packages/wiki/Building-packages) docs for how to build packages.
41+
42+
#### Default Sources
43+
44+
To build the `termux-exec` package from its default repository release tag or git branch sources that are used for building the package provided in Termux repositories, just clone the `termux-packages` repository and build.
45+
46+
```shell
47+
# Clone `termux-packages` repo and switch current working directory to it.
48+
git clone https://github.com/termux/termux-packages.git
49+
cd termux-packages
50+
51+
# (OPTIONAL) Run termux-packages docker container if running off-device.
52+
./scripts/run-docker.sh
53+
54+
# Force build package and download dependencies from Termux packages repositories.
55+
./build-package.sh -f -I termux-exec
56+
```
57+
58+
#### Local Sources
59+
60+
To build the `termux-exec` package from its local sources or a pull request branch, clone the `termux-packages` repository, clone/create the `termux-exec` repository locally, make required changes to the [`packages/termux-exec/build.sh`] file to update the source url and then build.
61+
62+
Check [Build Local Package](https://github.com/termux/termux-packages/wiki/Building-packages#build-local-package) and [Package Build Local Source URLs](https://github.com/termux/termux-packages/wiki/Creating-new-package#package-build-local-source-urls) docs for more info on how to building packages from local sources.*
63+
64+
```shell
65+
# Clone `termux-packages` repo and switch current working directory to it.
66+
git clone https://github.com/termux/termux-packages.git
67+
cd termux-packages
68+
69+
# Update `$TERMUX_PKG_SRCURL` variable in `packages/termux-exec/build.sh`.
70+
# We use `file:///path/to/source/dir` format for the local source URL.
71+
TERMUX_PKG_SRCURL=file:///home/builder/termux-packages/sources/termux-exec
72+
TERMUX_PKG_SHA256=SKIP_CHECKSUM
73+
74+
# Clone/copy `termux-exec` repo at `termux-packages/sources/termux-exec`
75+
# directory. Make sure current working directory is root directory of
76+
# termux-packages repo when cloning.
77+
git clone https://github.com/termux/termux-exec.git sources/termux-exec
78+
79+
# (OPTIONAL) Manually switch to different (pull) branch that exists on
80+
# origin if required, or to the one defined in $TERMUX_PKG_GIT_BRANCH
81+
# variable of build.sh file, as it will not be automatically checked out.
82+
# By default, the repo default/current branch that's cloned
83+
# will get built, which is usually `master` or `main`.
84+
# Whatever is the current state of the source directory will
85+
# be built as is, including any uncommitted changes to current
86+
# branch.
87+
(cd sources/termux-exec; git checkout <branch_name>)
88+
89+
# (OPTIONAL) Run termux-packages docker container if running off-device.
90+
./scripts/run-docker.sh
91+
92+
# Force build package and download dependencies from Termux packages repositories.
93+
./build-package.sh -f -I termux-exec
94+
```
95+
96+
## &nbsp;
97+
98+
&nbsp;
99+
100+
101+
102+
### On Device With `make`
103+
104+
To build `termux-exec` package on the device inside the Termux app with [`make`](https://www.gnu.org/software/make), check below. Do not use a PC to build the package as PC architecture may be different from target device architecture and the `clang` compiler wouldn't have been patched like Termux provided one is so that built packages are compatible with Termux, like patches done for `DT_RUNPATH`.
105+
106+
```shell
107+
# Install dependencies.
108+
pkg install clang git make termux-create-package
109+
110+
# Clone/copy `termux-exec` repo at `termux-exec` directory and switch
111+
# current working directory to it.
112+
git clone https://github.com/termux/termux-exec.git termux-exec
113+
cd termux-exec
114+
115+
# Whatever is the current state of the `termux-exec` directory will be built.
116+
# If required, manually switch to different (pull) branch that exists on origin.
117+
git checkout <branch_name>
118+
119+
# Remove any existing deb files in current directory.
120+
rm -f termux-exec_*.deb
121+
122+
# Build deb file for the architecture of the host device/clang compiler.
123+
make deb
124+
125+
# Install.
126+
# We use shell * glob expansion to automatically select the deb file
127+
# regardless of `_<version>_<arch>.deb` suffix, that's why existing
128+
# deb files were deleted earlier in case any existed with the wrong version.
129+
dpkg -i termux-exec_*.deb
130+
```
131+
132+
---
133+
134+
&nbsp;
135+
136+
137+
138+
139+
140+
[`packages/termux-exec/build.sh`]: https://github.com/termux/termux-packages/blob/master/packages/termux-exec/build.sh
141+
[`properties.sh`]: https://github.com/termux/termux-packages/blob/master/scripts/properties.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
page_ref: "@ARK_PROJECT__VARIANT@/termux/termux-exec-package/docs/@ARK_DOC__VERSION@/developer/contribute/index.md"
3+
---
4+
5+
# termux-exec-package Contribute Docs
6+
7+
<!-- @ARK_DOCS__HEADER_PLACEHOLDER@ -->
8+
9+
These docs are meant for you if you want to contribute to the [`termux/termux-exec`](https://github.com/termux/termux-exec) repository.
10+
11+
### Contents
12+
13+
- [Commit Messages Guidelines](#commit-messages-guidelines)
14+
15+
---
16+
17+
&nbsp;
18+
19+
20+
21+
22+
23+
## Commit Messages Guidelines
24+
25+
Commit messages **must** use the [Conventional Commits](https://www.conventionalcommits.org) spec so that changelogs can be automatically generated when [releases](../../../releases/index.md) are made as per the [Keep a Changelog](https://github.com/olivierlacan/keep-a-changelog) spec by the [`create-conventional-changelog`](https://github.com/termux/create-conventional-changelog) script, check its repository for further details on the spec.
26+
27+
**The first letter for `type` and `description` must be capital and description should be in the present tense.** The space after the colon `:` is necessary. For a breaking change, add an exclamation mark `!` before the colon `:` as an indicator, and it will also cause the change to be automatically highlighted in the changelog.
28+
29+
```
30+
<type>[optional scope]: <description>
31+
32+
[optional body]
33+
34+
[optional footer(s)]
35+
```
36+
37+
**Only the `types` listed below must be used exactly as they are used in the changelog headings.** For example, `Added: Add foo`, `Added|Fixed: Add foo and fix bar`, `Changed!: Change baz as a breaking change`, etc. You can optionally add a scope as well, like `Fixed(docs): Fix some bug`. **Do not use anything else as type, like `add` instead of `Added`, or `chore`, etc.**
38+
39+
- **Added** for new additions or features.
40+
- **Changed** for changes in existing functionality.
41+
- **Deprecated** for soon-to-be removed features.
42+
- **Fixed** for any bug fixes.
43+
- **Removed** for now removed features.
44+
- **Reverted** for changes that were reverted.
45+
- **Patched** for patches done for specific builds.
46+
- **Security** in case of vulnerabilities.
47+
- **Release** for when a new release is made.
48+
49+
---
50+
51+
&nbsp;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
page_ref: "@ARK_PROJECT__VARIANT@/termux/termux-exec-package/docs/@ARK_DOC__VERSION@/developer/index.md"
3+
---
4+
5+
# termux-exec-package Developer Docs
6+
7+
<!-- @ARK_DOCS__HEADER_PLACEHOLDER@ -->
8+
9+
These docs are meant for the developers, maintainers and contributors of the [`termux/termux-exec`](https://github.com/termux/termux-exec) repository and its forks.
10+
11+
### Contents
12+
13+
- [Build](build/index.md)
14+
- [Test](test/index.md)
15+
- [Contribute](contribute/index.md)
16+
17+
---
18+
19+
&nbsp;

0 commit comments

Comments
 (0)