I'm accustomed to running scripts on boot in Linux, but I'm not sure how to do this in Android. I'd like to start my SSH daemon on start, so I'll always be able to connect. How can I run an arbitrary script on Android boot? It'd be preferable to do this outside of Dalvik.
Answer
While looking around my Android filesystem, I found that it did, in fact have a /etc/init.d/
directory. After peeking around in there, I found /etc/init.d/20userinit
with the following lines:
if [ -e /data/local/userinit.sh ];
then
log -p -i -t userinit "Executing /data/local/userinit.sh";
busybux chmod +x /data/local/userinit.sh;
logwrapper /system/bin/sh /data/local/userinit.sh;
setprop cm.userinit.active 1;
fi;
This being, of course, exactly what I needed, I wrote the following script on my computer then pushed it to my device:
#!/system/bin/sh
dropbear -s -g
(pushed to device via scp userinit.sh phone:/data/local/userinit.sh
, mind you :] )
Rebooted the device, then ran ps | grep "[d]ropbear"
, and sure enough, it's running. Coolness!
No comments:
Post a Comment