Closed imraro closed 10 years ago
@imraro what kind of script do you have in mind? as in root feature to run sh (bash) script?
Exactly!
You can do this with App Shortcuts, to at least Tasker for now. There are maybe other apps too. Took a quick look at Script Manager, maybe.
Eventually this is a useful feature within Sfen too.
Oh god, this could get pretty nasty for someone who doesn't know what he is doing! :)
But, I will implement it as action- file picker will trigger and return us the selected *.sh file. This will run as normal user, not su. Bash inside the file should take care of that!
Added in next commit.
I have simple script but it isn't working for me:
#!/system/bin/sh
touch /sdcard/flile
Logcat:
D/sfen (16002): EVENT Run Script
D/sfen (16002): condition WIFI_CONNECT
D/sfen (16002): match all? true (results from conditions: [false]); RETURN RESULT: false
D/sfen (16002): no events running.
I/ActivityManager( 843): Displayed gpapez.sfen/.Main: +336ms
I/Timeline( 843): Timeline: Activity_windows_visible id: ActivityRecord{42a1a1a8 u0 gpapez.sfen/.Main t21} time:3259921
I/sfen (16002): Received: android.net.wifi.STATE_CHANGE
I/sfen (16002): Received: android.net.wifi.STATE_CHANGE
I/sfen (16002): Received: android.net.wifi.STATE_CHANGE
I/sfen (16002): Received: android.net.wifi.STATE_CHANGE
D/sfen (16002): EVENT Run Script
D/sfen (16002): condition WIFI_CONNECT
D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true
I/sfen (16002): action: Shortcut(ACT_RUNSCRIPT)
D/sfen (16002): Script exit value: 126
D/sfen (16002): Running next actions:
D/sfen (16002): > ACT_RUNSCRIPT
D/sfen (16002): EVENT Run Script
D/sfen (16002): condition WIFI_CONNECT
D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true
E/sfen (16002): Run Script is already running. Skipping actions.
D/sfen (16002): EVENT Run Script
D/sfen (16002): condition WIFI_CONNECT
D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true
E/sfen (16002): Run Script is already running. Skipping actions.
This is crazy. I've spent all day yesterday in this where command worked but bash didn't. When finally got it working, I've stop touching the code. Now it doesn't work again -_-
Will take a look at it.. Again On Aug 20, 2014 11:06 AM, "imraro" notifications@github.com wrote:
I have simple script but it isn't working for me:
!/system/bin/sh
touch /sdcard/flile
Logcat:
D/sfen (16002): EVENT Run Script D/sfen (16002): condition WIFI_CONNECT D/sfen (16002): match all? true (results from conditions: [false]); RETURN RESULT: false D/sfen (16002): no events running. I/ActivityManager( 843): Displayed gpapez.sfen/.Main: +336ms I/Timeline( 843): Timeline: Activity_windows_visible id: ActivityRecord{42a1a1a8 u0 gpapez.sfen/.Main t21} time:3259921 I/sfen (16002): Received: android.net.wifi.STATE_CHANGE I/sfen (16002): Received: android.net.wifi.STATE_CHANGE I/sfen (16002): Received: android.net.wifi.STATE_CHANGE I/sfen (16002): Received: android.net.wifi.STATE_CHANGE D/sfen (16002): EVENT Run Script D/sfen (16002): condition WIFI_CONNECT D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true I/sfen (16002): action: Shortcut(ACT_RUNSCRIPT) D/sfen (16002): Script exit value: 126 D/sfen (16002): Running next actions: D/sfen (16002): > ACT_RUNSCRIPT D/sfen (16002): EVENT Run Script D/sfen (16002): condition WIFI_CONNECT D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true E/sfen (16002): Run Script is already running. Skipping actions. D/sfen (16002): EVENT Run Script D/sfen (16002): condition WIFI_CONNECT D/sfen (16002): match all? true (results from conditions: [true]); RETURN RESULT: true E/sfen (16002): Run Script is already running. Skipping actions.
— Reply to this email directly or view it on GitHub https://github.com/lordgreg/Sfen/issues/24#issuecomment-52751187.
I'm back.. :)
@imraro you need to provide FULL path to file (inside bash script).
this won't work:
touch myfile.txt
but this will:
touch /storage/emulated/0/Download/test.txt
Same results...
@imraro I've fixed a thing where, before executing, I set running directory to the same where your sh file is. That way, example like this should also work (lets assume run.sh is in /sdcard/Download/)
touch yolo.txt
will create yolo.txt in /sdcard/Download/
Next commit & release will include this update (tested on VM and my device).
D/sfen ( 6392): EVENT Run Script
D/sfen ( 6392): condition WIFI_CONNECT
D/sfen ( 6392): match all? true (results from conditions: [true]); RETURN RESULT: true
I/sfen ( 6392): action: Shortcut(ACT_RUNSCRIPT)
D/sfen ( 6392): Script exit value: 126
# cat /sdcard/touchfile.sh
#!/system/bin/sh
touch test.txt
# ls /sdcard/test.txt
ls: /sdcard/test.txt: No such file or directory
# cd /sdcard
# sh /sdcard/touchfile.sh
# ls /sdcard/test.txt
/sdcard/test.txt
Hi, this is the result I get with your "slight modified" script
imraro.sh
#!/system/bin/sh
touch test.txt
# run other shell script that will create file
/system/bin/sh ./touchfile.sh
ls test.txt
#ls: /sdcard/test.txt: No such file or directory
# cd /sdcard
# sh /sdcard/touchfile.sh
# ls /sdcard/test.txt /sdcard/test.txt
# who am i?
whoami
# current directory?
pwd
# network config
ifconfig
touchfile.sh
#!/system/bin/sh
# create a file touched_by_imraro.txt
touch touched_by_imraro.txt
Log output 08-21 07:25:25.748 1994-1994/gpapez.sfen I/sfen﹕ action: Shortcut(ACT_RUNSCRIPT) 08-21 07:25:25.920 1994-1994/gpapez.sfen D/sfen﹕ Script exit value: 0 08-21 07:25:25.924 1994-1994/gpapez.sfen D/sfen﹕ Script response: test.txt 08-21 07:25:25.928 1994-1994/gpapez.sfen D/sfen﹕ Script response: u0_a87 08-21 07:25:25.928 1994-1994/gpapez.sfen D/sfen﹕ Script response: /storage/emulated/0/Download
Screenshot
As said, this was updated in yestrday's commit and will be released in next beta version (probably tomorrow)
How did you manage to set execute permissions for files in /sdcard ?
There's no other option. When creating new file, it gets automatically set to 777 (rwx) permission. If you in any chance have different permissions or asking about the file created by sh script, just use the chmod on newly created file in sh script too.
If, by any chance, files have different chmod, just use chmod RWX command on them. Or find permissions properties in any file browser.
$ chmod 0777 /sdcard/Download/touchfile.sh
Unable to chmod /sdcard/Download/touchfile.sh: Operation not permitted
$ su
# chmod 0777 /sdcard/Download/touchfile.sh
# ls -l /sdcard/Download/touchfile.sh
-rw-rw-r-- root sdcard_rw 33 2014-08-21 11:00 touchfile.sh
I think what sdcard is always mounting with noexec, at least in CM.
Interesting,.. will join their irc channel this afternoon to check this info a bit.
I think what the simplest solution is to start the script through invoking sh, not directly.
As you see, the script (the first one you use in condition), is called like that:
String[] cmd = new String[]{"/system/bin/sh", "-c", fileToRun};
so the actually execute is:
/system/bin/sh -c /sdcard/myRunnableScript.sh
I just tried this feature on Android 5.1.1, but it doesn't seem to work. Executing test scripts like the examples above works with Terminal Emulator (even without root) inside the /storage/emulated/0/Download directory, but doesn't work with Sfen. Neither when using a local path (aka touch asd.txt) nor when using the absolute path (touch /storage/emulated/0/Download/asd.txt).
I tried using Sfen in root mode and without, but it doesn't work in any of those. Could you maybe check if this still works for you?
It might be killer-feature.