Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunCommandService : TermuxService terminates before command completion #2081

Closed
bilalilyas90 opened this issue May 23, 2021 · 40 comments
Closed

Comments

@bilalilyas90
Copy link

Following is the code which I am executing from my app .... command executes successfully but it exits before completion i.e it doesn't download the packages fully using pkg install commands and exits the service.

            Intent intent = new Intent();
            intent.setClassName("com.termux", "com.termux.app.RunCommandService");
            intent.setAction("com.termux.RUN_COMMAND");
            intent.putExtra("com.termux.RUN_COMMAND_PATH",      "/data/data/com.termux/files/usr/bin/pkg");
            intent.putExtra("com.termux.RUN_COMMAND_BACKGROUND", true);
            intent.putExtra("com.termux.RUN_COMMAND_ARGUMENTS", new String[]{"install -y jq gettext curl openssh"});
            startService(intent);

this is the output from logcat

2021-05-24 03:32:27.250 28306-7451/com.termux I/termux-task: [7448] starting: [/data/data/com.termux/files/usr/bin/pkg, install -y jq gettext curl openssh]
2021-05-24 03:32:29.643 28306-7451/com.termux I/termux-task: [7448] stdout: Checking availability of current mirror: ok
2021-05-24 03:32:29.659 28306-7450/com.termux I/termux-task: [7448] stderr:
2021-05-24 03:32:29.659 28306-7450/com.termux I/termux-task: [7448] stderr: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2021-05-24 03:32:29.659 28306-7450/com.termux I/termux-task: [7448] stderr:
2021-05-24 03:32:32.627 28306-7451/com.termux I/termux-task: [7448] stdout: Get:1 https://k51qzi5uqu5dg9vawh923wejqffxiu9bhqlze5f508msk0h7ylpac27fdgaskx.ipns.dweb.link stable InRelease [14.0 kB]
2021-05-24 03:32:35.393 28306-7451/com.termux I/termux-task: [7448] stdout: Hit:2 https://grimler.se/game-packages-24 games InRelease
2021-05-24 03:32:35.558 28306-7451/com.termux I/termux-task: [7448] stdout: Hit:3 https://grimler.se/science-packages-24 science InRelease
2021-05-24 03:32:35.683 28306-7451/com.termux I/termux-task: [7448] stdout: Fetched 14.0 kB in 6s (2333 B/s)
2021-05-24 03:32:35.707 28306-7451/com.termux I/termux-task: [7448] stdout: Reading package lists...
2021-05-24 03:32:35.711 28306-7451/com.termux I/termux-task: [7448] stdout: Building dependency tree...
2021-05-24 03:32:35.711 28306-7451/com.termux I/termux-task: [7448] stdout: Reading state information...
2021-05-24 03:32:35.711 28306-7451/com.termux I/termux-task: [7448] stdout: All packages are up to date.
2021-05-24 03:32:35.716 28306-7450/com.termux I/termux-task: [7448] stderr:
2021-05-24 03:32:35.716 28306-7450/com.termux I/termux-task: [7448] stderr: WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
2021-05-24 03:32:35.716 28306-7450/com.termux I/termux-task: [7448] stderr:
2021-05-24 03:32:35.723 28306-7451/com.termux I/termux-task: [7448] stdout: Reading package lists...
2021-05-24 03:32:35.724 28306-7451/com.termux I/termux-task: [7448] stdout: Building dependency tree...
2021-05-24 03:32:35.724 28306-7451/com.termux I/termux-task: [7448] stdout: Reading state information...
2021-05-24 03:32:35.727 28306-7451/com.termux I/termux-task: [7448] stdout: The following package was automatically installed and is no longer required:
2021-05-24 03:32:35.727 28306-7451/com.termux I/termux-task: [7448] stdout: oniguruma
2021-05-24 03:32:35.727 28306-7451/com.termux I/termux-task: [7448] stdout: Use 'apt autoremove' to remove it.
2021-05-24 03:32:35.728 28306-7451/com.termux I/termux-task: [7448] stdout: 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2021-05-24 03:32:35.729 28306-7451/com.termux I/termux-task: [7448] exited normally

Any help please?

@agnostic-apollo
Copy link
Member

