这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@mame
Copy link

@mame mame commented Feb 3, 2020

This changeset allows us to specify the initial executable as Intent data. In other words, we can invoke a script under Termux by the following adb command:

adb shell start -n com.termux/.app.TermuxActivity -d file:///path/to/script.sh

The motivation is to use Termux as a CI environment. This changeset is helpful to run a test script. Otherwise, we need to send key events to Termux to input a command that invokes the test script, which is very fragile.

What do you think?

It is useful to run a script under Termux by using adb:
```
adb shell start -n com.termux/.app.TermuxActivity -d file:///path/to/script.sh
```
@ghost
Copy link

ghost commented Feb 3, 2020

Sorry, but we do not want to allow to initiate execution of arbitrary code by third-party intents without explicit approval by user.

#1029 (comment)


Your implementation is suitable for debug builds, but in such case additional changes should be done.

@ghost ghost closed this Feb 3, 2020
@mame
Copy link
Author

mame commented Feb 3, 2020

Thanks for taking the time to reply my PR! Your decision about security looks reasonable.

In my use case (Termux as a CI), I build and install a custom Termux package for each execution. So, it is enough if an initial script is allowed only when debug build. I've added a commit to allow an initial script only when BuildConfig.DEBUG:

https://github.com/termux/termux-app/compare/master...mame:TermuxActivity-accepts-executablePath?expand=1

Is there any chance to merge the change above?

Alternatively, it is even enough if I can specify a fixed initial script at the build time, such as ORG_GRADLE_PROJECT_TERMUX_INITIAL_SCRIPT=/path/to/script.sh ./gradlew assembleDebug. If you prefer this approach, I'm happy to try to implement it.

Thanks!

@ghost ghost reopened this Feb 3, 2020
@snogglethorpe
Copy link

snogglethorpe commented Feb 4, 2020 via email

@ghost
Copy link

ghost commented Feb 4, 2020

it seems like things are already wide-open security-wise

For ADB & root only.

@ghost
Copy link

ghost commented Feb 4, 2020

@mame Putting script to /sdcard does not work properly due to missing exec permission in this location (storage access is granted). /data/local/tmp accessible only by root. Execution from /system/bin obviously working fine.

So what expected path of where script should be put before execution ?

@mame
Copy link
Author

mame commented Feb 4, 2020

So what expected path of where script should be put before execution ?

The path I'm using is /sdcard/hello.sh. As you said it misses exec permission, but it works for me. I'm unsure why. Does it work only on limited Android versions? (I'm using API version 28, and default system-images).

hello.sh

#!/bin/sh
echo Hello
sleep 3

run.sh

adb push hello.sh /sdcard/hello.sh
adb install termux-app/app/build/outputs/apk/debug/app-debug.apk
adb shell pm grant com.termux android.permission.READ_EXTERNAL_STORAGE
adb shell pm grant com.termux android.permission.WRITE_EXTERNAL_STORAGE
adb shell am start -n com.termux/com.termux.app.TermuxActivity -d file:///sdcard/hello.sh

image

@mame
Copy link
Author

mame commented Feb 4, 2020

Well, is my script running on /system/bin/sh? Because I can install and invoke clang by this approach, I thought it run on Termux's shell. I'm sorry if I may miss something.

hello.sh

#!/bin/sh
dpkg --configure -a --force-confnew
pkg upgrade -y
pkg install -y clang
clang --version
echo 'int main() { puts("Hello world"); }' > test.c
clang -o test test.c
./test
sleep 3

image

@rubikitch
Copy link

Do you use SSH on Termux?
I'm running Termux scripts via SSH, works fine.

@mame
Copy link
Author

mame commented Feb 4, 2020

@rubikitch I want to automatically setup Termux on an empty Android image without manual operation. To use SSH, I need to run pkg install -y openssh; sshd; sleep first.

@mame
Copy link
Author

mame commented Feb 8, 2020

I've implemented another idea: specifying the default executable path via gradle properties.

We can specify the default path by the following build command.

./gradlew assembleDebug -Pcom.termux.defaultExecutablePath=/sdcard/hello.sh

The diff is much simpler than the original proposal.

https://github.com/termux/termux-app/compare/master...mame:configurable-default-executable-path?expand=1

@mame
Copy link
Author

mame commented Apr 28, 2020

Hi,

I'm running an Android CI environment for Ruby that uses Termux. Currently, to invoke a script in Termux, it sends key events "bash /sdcard/setup.sh" and ENTER by using adb shell input:

https://github.com/mame/rubyci-android/blob/34fc0697e69335bef123d69e484519f9a9967bf0/setup-android.sh#L134-L135

However, because it is not robust, it frequently fails to start the script.

https://github.com/mame/rubyci-android/actions/runs/89371431

I'd appreciate it if you provide any way to invoke a startup script in Termux.

@aan230999

This comment has been minimized.

@mame
Copy link
Author

mame commented Apr 14, 2021

I've noticed that this is now possible by using RUN_COMMAND Intent. I close my issue. Thank you for your great work!

@mame mame closed this Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants