How to start a script in termux from an app - android

I need to start a script in a termux environment on my android tablet from an other android app. I think it should be possible in two ways.
setting up some kind of startup script (like the ~/.bashrc in the bash shell) in termunx and starting termux from the other app
calling termux from the other app with the script name as parameter, so that termux executes that script immediately.
I don't know how to do either of these possibilities.
Does anybody know how to accomplish it, maybe with a third method, I didn't think of so far?

I didn't see the wood for the trees. The answer is exactly my first suggested way. I didn't realize, that bash is the default shell in termux. So just one of .bashrc .profile .bash_profile do the job.

Related

Using SCRCPY and React-Native at the same time on a linux machine

I am trying to use scrcpy for mirroring the mobile screen on my Linux machine, to develop a react-native app. But adb does not allow running scrcpy and react-native instance at the same time. It terminates one instance and starts the other one. The documentation for scrcpy states to add an env variable ADB=/path/to/adb scrcpy.
I'm not very familiar with Linux environments. Could someone help me with this please? I tried looking this up on the internet, but most of them explain how to do this on a windows environment.
Okay I figured this out myself.
This is what I did.
Create a new folder scrcpy-tools inside Android/Sdk.
copy adb from Android/Sdk/platform-tools into scrcpy-tools.
open the bashrc file and paste the following at the end of the file.
export SCRCPY_TOOLS=${HOME}/Android/Sdk/scrcpy-tools
function scrcpy_run () {
ADB=$SCRCPY_TOOLS/adb scrcpy
}
Save the file.
Open a new terminal and simply type scrcpy_run to start a new adb instance for scrcpy.
We can now run react-native side by side and debug it on the mobile phone.
I had the same problem using scrcpy on linux, exactly same behavior like you had.
I just switched to an other application for mirroring screens from the phone, try out Vysor.
You dont have HD resolution but its enough for testing, also it will work without closing either react native or Vysor itself.
Install it like that:
sudo apt install vysor

Pass parameter through shell to python

I run python in my Android Terminal and want to run a .py file with:
python /sdcard/myScript.py
The problem is that python is called in my Android enviroment indirect with a shell in my /system/bin/ path (to get it direct accessable via Terminal emulator).
My exact question, how the title tells how to pass parameter through multiple Shell scripts to Python?
My direct called file "python" in /System/bin/ contains only a redirection like:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh
and so on to call python binary.
Edit:
I simply add the $1 parameter after every shell, Python is called through like:
sh data/data/com.hipipal.qpyplus/files/bin/qpython-android5.sh $1
so is possible to call
python /sdcard/myScript.py arg1
and in myScript.py as usual fetch with sys.argv
thanks
I don't have experience in Android programming, so I can only give a general recommendation:
Of course the naive solution would be to explicitly pass the arguments from script to script, but I guess you can't or don't want to modify the scripts in between, otherwise you would not have asked.
Another approach, which I sometimes use, is to define an environment variable in the outermost scripts, stuff all my parameters into it, and parse it from Python.
Finally, you could write a "configuration file" from the outermost script, and read it from your Python program. If you create this file in Python syntax, you even spare yourself from parsing the code.
I have similar problem. Runing my script from Python console
/storage/emulator/0/Download/.last_tmp.py -s && exit
I am getting "Permission denied". No matter if i am calling last_tmp or edited script itself.
Is there perhaps any way to pass the params in editor?

Can I start an executable in an approved application?

I've noticed that it is possible on Android to change the permissions on a file with chmod, which means we can easily execute anything from an application:
var runtime = Runtime.GetRuntime();
runtime.Exec("chmod 0755 /my/file").WaitFor();
// Then ProcessBuilder to execute it.
Would Google Play Store accept an application that takes advantage of this flaw? I can't find any documentation about it, but I confirm that it works.
Actually, I want to include ffmpeg for tasks that are too slow to be executed using MediaCodec.
(I've also noticed that the Android framework sometimes directly access to a native version of ffmpeg, so maybe I could access it directly from the phone?)
I don't know for sure if it is ok for Google Play.
However i don't think it is security issue. You will exec process with the autorisation of your app.
I hope the following example will help you.
You can try the following command line with your device connect.
adb shell
To have a shell on your devices
Then you can try to look what is inside the files for an app (replace com.your.package by the name of a debbugable apk)
ls /data/data/com.your.package
This command will failde because you have not the good permission.
Now run the following command.
run-as com.your.package
You will now exec your command line with the same permission as your app.
You can now retry the previous ls command. It will work. However it will not work for another package.
So, i think the command you will exec with your code, will be exec with the privilege of your app. So i don't think you can elevate the privilege of you app on a file with this method.

how to run script at boot-time?

I need to run a script that sets cpu_freq .In order to retain the settings after reboot i need to run script which takes care of this issue.I tried to write service in init.rc but the edited part in init.rc disappears on reboot .is there some other way to start script on reboot.thanks
I've found success with magisk. When installed, it adds a directory for boot scripts under /data/adb/service.d, in which you can throw your shell scripts and have them executed by Magisk on boot.
For example, I have the following script:
#!/bin/sh
sleep 15 # to make sure we aren't running in an early stage of the boot process
crond -b -c /data/crontab/
Once created as /data/adb/service.d/start-crond.sh and made executable, it automatically launches crond at boot (provided by Magisk's internal busybox instance).
Use Script Manager.
This link may be helpful:
[ADDON][Xperia S] Generic startup/init.d scripts support for Stock ROM/Kernel
http://forum.xda-developers.com/showthread.php?t=1547238
Although it is for Xperia S, it also works for my ideos. I think the theory behind is quite generic. And if you have installed busybox, you can unzip the downloaded package, read the batch and make some change to the phone by yourself.
If you really want to run your script manually after boot, I prefer scriptme in play market. It's simple and small.

How to move apps to sdcard via shell script

I want to write a small tool to move apps to SDcard.
I found the movePackage()-method in Android Open Source and reflect the method. I failed because this method need com.android.PERMISSION.MOVE_PACKAGE which I cannot get. So I want to using shell script to do this for rooted devices.
But I don't actually know what happened in the movePackage()-method. So I can't write the correct script.
Could you please tell what happened inside the Android when a app is moved to SDcard? Can I do this with program?
I'm not sure If I understand you, but on rooted device you can use adb.
For example:
adb push /home/username/Desktop/app.apk /sdcard/app.apk
Also you can do this (for removing):
adb shell rm /sdcard/app.apk
If you want to install:
adb install /home/username/Desktop/app.apk

Categories

Resources