This is not a bug in RunCommandService, you are passing a single argument to pkg with the value install -y jq gettext curl openssh, all of which gets consumed by pkg script as part of add|i* when read as CMD="$1", leaving no arguments for apt install, which then prints out 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

You need to do

new String[]{"install", "-y", "jq", "gettext", "curl", "openssh"}

@bilalilyas90
Copy link
Author

Thank you so much ... it is working now 👍

One more question @agnostic-apollo
can we run multiple commands within a service ?
like after pkg commands I want to run curl commands ... so like in above example we define com.termux.RUN_COMMAND_PATH as for pkg ... what if we need to run multiple commands with different command_path??

@agnostic-apollo
Copy link
Member

agnostic-apollo commented May 24, 2021

Welcome.

Set executable to bash, instead of pkg and arguments to

new String[]{"-c", "pkg install -y jq gettext curl openssh; curl -s url; command 3;"}

You must add a semi-colon ; after each command. But this will need escaping of double quotes, etc for complex commands. Instead, use bash as executable, do not pass arguments extra, and pass any multi-line bash script as is in RUN_COMMAND_SERVICE.EXTRA_STDIN. Will require Termux app version >= 0.109.

Check https://github.com/termux/termux-app/wiki/RUN_COMMAND-Intent#run_command-intent-command-extras

@bilalilyas90
Copy link
Author

Thank you again @agnostic-apollo ... all is understood now from wiki link you shared :)

One more issue just appeared when I updated termux app and please can you help me with this also ...

Following is the output from termux terminal

Welcome to Termux!

Community forum: https://termux.com/community
Gitter chat: https://gitter.im/termux/termux
IRC channel: #termux on freenode

Working with packages:

  • Search packages: pkg search
  • Install a package: pkg install
  • Upgrade packages: pkg upgrade

Subscribing to additional repositories:

  • Root: pkg install root-repo
  • Unstable: pkg install unstable-repo
  • X11: pkg install x11-repo

Report issues at https://termux.com/issues

The Google Play version of the Termux app no longer
receives updates. For more information, visit:
https://wiki.termux.com/wiki/Termux_Google_Play

cp: cannot stat '/data/data/com.termux/files/home/.termux/termux.properties': Permission denied
~ $ termux-storage-get
The program termux-storage-get is not installed. Install it by executing:
pkg install termux-api
~ $ value="true"; key="allow-external-apps"; file="/data/data/com.termux/files/home/.termux/termux.properties"; mkdir -p "$(dirname "$file")"; chmod 700 "$(dirname "$file")"; if ! grep -E '^'"$key"'=.' $file &>/dev/null; then [[ -s "$file" && ! -z "$(tail -c 1 "$file")" ]] && newline=$'\n' || newline=""; echo "$newline$key=$value" >> "$file"; else sed -i'' -E 's/^'"$key"'=./'"$key=$value"'/' $file; fi
chmod: changing permissions of '/data/data/com.termux/files/home/.termux': Operation not permitted
bash: /data/data/com.termux/files/home/.termux/termux.properties: Permission denied
~ $

Issue here is that I already updated the termux.properties with allow-external-apps via adb and even if I try to run the above command to set value to true it gives permission denied...
and for this reason I am unable to run service from my app ... I have granted external storage permission also with RUN_COMMAND permission .. but still I am unable to execute the service from my app ...

Below is the output when try to run service

2021-05-25 02:00:44.102 19068-19247/com.qodit.mobileproxy D/PluginResultsService: Execution id 1001 result:
stdout:
```

```
stdout_original_length: `null`
stderr:
```

```
stderr_original_length: `null`
exitCode: `0`
errCode: `2`
errmsg: `RunCommandService require `allow-external-apps` property to be set to `true` in `~/.termux/termux.properties` file.`

@ghost
Copy link

ghost commented May 24, 2021

RunCommandService require allow-external-apps property to be set to true

This error means that you didn't changed this property in termux.properties or configuration file is unreadable due to wrong ownership, permissions or SELinux labels.

@bilalilyas90
Copy link
Author

Thank you again @agnostic-apollo ... all is understood now from wiki link you shared :)

One more issue just appeared when I updated termux app and please can you help me with this also ...

Following is the output from termux terminal

