Building your own Termux with a custom package name

hc
4 min readDec 8, 2021

--

Termux is an awesome Android app which emulates a linux environment. It allows you to run command line applications which is very useful for deployment.

In my latest project, I needed to use Termux but with a new package name. A simple refactoring of com.termux wasn’t enough to get the application to work properly.

Here I document the steps that I took to get my own package name to work.

1. Downloading the Termux Source

First we clone the termux-app. Open the project with Android Studio.

git clone https://github.com/termux/termux-app

Next, refactor com.termux and rename it to a new package name for example com.mytermux

Then we will edit all occurrence of com.termux to com.mytermux and com_termux to com_mytermux.

That is all for the renaming part.

Next, in the app’s build.gradlefile, add a return statement under task downloadBootstra().

task downloadBootstraps() {
return;
doLast {
def version = "2021.06.30-r1"
downloadBootstrap("aarch64", "ce56ce9a4e8845bd1d35cc2695bbdd636c72625ee10ce21c9b98ab38ebbee5ab", version)
downloadBootstrap("arm", "537e81951c7d3d3f3def9ce6778e1032457488e21edb2c037a1e0e680c39e747", version)
downloadBootstrap("i686", "3c2ca858c0225671c00c44ac182e31819ffa93ec624e95e02824e7d6d30ca1b4", version)
downloadBootstrap("x86_64", "93c50d36b45bca42bb014395e8e184e5b540adcad5d4e215f7e64ebf0d655d2b", version)
}
}

This will prevent the bootstraping process to download from the official termux servers. Instead it will use the local files we are going to build.

2. Building our bootstrap-{arch}.zip

The next step is to prepare our bootstrap packages which is used to setup when we install termux.

This process is very important as termux packages when built, have hardcoded path names.

Lets clone the package repository at termux-packages.

git clone https://github.com/termux/termux-packages.git

Next download build-bootstrap.shand put it in the folder termux-packages/scripts. This script is used to build termux packages locally instead of using the apt repository method. Doing so it means that you will not be able to do apt install package_name on your termux build.

wget https://gist.github.com/seeya/a9ce074cf560aa7113043859360b7bfc/raw/206b5f4755b65569cf4af8d92b2481258c134b74/build-bootstrap.sh

Next we need to edit /termux-packages/scripts/properties.sh.

Look for the variable TERMUX_APP_PACKAGE and set it to your package name.

TERMUX_APP_PACKAGE="com.mytermux"

Next, lets use docker as our environment to build our packages.

./scripts/run-docker.sh

Once ran, you should see your terminal showing something like this.

builder@533f0f18e289:~/termux-packages

This means that you are in the docker container. Now we can build our packages. For this example, I’m building the package vim for the architecture arm. Change it according to your needs.

./build-package.sh -a arm vim

Once built, you should find a vim_8.2.3700.deb inside outputs folder. You can build for packages and once done we will prepare our bootstrap-arm.zip. Doing so will ensure that all packages we built previously be available once the application is installed on the device.

./scripts/build-bootstrap.sh --architectures arm

This will start the building process and may take awhile. Depending on your computer’s speed, it could take up to 30 minutes.

Once completed you should see something like this.

  ...  
adding: var/lib/dpkg/info/findutils.md5sums (deflated 62%)
adding: var/lib/dpkg/info/docbook-xml.list (deflated 95%)
adding: var/lib/dpkg/info/findutils.list (deflated 85%)
adding: var/lib/dpkg/info/tmux.md5sums (deflated 53%)
adding: var/lib/dpkg/info/xsltproc.list (deflated 79%)
adding: var/lib/dpkg/info/ca-certificates-java.md5sums (stored 0%)
adding: var/lib/dpkg/alternatives/ (stored 0%)
adding: var/log/ (stored 0%)
adding: var/log/apt/ (stored 0%)
adding: var/service/ (stored 0%)
adding: var/service/sshd/ (stored 0%)
adding: var/service/sshd/down (stored 0%)
adding: var/service/sshd/run (deflated 5%)
adding: var/service/sshd/log/ (stored 0%)
adding: var/service/tor/ (stored 0%)
adding: var/service/tor/down (stored 0%)
adding: var/service/tor/run (deflated 5%)
adding: var/service/tor/log/ (stored 0%)
[*] Finished successfully (arm).

Now if you check your directory, there will be a file bootstrap-arm.zip generated.

builder@533f0f18e289:~/termux-packages$ ll
total 77664
drwxrwxr-x 11 builder builder 4096 Dec 8 17:18 ./
drwxr-xr-x 1 builder builder 4096 Dec 8 09:54 ../
-rw-rw-r-- 1 builder builder 245 Dec 8 08:03 BACKERS.md
-rw-r--r-- 1 builder builder 79365148 Dec 8 17:18 bootstrap-arm.zip
-rwxrwxr-x 1 builder builder 2632 Dec 8 08:03 build-all.sh*
-rwxrwxr-x 1 builder builder 19809 Dec 8 08:03 build-package.sh*
-rwxrwxr-x 1 builder builder 1254 Dec 8 08:03 clean.sh*
-rw-rw-r-- 1 builder builder 5391 Dec 8 08:03 CODEOWNERS
-rw-rw-r-- 1 builder builder 12134 Dec 8 08:03 CONTRIBUTING.md
drwxr-xr-x 2 builder builder 4096 Dec 8 09:12 debs/
drwxrwxr-x 38 builder builder 4096 Dec 8 08:03 disabled-packages/
drwxrwxr-x 8 builder builder 4096 Dec 8 08:03 .git/
-rw-rw-r-- 1 builder builder 404 Dec 8 08:03 .gitattributes
drwxrwxr-x 5 builder builder 4096 Dec 8 08:03 .github/
-rw-rw-r-- 1 builder builder 249 Dec 8 08:03 .gitignore
-rw-rw-r-- 1 builder builder 503 Dec 8 08:03 LICENSE.md
drwxrwxr-x 2 builder builder 4096 Dec 8 08:03 ndk-patches/
drwxr-xr-x 2 builder builder 12288 Dec 8 14:11 output/
drwxrwxr-x 1109 builder builder 32768 Dec 8 08:03 packages/
-rw-rw-r-- 1 builder builder 1932 Dec 8 08:03 README.md
drwxrwxr-x 2 builder builder 4096 Dec 8 08:03 sample/
drwxrwxr-x 4 builder builder 4096 Dec 8 17:13 scripts/

3. Building the Termux App

Now, we can extract the file and put it into our Termux:App in the folder /app/src/main/cpp/bootstrap-arm.zip.

To prevent any issues, do clean the project first and put the bootstrap-arm.zip in the folder.

Now build the project and you will see termux being built and intialized successfully!

Notes

Below are some notes which could prove useful if you’re on this topic.

  1. ./scripts/generate-bootstraps.sh — used when you want to go the apt route to install packages.
  2. /scripts/build-bootstraps.sh — is not found in the official repository. It’s gotten from https://github.com/termux/termux-app/issues/1983#issuecomment-812965326. With a slight modification to fix the output path of the debs being built.
  3. In order to use Termux:Boot, use the same signingConfigs on both application.
  4. https://gitter.im/termux/dev — very helpful community. Special thanks to agnostic-apollo who helped me along the way.

--

--

Responses (1)