I'd like to run adblock.sh and Nimbuzz after the phone has booted and connected to the internet. So far I've been able to write code that launches nimbuzz via a shell script like this:
Code:
am start -n com.nimbuzz/com.nimbuzz.InitScreen
but nothing happens when I save that to a file called autostart.sh in /data/opt/
However, issuing that command via adb or a terminal session does launch the app. I looked at other .sh files (userinit.sh etc) and saw that the PATH variable was defined so I added that but still nothing.
I figure running adblock.sh should be easy enough but have no idea how to make the script check for an internet connection. I figure I'd have to wait about 120 seconds for the phone to boot and acquire net connectivity (either 3g or wifi), so I could use something like sleep 120 to pause the script for two minutes before attempting to continue.
Could someone help me build an autostart.sh file? I'd really appreciate the help.
well... could someone please point me to a tutorial on shell scripts for android then? I've applied fu but have yet to come up with anything functional.
Hey bud,
Try saving the script in /system/sd, and naming it userinit.sh
If there already is a userinit.sh, just add the line to the very end of the file. You'll need to edit it in the computer
adb pull /system/sd/userinit.sh "C:/userinit.sh"
open the file in wordpad, make your addition,
adb push "C:/userinit.sh" /system/sd/userinit.sh
PM me if that doesn't work.
Related
In short,
I want to be able to
1) have a shell script which will connect via wireless to my local linux server and sync a directory
2) call this shell script from an icon on my home screen
3) see the output in window that popped up
Is this possible?
http://digitizor.com/2010/03/24/how-to-sync-nexus-one-with-rythmbox-music-player/
Not sure if a similar method works with Amarok
To kick it off from your phone.. vnc into your machine and start the process.
btw...this is a question and should have gone to the Q/A section.
I had a set of scripts on my Zaurus pda some years ago that, when a connection to my home network was detected, would try a rsync with my rsync server. It allowed me to have a always updated backup of my data. I have to look it up, even if only to set it up as a script, without a nice interface... It looks like a nice way of backing up my photos as soon as I am on my home wifi network.
there is app called Fsync that can do that for you.
Been doing this for months. Here is how.
Install Ampache on your Linux box. www.ampache.org
Configure Ampache and make sure you password protect! Open ports on your router/firewall.
Install Amdroid or Lullaby from the Market on your Android. Both apps will connect to your ampache server. I have been using Lullaby and prefer it.
Connection over 3G has almost no delay between songs and works well in the car
Thanks to both of you guys, but...
I don't know if that is will be enough for what the OP had in mind, but I wasn't talking about music/video streaming, I was talking of configurable automatic sync of directories, so ampache doesn't help me. Also, Fsync seems to need a ftp server, and all I need is a rsync server. I don't want to go around configuring ftp shares, etc, when rsync is way more suited to keeping two (or more) directories in sync.
I found out what I used on the zaurus: zNetBackup. Now is time to look at the sources, and if android runs scripts when setting up interfaces...
ruineraz said:
In short,
I want to be able to
1) have a shell script which will connect via wireless to my local linux server and sync a directory
2) call this shell script from an icon on my home screen
3) see the output in window that popped up
Is this possible?
Click to expand...
Click to collapse
You should already have everything you need, which is just rsync on the phone and ssh on the Linux box. Just run ssh on the box, set up keys, then figure out your rsync command and run it from GScript on the phone. GScript allows you to create a shortcut to a command or script on your home screen.
I use this general ssh/scp command to recursively transfer a directory to my sdcard all the time. Should be easy to adjust for rsync.
scp -i /path/to/keyfile -P port_number -r [email protected]:/path/to/directory /sdcard
fubaya said:
You should already have everything you need, which is just rsync on the phone and ssh on the Linux box. Just run ssh on the box, set up keys, then figure out your rsync command and run it from GScript on the phone. GScript allows you to create a shortcut to a command or script on your home screen.
I use this general ssh/scp command to recursively transfer a directory to my sdcard all the time. Should be easy to adjust for rsync.
scp -i /path/to/keyfile -P port_number -r [email protected]:/path/to/directory /sdcard
Click to expand...
Click to collapse
Thanks. Just can't seem to get ssh keys set up... dunno where to put them (don't seem to be .ssh folder anywhere)
ruineraz said:
Thanks. Just can't seem to get ssh keys set up... dunno where to put them (don't seem to be .ssh folder anywhere)
Click to expand...
Click to collapse
Good point. You can put the key anywhere, but you need a .ssh directory for the known_hosts file. It should be simple on a Linux based device, but... it's not really.
There is a Cyanogen wiki page about setting up ssh using dropbear, and you can probably get rsync working in a terminal with that.
However, trying to ssh with the normal ssh binary using GScript (to launch the script from home screen) gave me "Unknown own user" errors. To fix it, I replaced the ssh binary (maybe it was a link to busybox or dropbear, I dunno) with a link to the ssh binary from Better Terminal Emulator Pro. I've been doing that through several roms over the past few months and the BTEP ssh always works flawlessly. I run this every time I install a new rom:
rm /system/xbin/ssh
ln -s /data/data/com.magicandroidapps.bettertermpro/bin/ssh /system/xbin/ssh
I checked, and BTEP creates it's own home and .ssh directories at /data/data/com.magicandroidapps.bettertermpro/home/.ssh and the ssh command uses the known_hosts file from there, so basically, BTEP might be the best way to do all this but it costs a few bucks in the market.
This inspired me to start using rsync and I did successfully get it working with the below command:
Code:
rsync -rltDv -e "ssh -l USER -i /data/dropbear/dropbear_rsa_host_key -p XXXXX" --port=XXXXX [email protected]:/home/me/test /sdcard
rltDv is used to get around an rsync bug that gives chgrp errors. The -e command specifies the ssh command to use when connecting and I had to specify the user with "-l username", -i is the key to use which can be anywhere. You don't need the ssh option "-p XXXXX" unless you use something other than 22 for ssh. The same is probably true of the rsync --port=X option, but I didn't test it.
This worked successfully with GScript which is exactly what you're wanting. Here's the only downside.. Better Terminal Emulator Pro costs a few bucks so I don't know if it's worth it to you to get it for a replacement ssh binary that works with GScript.
EDIT: it's 2am and im half asleep so i hope all this makes sense. Can clarify tomorrow if needed
Thanks for the update, just got some time to pick this back up
sent from my nexus one from the future...
http://forum.xda-developers.com/showthread.php?p=8917482&highlight=rsync#post8917482
Don't know if this has been mentioned anywhere, but I'll post it anyway...
This utility will come in handy for those who use terminal emulators. "Bash" features command completion (by holding the center button on the directional pad) and can execute previous commands from history (by pressing Up on the direction pad).
Simply unzip the attachment to anywhere on your SD card, and, using a terminal emulator like ConnectBot do the following:
Code:
cd sdcard/[I]<folder where bash was saved>[/I]
su
sh bash.sh
Or, if you want to run from OpenRecovery, then unzip the files under /sdcard/OpenRecovery/scripts, then edit "bash.sh" so that the "cp bash/bash /system/bin" line is changed to "cp /sdcard/OpenRecovery/scripts/bash/bash /system/bin". To install it, use the "Miscellaneous->Run Script" option from OpenRecovery.
It will automatically take effect as your default shell the next time you start a terminal session or reboot. Or just type 'bash'
Thanks for the script , I havent had a chance to use it just yet but it would be extremely useful
~PsyCl0ne
PsyCl0ne said:
Thanks for the script , I havent had a chance to use it just yet but it would be extremely useful
~PsyCl0ne
Click to expand...
Click to collapse
No problem! It's a time saver for me... no more need to re-type commands or type out the long folder names.
Isnt busybox sh acting the same way ? whats advantage over busybox sh ?
http://www.faqs.org/faqs/unix-faq/shell/shell-differences/
Scroll down till you see a table...
zewelor1 said:
Isnt busybox sh acting the same way ? whats advantage over busybox sh ?
Click to expand...
Click to collapse
I think the most visible is the permanent history.
Busybox has the permanent history as compile option but nobody cares to enable it.
For the rest the busybox's shell is more than enough for the limited usage on a cellphone.
oh this is awesome.
Gonna come in real handy for ro/rw mounting. I'd been cheating by throwing a bunch of common commands into the 'first command' line and saving different connection profiles in ConnectBot
-----
*edit*
bummer, couldn't get Terminal Emulator to initialize the session. Attached is a zip with sh.sh to restore your shell to sh - actually, it just redirects the sym. link from bash to sh (sh0 binary), so you could use it to swap back and forth if you want - bash is left on the system.
Hey guys I basically did everything that the Cricket how to said, but with the Metropcs logins and passwords. I have flashed several phones before, but not an Android OS. The phone works with internet and picture text coming in, but the apps. like Youtube and Google maps will only work on WIFI and not on the network and MMS out will also not work.
My assumption is that it has to do with this whole autostart file thing. I am so new to this programming stuff that I am not sure what to do when it comes to this.
So I used QPST and CDMAW to program the back end so that is probably why the Internet works. APN and Proxy settings are all correct, but here is the only place I have an error.
These are the directions:
Before starting the next step make sure you have the u2nl file and autostart.sh in this folder c:/android/tools
"Now go to the command prompt on your pc and type the following commands:
cd c:\android\tools
adb remount
adb push c:\android\tools\u2nl /system/bin/u2nl
adb push c:\ android\tools\autostart.sh /data/opt/autostart.sh
Now:
adb shell
chmod 0755 /system/bin/u2nl
chmod 0755 /data/opt/autostart.sh
reboot"
My error begins when I type the adb remount.... it states unable to find device or something like that.
I plugged phone to computer not in Diag mode or any mode, just turned it off then back on and plugged it in. Is there a setting on the phone I need to check?
Then I go ahead and do those push commands just for the hell of it, it just scrolls through this whole display of things.. not sure what its doing.
The adb shell part works and so do those other commands after....
When I am done with the last line that has the autostart.sh and hit enter...
The phone doesn't reboot, I just unplug and then turn off and then back on. I would have thought there would be a script to reboot phone or something...
So what am I missing or is it not even possible to get Google maps and youtube to work on Metroweb... has to be on wifi??? I have seen people say they have done it...
Any help would be appreciated..
I don't know how I did it. I don't even know if it's a windows 7 thing, or a adb shell thing. But...
When I open adb shell and enter the "ls" or "ls -l" command, it returns the name of the file/dir in a strange format. Instead of just the name like "sdcard" I get:
<-[1;34msdcard<-[0m
I'm pretty sure it didn't always do this, so I must have enabled a switch somewhere (or I'm misusing the "ls" command). I do not have this problem with Terminal Emulator on the Captivate itself... just when using ADB shell on a Windows 7 machine. How do I turn this off? Any help would be greatly appreciated.
Thanks!
dc41 said:
I don't know how I did it. I don't even know if it's a windows 7 thing, or a adb shell thing. But...
When I open adb shell and enter the "ls" or "ls -l" command, it returns the name of the file/dir in a strange format. Instead of just the name like "sdcard" I get:
<-[1;34msdcard<-[0m
I'm pretty sure it didn't always do this, so I must have enabled a switch somewhere (or I'm misusing the "ls" command). I do not have this problem with Terminal Emulator on the Captivate itself... just when using ADB shell on a Windows 7 machine. How do I turn this off? Any help would be greatly appreciated.
Thanks!
Click to expand...
Click to collapse
ugh, this isn't garbage information or a mistake. this is windows command prompt (which isn't a proper terminal emulator) not being able to deciper the color coding techniques used in *NIX shells.
all these odd numbers are are simply color coding to "prettify" the shell if you're using a *NIX shell
Kaik541 said:
ugh, this isn't garbage information or a mistake. this is windows command prompt (which isn't a proper terminal emulator) not being able to deciper the color coding techniques used in *NIX shells.
all these odd numbers are are simply color coding to "prettify" the shell if you're using a *NIX shell
Click to expand...
Click to collapse
Thanks for the info! Now that I know what's going on, I should be able to find solution on the web.
Thanks!
dc41 said:
I don't know how I did it. I don't even know if it's a windows 7 thing, or a adb shell thing. But...
When I open adb shell and enter the "ls" or "ls -l" command, it returns the name of the file/dir in a strange format. Instead of just the name like "sdcard" I get:
<-[1;34msdcard<-[0m
I'm pretty sure it didn't always do this, so I must have enabled a switch somewhere (or I'm misusing the "ls" command). I do not have this problem with Terminal Emulator on the Captivate itself... just when using ADB shell on a Windows 7 machine. How do I turn this off? Any help would be greatly appreciated.
Thanks!
Click to expand...
Click to collapse
I've never had this happen when I use the adb shell on my Win7 machine. Which distro are you using? I have Home Premium x64.
miztaken1312 said:
I've never had this happen when I use the adb shell on my Win7 machine. Which distro are you using? I have Home Premium x64.
Click to expand...
Click to collapse
Ultimate 64, but like I said, it wasn't always like this. Some point in the lady week I must have changed a setting or something. Now I just have to figure out what I did and how to undo it.
I am guessing you switched ROMs? Seems to be the color setting in some of the ROMs on the LS command. It is not a windows bug, any terminal/shell that doesn't support colored directory/file names will give you this behavior.
See this thread for a fix:
http://forum.xda-developers.com/showthread.php?p=7714491
I have been having this issue since I upgraded to JH3 and SRE 1.2.1a (which included a new busybox 1.17.1 and proper symbolic links). SRE 1.2.1a also remove the stock ls command. I did not start looking into fixing it until tonight. Setting an alias for every adb shell session is annoying. Android does not include any of the profile start scripts like linux does or we would be able to stick an alias in some place like a .bashrc or /etc/bashrc.
Here is a permanent solution. I normally have a permanent alias setup on my linux machines with the switches below, you can modify the switches to your liking.
create a file in notepad with the following:
"ls -alh --color=never [email protected]" do not include the quotes.
Note the switches I am using:
a = show all files including hidden (the ones that start with a "." as a prefix on the name)
l = show files in long listing format/layout
h = show file size in human readable format eg and 1k instead of 1000.
Save the file as "ll" without an extension. You can use another name if you wish.
Use adb to push the file into /sdcard then adb shell to copy it to /system/xbin or copy via root explorer.
#assuming ll is in your SDK tools folder - move to sdcard
adb push ll /sdcard
#move to xbin folder
adb shell
su
mv /sdcard/ll /system/xbin/ll
I didn't touch the permissions (its working with -rw-rwxr-x) but just in case you can set permissions on the file.
chmod 755 ll
I rebooted my phone and I was still good to go using "ll" from adb shell.
adb shell ll
or adb shell
$ll
enjoy.
Mine does the same, looks nice when I am using on Ubuntu. I had flashed JH3 + SRE 1.2.1a also.
Did you try using the "dir" command? I think it comes with busybox 1.7.1. That one outputs fine for me when I am using the cmd prompt. Only little quirk is that I have to remember not to use ls when logged on Win7.
color codes were removed in SRE 1.2.2a: http://forum.xda-developers.com/showthread.php?t=751934
tikidroid said:
I have been having this issue since I upgraded to JH3 and SRE 1.2.1a (which included a new busybox 1.17.1 and proper symbolic links). SRE
Click to expand...
Click to collapse
Your fix worked perfectly for me!
Thanks!
tikidroid said:
Here is a permanent solution. I normally have a permanent alias setup on my linux machines with the switches below, you can modify the switches to your liking.
create a file in notepad with the following:
"ls -alh --color=never [email protected]" do not include the quotes.
Click to expand...
Click to collapse
Ahhh.... thank you so much for this post. This has been driving me crazy for a few hours, and I almost considered putting an alias to ll in init.rc (but I much prefer this less invasive method)
Useful workaround, thanks. Still needed, some two years later!
I have been trying to make this whole adb think work for about twenty hours strait and I still have not gotten very far. I own a mac and no pc and updated to froyo with my buddies pc. I have followed all the directions to a T over and over using terminal on the mac and I can get to the ADB commands and even to where I can see my phone by clicking devices but I must be missing something important. ANY HELP WOULD BE REALLY APPRECIATED I AM ABOUT TO PULL MY FREAKING HAIR OUT!!!
Ok, so if you can see your phone through adb, then you are definitely on the right track. Unfortunately, I'm not really familiar with OS X anymore so I'm not quite sure how to do it. Just sit tight for now until someone who does use a Mac, or has more of a clue then I do can help you out.
But seriously, don't pull your hair out. It won't stay on your head forever ya know...
Edit: oops, just saw this is JI6 (Froyo) not JF6, so I can't help you, but here is a general overview:
from terminal inside Android sdk main directory:
tools/adb devices -> list all devices connected that ADB can see
tools/adb shell -> gets a normal user shell on your phone
tools/adb reboot recovery -> reboots into recovery mode, suitable for update.zip root method
--------------------------------
Place the root update.zip on internal sdcard.
from terminal inside Android sdk directory:
tools/adb reboot recovery
Select the update software option, and you will be done.
laxwillsch said:
I have been trying to make this whole adb think work for about twenty hours strait and I still have not gotten very far. I own a mac and no pc and updated to froyo with my buddies pc. I have followed all the directions to a T over and over using terminal on the mac and I can get to the ADB commands and even to where I can see my phone by clicking devices but I must be missing something important. ANY HELP WOULD BE REALLY APPRECIATED I AM ABOUT TO PULL MY FREAKING HAIR OUT!!!
Click to expand...
Click to collapse
Start simple:
If you open a terminal on the mac, and go to your android SDK tools folder; what happens when you type ADB shell?
Or if you type any of the ADB push commands?
You need to give more detail around what you are seeing for us to help you.
Ok so if I am in terminal and i type in my /android-sdk-mac_x86/tools nothing happens and it just says /android-sdk-mac_x86/tools is a directory. But if I type the same but with /tools/abd it opens the abd command lines, like how to write code. Then when I try to "adb push rageagainstthecage-arm5.bin /data/local/tmp/rageagainstthecage-arm5.bin"
it says "-bash: adb: command not found"
however when I type laxwillsch$ /android-sdk-mac_x86/tools/adb shell
it does give me the drop down $
but when I then try to write the next line of code "chmod 0755 rageagainstthecage-arm5.bin"
it says "chmod: rageagainstthecage-arm5.bin: No such file or directory"
I am stumped I am beginning to think i need to buy a pc as I am very interested in android development and want to learn more, but it seems all the tutorials are run assuming you are on a PC
EDIT** I have downloaded the android SDK started pack, and the 2.2 root pack and they are all in my /android-sdk-mac_x86/tools folder that is directly on my Macintosh HD for simplicity
Do you know how to change directories (cd command)?
The problem is that you are trying to work in one directory, but all your tools are in another.
So change directories to the tools directory:
cd /android-sdk-mac_x86/tools/
now run your adb commands - you may have to type ./adb to tell your mac to look in the current directory for the adb command (that is what ./ means "start here")
Also, try to understand what is happening so you can more easily troubleshoot: chmod is a command to change permissions, and you are running it on the phone. If you can't push the file to the phone, then you can change it's permisssions. I guess you never got rageagainstthecage on the phone, so there is no way to chmod it.
If you can't do this on a mac, a PC is not easier. I use both, and like both, but you need to learn basic commands first - they apply to the mac terminal and the windows cmd prompt.
Getting root means moving in and out of the phone - adb shell - puts you in a terminal on the phone. So you really need to understand cd (change directory); pwd (present working directory - shows you where you are); cp (copy); and know your current path - what the ./ does.
I hope this helps, not trying to sound condescending - maybe practice a linux terminal tutorial would help
Thanks so much, I am at school right now and cant test out all that but you are really helping me understand all this! I will post tonight and let you know how it goes. again thank you
ok so i dont have my usb cable with me but I was playing around with the commands that you suggested and ureka! i finally got to a point where it says "h70-33-65-19:tools laxwillsch$" thats a first! and when i type pwd it shows "/android-sdk-mac_x86/tools" so that means I am working out of the right directory right? and from here I enable usb debugging connect my phone then just copy and paste the codes from the thread correct?
yes, it sounds like you are on the right track. But take it nice and slow when you follow the steps. It is very important that the commands are entered exactly as you see them.
Also, one step tells you to wait for something to run and kick you out of ADB - wait just like it says - takes about 45 seconds but feels like forever.
If you are in the tools directory - just by typing "adb" no quotes will give you whole page of adb commands - if you get a "command not found", then you need to add the ./ and make it ./adb
Hope this helps and again, read the commands step by step a couple times first so you understand what is happening.
In a nutsell, you push the rage file;
change its permissions, run it;
get kicked out of ADB and then open a new ADB shell;
you are now root;
remount the system partition to give you write access when it reboots;
reboot;
push over some files;
change permissions on files you pushed;
reboot;
Some things to know - SU is a command for gaining root access; when you use SU your prompt changes (in adb shell) from $ to #
If you are succesful you should see the SuperUser app listed in your apps.
Done and Done just rooted successfully couldnt have done it without you! thanks so much