Welcome to Termux!

Community forum: https://termux.com/community
Gitter chat: https://gitter.im/termux/termux
IRC channel: #termux on freenode

Working with packages:

  • Search packages: pkg search
  • Install a package: pkg install
  • Upgrade packages: pkg upgrade

Subscribing to additional repositories:

  • Root: pkg install root-repo
  • Unstable: pkg install unstable-repo
  • X11: pkg install x11-repo

Report issues at https://termux.com/issues

The Google Play version of the Termux app no longer
receives updates. For more information, visit:
https://wiki.termux.com/wiki/Termux_Google_Play

cp: cannot stat '/data/data/com.termux/files/home/.termux/termux.properties': Permission denied
~ $ termux-storage-get
The program termux-storage-get is not installed. Install it by executing:
pkg install termux-api
~ $ value="true"; key="allow-external-apps"; file="/data/data/com.termux/files/home/.termux/termux.properties"; mkdir -p "$(dirname "$file")"; chmod 700 "$(dirname "$file")"; if ! grep -E '^'"$key"'=.' $file &>/dev/null; then [[ -s "$file" && ! -z "$(tail -c 1 "$file")" ]] && newline=$'\n' || newline=""; echo "$newline$key=$value" >> "$file"; else sed -i'' -E 's/^'"$key"'=./'"$key=$value"'/' $file; fi
chmod: changing permissions of '/data/data/com.termux/files/home/.termux': Operation not permitted
bash: /data/data/com.termux/files/home/.termux/termux.properties: Permission denied
~ $

Issue here is that I already updated the termux.properties with allow-external-apps via adb and even if I try to run the above command to set value to true it gives permission denied...
and for this reason I am unable to run service from my app ... I have granted external storage permission also with RUN_COMMAND permission .. but still I am unable to execute the service from my app ...

Below is the output when try to run service

2021-05-25 02:00:44.102 19068-19247/com.qodit.mobileproxy D/PluginResultsService: Execution id 1001 result:
stdout:


stdout_original_length: `null`
stderr:
stderr_original_length: `null`
exitCode: `0`
errCode: `2`
errmsg: `RunCommandService require `allow-external-apps` property to be set to `true` in `~/.termux/termux.properties` file.`

RunCommandService require allow-external-apps property to be set to true

This error means that you didn't changed this property in termux.properties or configuration file is unreadable due to wrong ownership, permissions or SELinux labels.

I just solved this issue ... it was due to wrong permissions to ~/.termux using below command
chmod 755 -R /data/data/com.termux/files/home/.termux;

@agnostic-apollo
Copy link
Member

I already updated the termux.properties with allow-external-apps via adb

That's likely where your problem is. I assume you ran commands with root which would have created the files with root ownership, look here for a potential fix. Or delete .termux directory with root and recreate it from termux shell, if that's the only thing you did with root.

chmod 755 -R /data/data/com.termux/files/home/.termux;

755 (rwxr-xr-x) will just allow termux to read it due to everybody read bit set, but writing would fail. The real reason is likely wrong ownership, you need to fix it as mentioned above. Termux directories only need 700 permission. Run stat .termux

@bilalilyas90
Copy link
Author

RunCommandService require allow-external-apps property to be set to true

This error means that you didn't changed this property in termux.properties or configuration file is unreadable due to wrong ownership, permissions or SELinux labels.

I did change this property to true ... but as @agnostic-apollo said I ran commands with root permissions and that's why I couldn't access the .termux folder ...

@bilalilyas90
Copy link
Author

I already updated the termux.properties with allow-external-apps via adb

That's likely where your problem is. I assume you ran commands with root which would have created the files with root ownership, look here for a potential fix. Or delete .termux directory with root and recreate it from termux shell, if that's the only thing you did with root.

chmod 755 -R /data/data/com.termux/files/home/.termux;

755 (rwxr-xr-x) will just allow termux to read it due to everybody read bit set, but writing would fail. The real reason is likely wrong ownership, you need to fix it as mentioned above. Termux directories only need 700 permission. Run stat .termux

@agnostic-apollo Thank you for your support :) now I understand the issue properly and have solved the problem ...

@agnostic-apollo
Copy link
Member

welcome :)

@bilalilyas90
Copy link
Author

@agnostic-apollo
if we want to run the service directly after installing apk without even opening the app once what should we do?
when I run the service directly after installing apk I get following error

Regular file not found at executable file path.
Executable Absolute Path: "/data/data/com.termux/files/usr/bin/bash"

any shell command or something like this??

@agnostic-apollo
Copy link
Member

When you install (not update) termux, bootstrap has not been set up. $PREFIX does not exist, hence you get that error. No other way than letting termux setup bootstrap first.

@bilalilyas90
Copy link
Author

Is there any way to setup bootstrap via some adb command?

@agnostic-apollo
Copy link
Member

agnostic-apollo commented May 25, 2021

For testing it might be possible with root (ADB != root), do a fresh install of termux. Copy /data/data/com.termux to /data. Then uninstall. Then reinstall. Copy /data/com.termux to /data/data/com.termux, then get sharedUserId assigned to com.termux as mentioned here, then restore ownership and selinux context of /data/data/com.termux as mentioned here. You will have to replace $(id -u):$(id -u) with <uid>:<uid> you found earlier, like 10123:10123. Then hopefully, it might work, I haven't tested this.

@bilalilyas90
Copy link
Author

@agnostic-apollo

How can we run commands as SU via RunCommandService ??

@agnostic-apollo
Copy link
Member

Either create your own custom script that calls su or install this sudo and pass commands or scripts directly to it.

@bilalilyas90
Copy link
Author

Either create your own custom script that calls su or install this sudo and pass commands or scripts directly to it.

Again thank you :) it worked 👍

@bilalilyas90
Copy link
Author

I already updated the termux.properties with allow-external-apps via adb

That's likely where your problem is. I assume you ran commands with root which would have created the files with root ownership, look here for a potential fix. Or delete .termux directory with root and recreate it from termux shell, if that's the only thing you did with root.

chmod 755 -R /data/data/com.termux/files/home/.termux;

755 (rwxr-xr-x) will just allow termux to read it due to everybody read bit set, but writing would fail. The real reason is likely wrong ownership, you need to fix it as mentioned above. Termux directories only need 700 permission. Run stat .termux

I once again need your help @agnostic-apollo
My scenario basically is that I want to run RunCommandService from my app without interacting with termux app ...
that part of installing bootstrap packages after new term app installation I did it by calling termuxActivity for few second and then close it like this :

am start -n com.termux/.HomeActivity; sleep 10; am force-stop com.termux;

this all is ok .. but now issue is of termux.properties file .. I tried to set allow-external-apps to true via add shell as root user as I was unable to access or write it without root user .. so now how can I make it work without interaction with termux shell and run the commandService from my app??

@agnostic-apollo
Copy link
Member

You could do adb shell 'run-as com.termux sh -c "mkdir -p /data/data/com.termux/files/home/.termux; echo allow-external-apps=true >> /data/data/com.termux/files/home/.termux/termux.properties"'

@bilalilyas90
Copy link
Author

You could do adb shell 'run-as com.termux sh -c "mkdir -p /data/data/com.termux/files/home/.termux; echo allow-external-apps=true >> /data/data/com.termux/files/home/.termux/termux.properties"'

I get this following error :

adb shell 'run-as com.termux sh -c "mkdir -p /data/data/com.termux/files/home/.termux; echo allow-external-apps=true >> /data/data/com.termux/files/home/.termux/termux.properties"'
run-as: Package 'com.termux' is not debuggable

@ghost
Copy link

ghost commented May 28, 2021

Yes, because release builds are not debuggable. You need to build a such yourself or obtain a development snapshot from Github Actions, e.g. this https://github.com/termux/termux-app/suites/2809748693/artifacts/62504662.

@bilalilyas90
Copy link
Author

Yes, because release builds are not debuggable. You need to build a such yourself or obtain a development snapshot from Github Actions, e.g. this https://github.com/termux/termux-app/suites/2809748693/artifacts/62504662.

ahhh yes I also thought so ..
Thank you this debug app in the link worked 👍

@agnostic-apollo
Copy link
Member

agnostic-apollo commented May 28, 2021

As xeffyr mentioned, can't use run-as on release builds. With root for release builds, you can also do following after bootstrap has been created:

termux_uid="$(adb shell stat -c %U /data/data/com.termux)"
adb shell 'su '"$termux_uid"' -c "mkdir -p /data/data/com.termux/files/home/.termux; echo allow-external-apps=true >> /data/data/com.termux/files/home/.termux/termux.properties"'

But then again, all these "hacks" with adb/root would only work for your personal app/mobile environment, don't expect them to work or don't use these design for production apps.

@bilalilyas90
Copy link
Author

@agnostic-apollo

Hi
I need need some help regarding termux app ...
I download the code and run code in android studio which run perfectly...
but when I change package name it doesn't work properly and gives following error

exec("/data/data/com.qodit.mobilespy/files/usr/bin/login"): No such file or directory
[Process completed (code 1) - press Enter]

this is the error which I get after changing package name ...
Can you tell me what should I do?

@agnostic-apollo
Copy link
Member

Check #1983

@bilalilyas90
Copy link
Author

Check #1983

I tried the steps and here I got this error and url not found/ :

Downloading http://deb.debian.org/debian/pool/main/a/apt/apt_2.3.5.tar.xz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (22) The requested URL returned error: 404 Not Found
Failed to download http://deb.debian.org/debian/pool/main/a/apt/apt_2.3.5.tar.xz
[*] Building 'apt' exited with exit code 1
Failed to build package 'apt' for arch 'aarch64'

@agnostic-apollo
Copy link
Member

agnostic-apollo commented Jun 20, 2021

The reason is already mentioned here.

If you get curl: (22) The requested URL returned error: 410 Gone or something like 404 Not Found while running build-bootstraps.sh when its downloading a package source, then you will have to update the TERMUX_PKG_VERSION, TERMUX_PKG_SRCURL, etc in the build.sh file for the respective package, and fix any *.patch files or apply additional ones if compilation fails, or open an issue in termux-packages.

Either change url and update patches if necessary yourself and if you can't, wait for someone else to do it when they update apt and then quickly build while the url is still valid.

@bilalilyas90
Copy link
Author

The reason is already mentioned here.

If you get curl: (22) The requested URL returned error: 410 Gone or something like 404 Not Found while running build-bootstraps.sh when its downloading a package source, then you will have to update the TERMUX_PKG_VERSION, TERMUX_PKG_SRCURL, etc in the build.sh file for the respective package, and fix any *.patch files or apply additional ones if compilation fails, or open an issue in termux-packages.

Either change url and update patches if necessary yourself and if you can't, wait for someone else to do it when they update apt and then quickly build while the url is still valid.

Ahh sorry I missed this .. I will try to update myself ..
Thank You

@bilalilyas90
Copy link
Author

@agnostic-apollo

I successfully managed to build bootstrap packages and changed the package name also.
Now one more question is about sudo.
https://github.com/agnostic-apollo/sudo/

how to use this sudo with our changed package name?
I get this following error

Screenshot 2021-06-21 at 3 31 16 PM

@ghost
Copy link

ghost commented Jun 21, 2021

@bilalilyas90 Adjust following line to match your new package name: https://github.com/agnostic-apollo/sudo/blob/master/sudo#L1

@bilalilyas90
Copy link
Author

@bilalilyas90 Adjust following line to match your new package name: https://github.com/agnostic-apollo/sudo/blob/master/sudo#L1

Thank you @xeffyr it worked

@bilalilyas90
Copy link
Author

@xeffyr @agnostic-apollo

Bootstrap packages were built successfully but now I am getting this following error of 403 when using pkg install?

Screenshot_1624289450

@ghost
Copy link

ghost commented Jun 21, 2021

now I am getting this following error of 403 when using pkg install?

Why you think that Termux should allow usage of its hosting capabilities by unaffiliated projects?

You need to build not only bootstrap packages but all other packages which you consider necessary and create own repository.

@bilalilyas90
Copy link
Author

now I am getting this following error of 403 when using pkg install?

Why you think that Termux should allow usage of its hosting capabilities by unaffiliated projects?

You need to build not only bootstrap packages but all other packages which you consider necessary and create own repository.

Ok I understand your point ..
So after creating my own repository how can I change the repository links?

@ghost
Copy link

ghost commented Jun 21, 2021

Change this: https://github.com/termux/termux-packages/blob/master/packages/apt/build.sh#L65

Also, remove (or adjust appropriately) following scripts since they are mostly useless for the forks:

This stuff can also be dropped - packages providing links to optional repositories:

If really need packages from these repos, you can clone them (1, 2, 3, 4, 5) and merge directory ./packages with your termux-packages repository fork.

Of course that will require rebuilding bootstrap archive to include changes made to build.sh files.

@bilalilyas90
Copy link
Author

@xeffyr

Can you please guide me how to create my own repository ? I have a server but I am confused how to create my own repository and upload to server?

@bilalilyas90
Copy link
Author

@agnostic-apollo

I am getting this error also and here it still says permission denied for com.termux package which I already changed everywhere?

Screenshot_1624352129

@ghost
Copy link

ghost commented Jun 22, 2021

Can you please guide me how to create my own repository ?

Its regular Debian (apt) package repository, there no any Termux-specific guides. Internet is has lots of articles about building own Debian repositories with various tools. We use Aptly, its website provides a complete docs about its commands, start from https://www.aptly.info/doc/commands/.

Sample ~/.aptly.conf:

{
    "rootDir": "/srv/aptly-rootfs",
    "downloadConcurrency": 4,
    "downloadSpeedLimit": 0,
    "architectures": [],
    "dependencyFollowSuggests": false,
    "dependencyFollowRecommends": false,
    "dependencyFollowAllVariants": false,
    "dependencyFollowSource": false,
    "dependencyVerboseResolve": false,
    "gpgDisableSign": false,
    "gpgDisableVerify": false,
    "gpgProvider": "gpg",
    "downloadSourcePackages": false,
    "skipLegacyPool": true,
    "ppaDistributorID": "Termux",
    "ppaCodename": "",
    "skipContentsPublishing": true,
    "FileSystemPublishEndpoints": {
      "termux": {
        "linkMethod": "hardlink",
        "verifyMethod": "md5"
      }
    },
    "S3PublishEndpoints": {},
    "SwiftPublishEndpoints": {}
}

Creating repository:

aptly repo create -architectures="all aarch64 arm i686 x86_64" -distribution="stable" -component="main" termux

Adding packages:

aptly repo add termux ./dir/with/debfiles

Publishing (first time):

aptly publish repo termux termux

Details on how to use gpg for signing are omitted. Search for guides on how to create gpg key on the Internet. If still have problems with gpg, use -skip-signing option...

Publishing (updating published repo):

aptly publish update stable termux

Notes:

  • termux is repository name and also file system endpoint name as mentioned in ~/.aptly.conf
  • stable is a distribution name of created repository.

I am getting this error also and here it still says permission denied for com.termux package which I already changed everywhere?

If you have invalid package name in deb files, then how you built bootstrap packages?

Here is what should be done and expected steps order:

  1. Edit https://github.com/termux/termux-packages/blob/master/scripts/properties.sh#L15
  2. Build all packages mentioned https://github.com/termux/termux-packages/blob/master/scripts/generate-bootstraps.sh#L302-L343, assuming BOOTSTRAP_ANDROID10_COMPATIBLE is false.
  3. Create apt repository and publish built packages.
  4. Edit https://github.com/termux/termux-packages/blob/master/scripts/generate-bootstraps.sh#L22. Note: you may use --repository option instead, but since you're doing a fork, I recommend changing the script default values instead.
  5. Build bootstrap archives.

You can use grep -r com.termux . to search all occurrences of com.termux.

Remember that:

  • Every official Termux binary has a hardcoded /data/data/com.termux/files/usr at least in DT_RUNPATH ELF section. Many packages also define hardcoded paths to /tmp, /var, etc.
  • Every official Termux deb files have path ./data/data/com.termux/files/usr since we don't emulate rootfs and chose to use prefix variant.
  • Apt is patched to send us information about installation and we can easily detect "Termux" app with third-party package name. Right now this works in a soft mode.

@bilalilyas90
Copy link
Author

Can you please guide me how to create my own repository ?

Its regular Debian (apt) package repository, there no any Termux-specific guides. Internet is has lots of articles about building own Debian repositories with various tools. We use Aptly, its website provides a complete docs about its commands, start from https://www.aptly.info/doc/commands/.

Sample ~/.aptly.conf:

{
    "rootDir": "/srv/aptly-rootfs",
    "downloadConcurrency": 4,
    "downloadSpeedLimit": 0,
    "architectures": [],
    "dependencyFollowSuggests": false,
    "dependencyFollowRecommends": false,
    "dependencyFollowAllVariants": false,
    "dependencyFollowSource": false,
    "dependencyVerboseResolve": false,
    "gpgDisableSign": false,
    "gpgDisableVerify": false,
    "gpgProvider": "gpg",
    "downloadSourcePackages": false,
    "skipLegacyPool": true,
    "ppaDistributorID": "Termux",
    "ppaCodename": "",
    "skipContentsPublishing": true,
    "FileSystemPublishEndpoints": {
      "termux": {
        "linkMethod": "hardlink",
        "verifyMethod": "md5"
      }
    },
    "S3PublishEndpoints": {},
    "SwiftPublishEndpoints": {}
}

Creating repository:

aptly repo create -architectures="all aarch64 arm i686 x86_64" -distribution="stable" -component="main" termux

Adding packages:

aptly repo add termux ./dir/with/debfiles

Publishing (first time):

aptly publish repo termux termux

Details on how to use gpg for signing are omitted. Search for guides on how to create gpg key on the Internet. If still have problems with gpg, use -skip-signing option...

Publishing (updating published repo):

aptly publish update stable termux

Notes:

  • termux is repository name and also file system endpoint name as mentioned in ~/.aptly.conf
  • stable is a distribution name of created repository.

I am getting this error also and here it still says permission denied for com.termux package which I already changed everywhere?

If you have invalid package name in deb files, then how you built bootstrap packages?

Here is what should be done and expected steps order:

  1. Edit https://github.com/termux/termux-packages/blob/master/scripts/properties.sh#L15
  2. Build all packages mentioned https://github.com/termux/termux-packages/blob/master/scripts/generate-bootstraps.sh#L302-L343, assuming BOOTSTRAP_ANDROID10_COMPATIBLE is false.
  3. Create apt repository and publish built packages.
  4. Edit https://github.com/termux/termux-packages/blob/master/scripts/generate-bootstraps.sh#L22. Note: you may use --repository option instead, but since you're doing a fork, I recommend changing the script default values instead.
  5. Build bootstrap archives.

You can use grep -r com.termux . to search all occurrences of com.termux.

Remember that:

  • Every official Termux binary has a hardcoded /data/data/com.termux/files/usr at least in DT_RUNPATH ELF section. Many packages also define hardcoded paths to /tmp, /var, etc.
  • Every official Termux deb files have path ./data/data/com.termux/files/usr since we don't emulate rootfs and chose to use prefix variant.
  • Apt is patched to send us information about installation and we can easily detect "Termux" app with third-party package name. Right now this works in a soft mode.

@xeffyr
Thank you for your reply

I followed the steps provided by @agnostic-apollo in this link
#1983 (comment)

I think this create apt repository step was not done and can this be the issue? because I changed the package from properties.sh and searched for com.termux occurrences and changed that too.

  1. Create apt repository and publish built packages

So first I should create apt repository as guided by you and then then changed the repository url and then create bootstrap packages again?

@ghost
Copy link

ghost commented Jun 22, 2021

I think this create apt repository step was not done and can this be the issue?

No, the mentioned steps applicable only for official bootstrap generation script. If you managed to create bootstrap archive without apt repository, ok. But make sure that all packages have com.termux changed to appropriate value.

because I changed the package from properties.sh and searched for com.termux occurrences and changed that too.

After changing prefix, you won't be able to install the original Termux packages anymore. External packages (i.e. installed with apt) should be rebuilt too.

So first I should create apt repository as guided by you and then then changed the repository url and then create bootstrap packages again?

Since you already have working bootstrap set, you need only to create apt repository and replace URLs.

However if you think that application will use only specific packages, you can go with alternate approach such as extending the bootstrap set. This will allow you to omit the requirement of setting up own apt repository but will require disabling package manager and handle environment updates on application side.

@ghost ghost locked and limited conversation to collaborators Oct 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants