[MOD] Change WiFi hostname - for custom ROMs (Sept 23) - Nexus One Android Development

This is useful for identifying phones on the local networks by looking at DHCP lease tables in the routers. It doesn't make your phone appear on Windows networks, since the phone needs to broadcast NetBIOS name for that. If you want your phone to show up on Windows networks (and share files) - you need Samba server, and JimmyChingala is working on one.
ROM developers can insert the option to customize hostname using the way described below in their Spare Parts options. Feel free to do so.
[SOLUTION]
The following shell command does the job of changing WiFi hostname:
echo YOURHOSTNAME > /proc/sys/kernel/hostname
Click to expand...
Click to collapse
For the change to stay, it should be executed on each boot. And here the things start being more problematic.
For custom ROMs:
Most, if not all, custom ROMs include some user init shell script that will be executed on boot, making the solution easy.
Enter the following line in the Terminal / ADB shell:
echo "echo YOURHOSTNAME > /proc/sys/kernel/hostname" >> the_path_and_name_of_userinit_script.sh
chmod 777 the_path_and_name_of_userinit_script.sh
Click to expand...
Click to collapse
Several examples of custom ROMs and their userinit scripts:
Suggested - will work for most ROMs (creates another file in directory of autoexecuted scripts): /etc/init.d/88hostnameinit
Additional possibility for Enomther's ROM: /data/local/userinit.sh
Additional possibility for CyanogenMOD: /sd-ext/userinit.sh
For stock ROMs:
There is no autorun script for stock ROMs, so they have to be added through modifying boot.img. It's a complicated procedure, and even though guides exist for it - I suggest not to mess with it only because of the hostname. The easiest solution would be to create a script file with the line above using Gscript or other scripting solutions, and execute it after each reboot. If anyone really wishes to modify boot.img - I assume that he/she knows enough about Linux/Android since it can be relatively easily done only on Linux, can find the necessary guides with some googling (like I did), and in this case the modification is easiest to do directly in init.rc - changing "hostname localhost" to "hostname name_of_your_choice".

[ORIGINAL POST]
Hi people,
I'm not much of a dev, but I can find my way around with a bit of Google search And sorry about the links that don't link, new user's permissions don't allow me to...
Anyway, after messing with my router today I've noticed that Nexus transmits "localhost" as its host name to DHCP server, causing my DD-WRT to show it as "*". I went to Google and to my surprise, discovered that there isn't such an option in any Nexus ROM yet.
Found this: LINK_www_laslow_net_?p=501
To change your hostname on Cyanogen 5.x, add the following line to the bottom of /system/etc/init.d/01sysctl -- and make sure you make a backup of 01sysctl before editing it!
echo NEWHOSTNAME > /proc/sys/kernel/hostname
Click to expand...
Click to collapse
I tested it, and it didn't work. After booting, the file still read "localhost" in it, and the hostname on DHCP server reflected it.
But, I didn't get frustrated, connected with ADB, manually executed the command:
echo MyHostName > /proc/sys/kernel/hostname
checked that the file was overwritten, disabled WiFi, deleted DHCP lease, enabled WiFi back - and voila, I have a new hostname!
Then I went to search for hostname setting, which got me to /init.rc:
on boot
# basic network init
ifup lo
hostname localhost
domainname localdomain
Click to expand...
Click to collapse
Well, I guess that's the place. A tiny problem, though - it's in the boot image, which can't be easily modified. Thanks to the latest thread on update.zip creation I can probably do it myself, but I wanted to share the findings and ask for the correct way to implement.
There's a "dirty but functional" way of "disable WiFi - override /proc/sys/kernel/hostname - enable WiFi", and it's probably not a problem to stick it somewhere in the boot sequence, or even write an app that writes those changes to one of the boot scripts and allows configuration of host and domain names. But it's not the best way - DHCP might already give out a lease, and the new host name might not register.
And there's a correct (?) way of doing it, introducing it into init.rc. Since it's "on boot", I suppose that it runs after mounting the partitions - which means that the partitions are already accessible.
In this case, the best way would be executing a small shell script that would check for existence of, say, "/system/etc/settinghostdomainnames.rc" and create a default one if it's not there, then use "import /system/etc/settinghostdomainnames.rc" and set a manual trigger, like the guy is trying to do here:
LINK_groups.google.co.jp_group_android-developers_browse_thread_thread_e2f432707b735ff0
"trigger someeventtobringupnetworkinterface"
That would allow to use a custom setting for host and domain names that can be changed by SW, and adding that as another option into ROM Settings app or external app.
But the guy in question didn't succeed. What did he miss? Would it be better to do something like "on fakesystemproperty=something" and instead of manual trigger, doing "setprop fakesystemproperty something"?
I can probably test it and find out myself, but it would take loads of time compared to one of the kernel devs, and I don't even have the environment set up for modifying boot images. I was kinda hoping that one of the kernel devs would test it. I can write and post the modifications to init.rc and the custom script, they're very simple.
So, who can help me with answering the questions in the thread, and/or testing the modification?

Thanks! It's back.
Oh well, I'll keep preparing Ubuntu VM anyway

OK, first test fired - updated /init.rc in my own boot.img, checked the values. It's working, hostname is indeed modified.
Now I'll try to rewrite /init.rc in such way as to load the hostname setting from elsewhere, while not screwing the security. Will post results soon.

Setting it to the same value as the BT value would be ideal. I'm not sure how you could do that though, because the init scripts run before the frameworks load

Looking forward for a fix to this problem.

Update, but only partially on topic:
God, I hate SH scripting. Couldn't even google a normal tutorial that would explain where I went wrong. A script of 10 lines, and I can't make it work.
Let's see, I need something like this:
#!/system/bin/sh
echo "on service-exited-network_prepare" > /system/etc/net_init.rc
echo " ifup lo" >> /system/etc/net_init.rc
if [ -e "/system/etc/net_init.domain" ];
then
echo "hostname `cat /system/etc/net_init.host`" >> /system/etc/net_init.rc
else
echo "hostname localhost" >> /system/etc/net_init.rc
fi
if [ -e "/system/etc/net_init.domain" ];
then
echo "domainname `cat /system/etc/net_init.domain`" >> /system/etc/net_init.rc
else
echo "domainname localdomain" >> /system/etc/net_init.rc
fi
echo >> /system/etc/net_init.rc
Of course, this thing fails miserably with -
Syntax error: end of file unexpected (expecting "then")
What the hell am I doing wrong? Never used SH before, mostly tcsh and perl.
Thanks.

Oh well, I guess I got the problem.. Unix vs Windows file format. Sorry for bothering.

its always bothered me that you cant change the device name for wifi networks, and ive always looked for a way to change it.
kudos to you for the ambition and diligence to do it!
dont give up, if you can get it smoothed out enough im sure cyanogen will implement it in his next mod. ive always wished there was an option in wifi settings to change device name. itd be very useful for lan ip configuring and when your connected to a random hotspot lol

Ok, after fighting for a day, I still didn't manage to import another .RC file and run on service exit (I don't even see the trace of the process I'm trying to start - the first thing it does is attempting to write log, and there is no log, no matter where I put the start command), but at least for a "quick-and-dirty way" there's a very simple solution, given SD-EXT partition (I believe everyone creates it):
open terminal application, type the following command:
echo "echo YOURHOSTNAME > /proc/sys/kernel/hostname" > /sd-ext/userinit.sh
That would override the hostname of the system before boot completion.

After some reading, I believe there's nothing bad in setting the hostname twice - once default localhost in init.rc, and then overriding it using /proc/sys directory, Linux is designed to cope with that and hopefully so does Android.
So, as to pershoot's request, it's possible to write a small application to read Bluetooth device name value and write it as WiFi hostname, and include it in boot process right before 20userinit.
Now this is a task I'm not suitable for, I have no knowledge of frameworks whatsoever. Anybody up to the task?

Jack_R1 said:
After some reading, I believe there's nothing bad in setting the hostname twice - once default localhost in init.rc, and then overriding it using /proc/sys directory, Linux is designed to cope with that and hopefully so does Android.
So, as to pershoot's request, it's possible to write a small application to read Bluetooth device name value and write it as WiFi hostname, and include it in boot process right before 20userinit.
Now this is a task I'm not suitable for, I have no knowledge of frameworks whatsoever. Anybody up to the task?
Click to expand...
Click to collapse
I requested it and I'm not pershoot

Oops Sorry, my bad. Fever and lots of time in front of the computer don't do me good...

Kudos to you Jack_R1. Watching this.
Let me know if you need any help with shell scripting.

Gonna watch this and try it out later, the solution so far.

is this a stable fix?

is this confirmed to work?

Sorted out, updated with the most current info and several examples of custom ROMs.

Jack_R1 said:
Sorted out, updated with the most current info and several examples of custom ROMs.
Click to expand...
Click to collapse
I am running CM6 with a2sd and somehow the /sd-ext/userinit.rc is not executed. Even if I change permissions of the file to 777, it's not executed.
I also haven't found in init.d the script which executes userinit.rc, might be because I am running custom kernel? (wildmonks).
The only way for me to do it was to put the script in /etc/init.d/88userinit file and change it's permissions to 777

It's /scripts/userinit.sh, not userinit.rc
The execution of /sd-ext/userinit.rc used to be in /init.rc, in boot.img.
But the preferred way for most of the ROMs is to use /etc/init.d/ scripts anyway, since a lot of ROMs use them.
Changed the 1st post to reflect it.

Related

[Q] Cyanogen: Set net.hostname at boot

Android 2.2 sets the default hostname to android_dfhjkahdjksf or something equally useless.
To override this in Cyanogen 6.1 you need to set the net.hostname property with setprop Eg:
# setprop net.hostname mickey
My problem is when I try to set this up at boot, something always overwrites my change with the default. I have tried putting it in my init.rc, /etc/init.d and /data/local/userinit.sh and it is always reset to default by the time the phone has booted.
Does anyone have any more ideas about how to permanently set the hostname? It would be a good option to have in cyanogenmod.
UP. I'm very interesting too.
The root filesystem is stored in the boot.img and is expanded to a ramdisk every time you reboot. For changes to be permenant, you need to extract the boot.img file, extract the kernel and ramdisk sections, modify the ramdisk image with your changes, then recombine the kernel and ramdisk to a new boot.img and reflash it. You'll probably need to do this on a linux machine that understands unix permissions and ramdisk/cpio filesystems as well as having a good knowledge of linux and unix commands. See this thread:
http://forum.xda-developers.com/showthread.php?t=551711
note: your kernel may use a different "--base 0x19200000" option when building the kernel boot image.
Is there not a way to add a correlating line to the build.prop file?
EDIT: This doesn't work - whatever is setting the net.hostname writes out after build.prop is read.
I'm looking...
I did a search in the /system/etc directory for any file doing setprop (I'm using a miui rom) and found the following script. I did the setprop for net.hostname in there and it too is being overwritten.
search command:
grep -H -r setprop /system/etc
/system/etc/init.goldfish.sh
I'm running out of ideas other than using autostart to set it after reboot.
EDIT2: doh. I think I already knew this but it dawned on me that the default net.hostname comes from concatenating the "android_id" (found in the secure database table) to the end of "android_".
So seems more likely to reset it after reboot using a script (gscript to launch it manually or use autostart to launch it automatically at the end of reboot cycle).
Property net.hostname originate from services.jar (ConnectivityServices.java):
Code:
// setup our unique device name
String id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
if (id != null && id.length() > 0) {
String name = new String("android_").concat(id);
SystemProperties.set("net.hostname", name);
}
Maybe CM guys would change this to add another "if /proc/sys/kernel/hostname is different than localhost, use it for net.hostname too" condition.
I'm not using CM so it is up to you guys to make a feature request.
Another approach would be to set service in init.rc that would start your net.hostname changing script on some property being set just after net.hostname is set. You could use also:
Code:
on property:net.hostname=android_blahblah
...but that wouldn't be so handy since you will have to change that line in init.rc every time you make a factory reset.
Really interesting, thx !
BlaY0 said:
Property net.hostname originate from services.jar (ConnectivityServices.java):
Code:
// setup our unique device name
String id = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
if (id != null && id.length() > 0) {
String name = new String("android_").concat(id);
SystemProperties.set("net.hostname", name);
}
Maybe CM guys would change this to add another "if /proc/sys/kernel/hostname is different than localhost, use it for net.hostname too" condition.
I'm not using CM so it is up to you guys to make a feature request.
Another approach would be to set service in init.rc that would start your net.hostname changing script on some property being set just after net.hostname is set. You could use also:
Code:
on property:net.hostname=android_blahblah
...but that wouldn't be so handy since you will have to change that line in init.rc every time you make a factory reset.
Click to expand...
Click to collapse
Thanks a lot. I've been looking for this for the past hour or so. Traditional linux methods to set the hostname don't work... I think I'll add an option in cyanogenmod settings for this and submit it to Gerrit. Look for it to show up within the next day or two.
That's great m8! Cheers
Sent from my HTC Legend
underscores in hostnames are bad
The main thing I want to do is get rid of that underscore. Several of the places I hook up with with WiFi attempt to enter the hostname supplied during the DHCP conversation into a DNS. But underscore is illegal for this purpose.
Numbat.
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A

[HOWTO] Remove bash Color Codes

Anyone who uses the latest roms, mods, etc. is probably using bash. Bash is awesome, bash is great bash is...annoying if you use Windows with adb.
Familiar sight?
bash-4.1# ls
ls
←[1;36mbin←[0m ←[1;32minit.rc←[0m ←[1;34msbin←[0m
←[1;34mcache←[0m ←[1;32minit.smdkc110.rc←[0m ←[1;34msdcard←[0m
←[1;34mconfig←[0m ←[1;32minit.smdkc110.sh←[0m ←[1;34msqlite_stmt_journals←[0m
←[1;34mdata←[0m ←[1;36minit_samsung←[0m ←[1;34msys←[0m
←[1;34mdbdata←[0m ←[1;34mlib←[0m ←[1;34msystem←[0m
←[1;32mdefault.prop←[0m ←[1;32mlpm.rc←[0m ←[1;32msystem.prop←[0m
←[1;34mdev←[0m ←[1;34mmnt←[0m ←[1;34mtmp←[0m
←[1;34mefs←[0m ←[1;34mpreinstall←[0m ←[1;34muserdata←[0m
←[1;36metc←[0m ←[1;34mproc←[0m ←[1;36musr←[0m
←[1;32mfota.rc←[0m ←[1;32mrecovery.rc←[0m ←[1;34mvoodoo←[0m
←[1;36minit←[0m ←[1;34mres←[0m
Now my way:
bash-4.1# ls
ls
bin init.rc sbin
cache init.smdkc110.rc sdcard
config init.smdkc110.sh sqlite_stmt_journals
data init_samsung sys
dbdata lib system
default.prop lpm.rc system.prop
dev mnt tmp
efs preinstall userdata
etc proc usr
fota.rc recovery.rc voodoo
init res
Requirements:
Root.
Clockworkmod Recovery.
My busybox.
My color code removal patch.
Patch
http://dl.dropbox.com/u/2056318/bash_nocolor_1.1.zip
Install both via cwm. Make a nandroid backup first, JUST IN CASE.
If my patch hosed ls on your phone, this should fix it. Sorry about that.
http://dl.dropbox.com/u/2056318/bash_nocolor_fix.zip
Great Work!
What is this?
Did you remove all color from bash, or is it just not doing ls in color by default?
I would recommend people use something like mintty or console2 as their terminal on Windows instead of a regular cmd anyway, for anyone who actually uses the terminal frequently. Well, so console2 gets the same stupid behavior as the standard cmd with escape codes in adb for some reason, but it works with bash color escape codes in general (I have them in my $PS1). Mintty does support escape codes in adb shell, and is generally pretty nice, but doesn't have tabs unfortunately. Just a tip for people.
Nice job for those who don't want to change their terminal, of course. I just feel that for power users mintty is a better solution.
It removes them from ls, which is which is the only place the problem will lie for most windows users. I require my busybox, as there are many versions out there, but mine is the latest, and I know it supports ls. My patch removes the ls binary from Android and replaces it with my own symlink.
As for those options, I will stick with my powershell, but thanks. A poweruser should be using Linux anyway (I do normally).
Ah, yeah, that's probably true. But why is the default ls with colors in Android anyway? I normally need to create an alias to set ls to ls --color=auto or something along those lines usually. Is it just not getting the terminal info properly? I'm just curious about this I guess.
I'm a weird person who uses Unix shells on Windows, I guess because I like games too much.
Its not. ls in itself is a binary, not a symlink. It is running through the bash shell. Bash, is what supports colors. By default Android does not run bash, but sh.
Oh huh, didn't realize Android used sh by default. Guess I never paid attention.
Do you drop busybox in /system/bin to install it? That is, if you aren't flashing it from cwm.
Hate to be the bringer of bad news, but something in this breaks WiFi. After installing it, I can no longer connect to my router, it just stalls at "Obtaining address". When I check the router, it's already assigned an address.
I reflashed DL09 cleanly, and it connects right away. I re-apply this fix, and WiFi stops working again.
I did say make a nandroid backup....right?
Anyway, you are correct. Patch has been removed until I can figure something else out.
I did say make a nandroid backup....right?
Anyway, you are correct. Patch has been removed until I can figure something else out. Please revert to an earlier nandroid.
First post updated with a better fix that disables color for bash, system wide. Thanks to enderst from irc for the help.

[TOOLS] [LINUX, MAC, WINDOWS] Knives & Forks - v. 12.02.04

Knives & Forks
WHAT IS IT?
Knives & Forks is a set of Android tools for everyone. Every operating system, every device.
This cross-platform Android toolkit, written in Python, that is designed to work in Linux, Mac OS X or Windows. I wanted to create something that was unique, and offered a consistent and feature-filled set of tools for Android devs no matter what operating system they use, and for as many Android devices as possible.
WHAT DOES IT DO?
I just started work on this project, so it doesn't do very much yet. Right now we are just focusing on getting drivers and adb installed for as many devices as we can on all three platforms. Once we have adb working for everyone, the real fun can begin as we start to add more device tools that will make use of adb, such as rooting. Eventually ROM customization tools will be added, but we are focusing on device tools and cross-platform compatibility at this time.
View the changelog to see a list of included drivers. The only device that I can confirm is compatible with this script in Linux, Mac OS X, and Windows is the Samsung Galaxy S II, Sprint Epic 4G Touch. This just so happens to be my personal phone, but as I gather feedback I will create an official list of supported devices.
WHERE DO I GET IT?
This project is now being hosted by the Android Creative Syndicate. An up to date link to the most current version of the script, installation instructions for Linux, Max OS , and Windows, and other information can be found HERE. Registration is not required at the ACS forum to download or view installation instructions. You are free to reply in the thread you are reading right now if you don't want to register for another forum.
I HAVE IT INSTALLED, NOW WHAT?
You should be able to open up your terminal application (or command prompt) and run some adb commands. In the future we will be automating adb commands for you, but for now you can try the following as a simple test:
Code:
adb reboot
If everything worked, your Android device should reboot. For further reading on what you can do with adb you can read THIS PAGE.
HOW TO SUPPORT THIS PROJECT
FEEDBACK
Download my script, test it, let me know what happens. Let me know what other features/tools I should add.
THANKS
Hit the thanks button if you like what I'm doing here.
DONATIONS - I don't currently have a link to send me money, but I could quickly set something up if somebody decides they want to help me feed my kid. I am recently unemployed, but I am not relying on my scripting skills to feed my family. Save your cash for a more worthy project, or tuck it away and wait until the project turns into something amazing.
INFORMATION
TELL ME ABOUT YOUR ANDROID DEVICES!
If my script isn't getting adb setup for your device, let me know where to download the correct Windows driver and/or what udev rules I need to add in Linux.
The next phase of this project will be automating the rooting process. If you know the process for rooting your device, please share the details.
HOW TO REPLY TO THIS THREAD
Please do not reply by saying something like "This looks awesome, I'm going to download it now!".
Just download it, test it out, and then tell me about it.
If my script works for you, please don't post something like "It worked for me, this is the best thing since sliced bread!".
At the moment all my script will do is install adb and drivers for your device. In order to test please uninstall any drivers you may have already installed, run my script, then reply with the following information:
Operating System (including version and 32-bit or 64-bit architecture)
Android Device
If you open up a terminal/command prompt window and enter the following command, does your device reboot? If not, do you receive any error messages (while running that command or at any phase of running the Kinves & Forks script)?
Code:
adb reboot
CHANGELOG
Code:
------------------------------------------------------------------------------------
Knives & Forks: Changelog
------------------------------------------------------------------------------------
The most current version is available for download from:
http://knivesandforks.info/releases/knives-and-forks-current.php
**** 12.02.04 ****
http://knivesandforks.info/releases/knives-and-forks-12.02.04.php
- LINUX CHANGES:
-- "python2" is now called by "Knives-and-Forks-Linux.sh" instead of "python" on Arch.
- This prevents starting the script with Python 3, which results in errors.
-- Changes to "scripts/linux/install-adb-linux.sh":
- "su" will be used if "sudo" is not installed, or user doesn't have permissions to use it.
- Added 32-bit libs for more 64-bit distros:
- Arch (new in this release)
- CentOS (new in this release)
- Debian
- Fedora (new in this release)
- Ubuntu, Kubuntu, Xubuntu
- Added Debian version of '/etc/udev/rules.d/99-android.rules'
- Added '/lib/udev/rules.d/92-permissions.rules' for Debian.
This should fix permissions, allowing adb to run without sudo or su.
- WINDOWS CHANGES:
-- Fixed a couple of missing quotes which were breaking things under Windows XP
- "%userprofile%" was coming back as "c:\documents" instead of "c:\documents and settings\username" in a couple of places
-- "c:\python27" is now the only directory where we look for python.exe
- It is faster to download and install Python to "c:\Python27" than it is to search for it elsewhere.
- This will also prevent issues where Python 3 was installed instead of Python 2, since the script currently gives errors under Python 3.
-- Updated amd64 and x86 versions of setx.exe for updating system PATH on XP/VISTA/7
-- PATH is updated with adb.exe location after Python is installed.
-- The computer will now reboot after updating the PATH, to make sure it will be updated before running the main program.
**** 12.01.27 ****
http://knivesandforks.info/releases/knives-and-forks-12.01.27.php
- GENERAL CHANGES:
-- After adb is installed, adb will reset the android device by running "adb reboot" instead of displaying a list of attached devices with "adb devices".
adb was occasionally reporting no devices were attached, when they infact were. When this happened "adb reboot" still worked, so it is a better test to see if adb is setup properly.
-- Friendlier messages during adb install and testing
-- Added a startup check to make sure the script is running from the correct directory
-- Removed empty Project directory, as it is not being used yet.
- LINUX CHANGES:
-- Added support for "lxterminal" and "urxvt" in "Knifes-and-Forks-Linux.sh"
-- Changed idVendors for Linux udev rules to lowercase instead of uppercase.
- WINDOWS CHANGES:
-- Startup script searches for python in "C:\Program Files (x86)" then "C:\Program Files" and "c:\" last.
-- Drivers should now install even if the language is not English
-- Added drivers for Casio C771 G'zOne Commando
-- Added LG drivers
-- Replaced setx.exe
**** 12.01.25 ****
http://knivesandforks.info/releases/knives-and-forks-12.01.25.php
- Replaced "Knives-and-Forks-Mac.sh" with "Knives-and-Forks-Mac.app".
Starting the script on a Mac should now be as simple as double-clicking the new .app file.
**** 12.01.24 ****
http://knivesandforks.info/releases/knives-and-forks-12.01.24.php
- Fixed a typo which caused the script to crash when viewing the credits screen.
- Smarter python fix for Windows users.
-- "C:\" and all sub-directories are searched for python.exe.
-- If python is not not found, it will be downloaded from python.org and installed to c:\python27.
-- If python is found (in "C:\python27", "c:\python", "c:\xyz123", "c:\program files\python27" or in any directory with any name anywhere on drive c:) the main menu script will launch.
- Added changelog.txt to the release .zip file.
**** 12.01.23 ****
http://knivesandforks.info/releases/knives-and-forks-12.01.23.php
- Minor update to fix Python installation for Windows users, which was causing the script not to launch.
**** 12.01.22 ****
(FIRST PUBLIC RELEASE)
http://knivesandforks.info/releases/knives-and-forks-12.01.22.php
- Added option to install adb & fastboot for Linux, Windows, Mac
- Added Linux drivers for:
-- ACER
-- ASUS
-- DELL
-- FOXCONN
-- GARMIN-ASUS
-- Google
-- Hisense
-- HTC
-- HUAWEI
-- K-TOUCH
-- KT Tech
-- KYOCERA
-- LENEVO
-- LG
-- MOTOROLA
-- NEC
-- NOOK
-- NVIDIA
-- OTGV
-- PANTECH
-- PEGATRON
-- PHILIPS
-- PMC-SIERRA
-- QUALCOMM
-- SK TELESYS
-- SAMSUNG
-- SHARP
-- SONY ERICSSON
-- TOSHIBA
-- ZTE
- Added Mac drivers for:
-- Nothing. According to Google, "It just works." Let me know if they are right.
- Added a custom Windows installer with drivers for:
-- GOOGLE
-- HTC
-- HUAWEI
-- SAMSUNG
WHERE DID THE OLD POSTS GO?
In an attempt to reduce unnecessary clutter in my original thread, I created supporting threads in each Android device forum. The whole reason behind posting so many times was to keep certain information in the Chef Central post, and certain information out of it in an effort to reduce clutter. Who wants to read through 50 pages of how this, that, and the other thing is or isn't working on devices that you don't own? That system appeared to work very well, but apparently I broke the rules by posting in every Android device forum.
Learn from my mistakes, don't post similarly worded posts all over the place!
ATTENTION PYTHON PROGRAMMERS:
Any idea on what I can do to make the Python files work in Python 2 and Python 3? I have only tested in Python 2.7.2, but I have received reports that Python 3 gives errors. I'm not really doing anything all that fancy, so I'm not sure if something is just a matter or new syntax or something else needs to be imported or what. Any help would be appreciated.
The next release will call "python2" for Arch Linux users since "python" will use python 3.
ATTENTION LINUX USERS:
I am currently testing my Knives & Forks script in some virtual machines using VirtualBox, as well as my local Xubuntu installation.
For distro specific things (installing 32-bit libs, udev changes, etc) in the next release I will be detecting the distro using the following code:
Code:
echo " -- DETECTING LINUX DISTRO --"
if [ "`cat /etc/issue | grep Arch | wc -l`" == "1" ]; then
DISTRO_NAME="Arch"
elif [ "`cat /etc/issue | grep Cent | wc -l`" == "1" ]; then
DISTRO_NAME="CentOS"
elif [ "`cat /etc/issue | grep Debian | wc -l`" == "1" ]; then
DISTRO_NAME="Debian"
elif [ "`cat /etc/issue | grep Fedora | wc -l`" == "1" ]; then
DISTRO_NAME="Fedora"
elif [ "`cat /etc/issue | grep Ubuntu | wc -l`" == "1" ]; then
# DETECTS UBUNTU, KUBUNTU, XUBUNTU, ETC
DISTRO_NAME="Ubuntu"
else
DISTRO_NAME="UNKNOWN"
fi
echo " - $DISTRO_NAME"
Please let me know what other distros your using and if you are able to find the name using the "/etc/issue" method I am using in the above if statements.
I wrote a bash function to check if sudo is installed, and then to see if the current user has permissions to use sudo. If sudo is not installed, or if the current user does not have permission to use it, su will be used instead. This will be included in my next update, but I wanted to post it here first:
Code:
echo " -- CHECKING TO SEE IF 'SUDO' IS INSTALLED --"
CURRENT_USER=$USER
USE_SUDO="NO"
if [ -f "/usr/bin/sudo" ]; then
echo " - 'sudo' is installed."
echo ""
echo " -- CHECKING FOR PERMISSION TO USE 'SUDO' --"
echo ""
echo " If prompted, enter the password for the user '$CURRENT_USER'."
echo ""
if [ "$(sudo whoami)" != "root" ]; then
echo ""
echo " - Sorry, '$CURRENT_USER' does not have permission to use 'sudo'."
echo " - 'su' will be uses instead of 'sudo'."
echo ""
else
echo " - '$CURRENT_USER' has permission to use 'sudo'."
USE_SUDO="YES"
echo ""
fi
else
echo " - 'sudo' is not installed."
echo " - 'su' will be used instead of 'sudo'."
echo ""
fi
DO_SU()
{
echo ""
if [ $USE_SUDO == "YES" ]; then
# echo " -- USING 'SUDO' TO RUN '$1' --"
echo ""
echo " If prompted, enter the password for the user '$CURRENT_USER'."
echo ""
sudo $1
else
# echo " -- USING 'SU' TO RUN '$1' --"
echo ""
echo " If prompted, enter the password for the user 'root'."
echo ""
su -c "$1"
fi
echo ""
}
# EXAMPLE USAGE OF THE DO_SU() FUNCTION:
# NOTE THAT THE COMMAND TO RUN WITH SU OR SUDO HAS TO BE IN QUOTES
DO_SU "whoami"
I also found out why debian users were being forced to use sudo or su in order to use adb. The next release will include this fix, but for those who might be interested in making this change manually:
Open "/lib/udev/rules.d/91-permissions.rules" as root (su or sudo) in your favorite text editor and find this line
Code:
usbfs-like devices SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, \ MODE=”0664″
Change MODE to "0666"
Code:
usbfs-like devices SUBSYSTEM==”usb”, ENV{DEVTYPE}==”usb_device”, \ [B]MODE=”0666“[/B]
Instead of replacing or modifying your "/lib/udev/rules.d/91-permissions.rules" file, the next version of my script will actually create a "/lib/udev/rules.d/92-permissions.rules" for Debian users that contains only the following:
Code:
# usbfs-like devices
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \
MODE="0666"
This file will load right after the 91-permissions.rules and replace just the usbfs-like devices settings. I'm just doing this with my script so I don't accidently break anything on your system. If you are making the changes manually, editing the 91-permissions.rules file should be all you need to do.
Save your changes and then restart udev as root (using sudo or su)
Code:
/etc/init.d/udev restart
-- or --
Code:
service udev restart
This assumes of course that you already have a working udev rule for your android device, and that adb is working only with su or sudo currently. Once this change is made you should be able to use adb without being forced to use su or sudo.
First post updated with latest release, version 12.02.04.
Lots of changes for XP and various Linux distros. See changelog for more information, but things should work better in Arch, CentOS, Debian, Fedora, and Ubuntu (including Kubuntu, Xubuntu, etc).
Hi, I just downloaded the latest file (12.02.04) but it's only 4 KB.
Could you check please?
Thank you!
Trying to unzip the file in Ubuntu 11.10 and this what I get:
Archive: knives-and-forks-12.02.04.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of knives-and-forks-12.02.04.zip or
knives-and-forks-12.02.04.zip.zip, and cannot find knives-and-forks-12.02.04.zip.ZIP, period.
Any help?
I had a typo in the .zip filename, so if you tried to download the file yesterday you basically just downloaded an error message that the .php counter script gave when it couldn't find the file. I will have to take a look at that later because it is supposed to display the message not make you download it.
The problem is now fixed, sorry about that.
Thanks for update.
Downloaded and installed.
Now I can adb from linux.
Have one more question. I hope you can help me with that as well.
I don't see my device (E4GT) as external hard drive or USB drive when debuging is on to copy files to it.
When debuging is off it shows 2 Android devices but when I click on them I'm getting this message:
Error initializing camera: -60: Could not lock the device
Any ideas?
My guess is maybe they didn't get unmounted properly that last time you had it plugged in, but I have no idea why you would get an error message about the camera. I have not seen that one.
Try installing Dropbox and backing up anything important, then formatting the sdcard and try mounting again.
Maybe somebody else has had that error and has a better idea,
I'll try to format sd card tonight when I get home.
But what would be the problem with internal storage?
And what should or could I try to proper mount it?
agat63 said:
I'll try to format sd card tonight when I get home.
But what would be the problem with internal storage?
And what should or could I try to proper mount it?
Click to expand...
Click to collapse
First thing to check is that it isn't ROM related. Boot into recovery and try to mount as a usb drive and see if it works or not. If it does, I would say wipe and flash another ROM. If it doesn't work from recovery, then it could be a result of not unmounting before unplugging from your computer.
Sometimes if you have your phone mounted as a USB drive, or even just a regular flash drive, and it you unplug it before it is done unmounting (or if you don't use the safely remove hardward feature of Windows) the filesystem can get trashed. It hasn't happened alot with me, and I have seen the problem happen mostly when a flash drive is unplugged before the OS can finish writing to it.
After you get all of your important stuff backed up somewhere like dropbox, reboot into your recovery and repartition the sd card and/or your internal storage, whatever is giving you the problem. When you reboot into android you should be able to use it as normal, and dropbox should automatically copy everything back that you backed up.
This problem isn't really related to my script, so I if you can't get the issue resolved make a new post in Android QA or somewhere else. PM me if you post elsewhere and I can see if I can help you out there.
I didn't mean to say that the problem is related to your script.
Your script works just fine and I'm able to adb.
I'm kinda new to linux and still learning it.
I needed help and advise for how to connect phone to pc in linux.
It works in windows for me.
When I get on my PC I'm gnats give this awhirl. Ad for your mounting disk drives if ur on any ics rom it wont and I don't know how to enlighten me someone but if its gingerb then make sure u mount with the phones option when u plug in on ur handset ther should be some kind of way to switch between teather, disk and charge only? Wat fone u got?
Does this knife and forks compile? What does it do? Sorry to sound like a knob.
Sent from my GT-I9100 using XDA Premium App
This worked for my att gs2.
Sent from my GT-I9100 using Tapatalk
By using the Android Font you are violating their copyright rules. But you are free to modify the Android Robot, as long as you refer to them and say that you have permission.
Bad-Wolf said:
By using the Android Font you are violating their copyright rules. But you are free to modify the Android Robot, as long as you refer to them and say that you have permission.
Click to expand...
Click to collapse
The post where I found the font said it was an Android logo inspired font, and not the actual android logo font.
I have changed the font I'm using, and have updated my logo graphic to fight off any further concerns.
Colliebudz said:
Does this knife and forks compile? What does it do? Sorry to sound like a knob.
Click to expand...
Click to collapse
At the moment it simply automates getting adb setup on Linux, Mac, and Linux.
I have plans to add support for device rooting next, followed by some other adb commands, then rom customization tools as the last stage of development.
Pushing files to the phone, running shell commands, etc, requires that adb is setup properly, so that is where the focus is at right now. Getting the adb & driver installation scripts setup to run on all three platforms is also helping take care of some general troubleshooting, which is good to get out of the way before the main script gets tons of extra features.
All of this info should be in the first post, I'll try to clarify things when I make the next update.
Waddle said:
This worked for my att gs2.
Sent from my GT-I9100 using Tapatalk
Click to expand...
Click to collapse
Thanks for the feedback. What OS?

Is it possible to get some standard linux tools into Android?

Ok, I read through several threads here and there and everything I found out here and there was, well, we do not have these tools/commands, but the discussion went into other directions and where never really answered.
My situation:
I do several thing every day, some of them are fun, others are not. The funny things I mostly do myself by hand. The not so funny things, well, shell scripts are funny.
I startet a terminal on my Android (After 2 days of work to get nslookup and dig running on iOS 5.1.1 together with crontab.) and tested some functions/tools I daily need for some of my shell script:
- chown -> works
- chmod -> works
- nslookup -> works
- dig -> up and running
- simple rm, mv, mkdir, rmdir -> check
- crontab -> WTF?! You serious, I LOVE IT!
- zip -> error <- Ouch, that hurts. Sure, gzip, tar and others are there I hope.
- sudo -> even bigger error
- login -> error <- Don't get me wrong, but when there is root, there are other users, ls -la gives me at least 3 users: root, system, radio, and 4 groups: sdcard_r, cache, system, root
passwd -> Ok, I get it, different usermanagment, but the rightsmanagment seems to be the same than in std. linux. I chowned a dir and chmoded some things for testing purpose and I got no access to these files unless I use a file explorer/manager with root, so there is basicly the same rights managment behind it. Switching chown and chmod back to original state, everything works without root access file manager. Oh and "w" doesn't work, not even "who". lsof returns many things, every app is its own user, well, normal behaviour.
I than tested some variables, that are standard, even on iOS (Without doing more than jailbreaking and installing a terminal.)
sudo echo $SUDO_USER -> error <- clear, we have no sudo.
su echo $SUDO_USER -> empty <- Yep, no sudo, no $SUDO_USER
su echo $SU_USER -> empty <- I guessed it, because, well, we have nothing else to guess.
Since variables return empty even when they are not set or do not exist, we can't say that this will work in any way unless we know every damn variable set in the whole system. $SUDO_USER in a normal *nix enviroment returns empty when no sudo is in use currently. If in use, it will return the current user that is running sudo, normaly the logged in user or the corresponding worker taskname that is set in the system. lsof on Android shows many app_XX entries, so like normal under *nix.
Ok, my question:
Would it be possible to get sudo, zip and the $SUDO_USER running on Android? I don't mind the possible security issues that could come with this, I have several SGS2 and 2 of them have no SIM card, these are only gadget tools for command line and other stuff. There is no data on these SGS2 that are important.
Discussion about pro and cons are not welcome. This is just a possibility question. My Linux skill is to low to get these things done myself, so I ask you people who know more about this. And yes, I try to get some shell scripts running on my androids, why not use these wonderful gadgets for productity when most of the people waste time with FB, twitter and co on their mobiles.

[Q][SOLVED]Writing into ramdisk from init.rc

EDIT: The solution is in post #6.
Hi,
I'm trying to make a kernel modification which would create a file on boot before any partition is mounted. I wrote a simple shell script which tries to create a file in the root directory. The problem is I can't write any file to the / directory from a program or a script called by exec from init.rc. If I run dmesg, I can't find any indication of a problem there. I tried to modify the script to write to the /data directory on post-fs, and that worked, but that is not what I want.
I can't find out where the problem is. Do you have any ideas? Thanks.
simplified init.rc snippet:
Code:
on fs
# some work
exec /sbin/busybox sh /test.sh
# some other work
mount_all /fstab.grouper
# and another work
/test.sh
Code:
#!/sbin/busybox sh
echo "test" > /test
/ mounts as ro pretty early...
try to remount it rw before making files, or change the part of init.rc that mounts it ro.
frantisek.nesveda said:
Hi,
I'm trying to make a kernel modification which would create a file on boot before any partition is mounted. I wrote a simple shell script which tries to create a file in the root directory. The problem is I can't write any file to the / directory from a program or a script called by exec from init.rc. If I run dmesg, I can't find any indication of a problem there. I tried to modify the script to write to the /data directory on post-fs, and that worked, but that is not what I want.
I can't find out where the problem is. Do you have any ideas? Thanks.
simplified init.rc snippet:
Code:
on fs
# some work
exec /sbin/busybox sh /test.sh
# some other work
mount_all /fstab.grouper
# and another work
/test.sh
Code:
#!/sbin/busybox sh
echo "test" > /test
Click to expand...
Click to collapse
I am having the same problem, my script is not called. Did you find the solution?
Khaon said:
I am having the same problem, my script is not called. Did you find the solution?
Click to expand...
Click to collapse
Not yet. But recently I got back to the project where I would use it, so maybe I can take a look again and see if I am any wiser now. I'll try to solve it this evening or tomorrow, I'll be reinstalling my tablet so I'll have a good oportunity. I'll post the results here.
frantisek.nesveda said:
Not yet. But recently I got back to the project where I would use it, so maybe I can take a look again and see if I am any wiser now. I'll try to solve it this evening or tomorrow, I'll be reinstalling my tablet so I'll have a good oportunity. I'll post the results here.
Click to expand...
Click to collapse
That would be great, the only thing I could see is upon booting its permissions are read-only. And chmod 0777 doesn't change its permissions(rootfs is rw)
Khaon said:
That would be great, the only thing I could see is upon booting its permissions are read-only. And chmod 0777 doesn't change its permissions(rootfs is rw)
Click to expand...
Click to collapse
OK, I found the cause of the problem and the solution.
The implementation of the exec command in Android init scripts is missing from the init binary by default - the source looks like this:
Code:
int do_exec(int nargs, char **args)
{
return -1;
}
So there are two options - either write the do_exec function yourself, or use a trick to execute your programs.
Writing it yourself would be probably cleaner, but it would mean compiling the init binary again and not everyone wants to do that, so I'll be using the trick.
The trick is to register your program as a service and then invoke it via the start command.
Example init.rc:
Code:
# service invocation - where you need it
# warning - this will not wait for the finish of the program
start my_awesome_program
.
.
.
# service declaration - along with other declarations at the end of the file
service my_awesome_program /sbin/my_awesome_program
disabled
oneshot
If you want to implement the do_exec function and use the exec command, you can use for example CyanogenMod's implementation.
There may be a third option, but I haven't tested that - you can copy the init binary from a kernel which has the exec command working - I suppose all CM kernels should, but I haven't tried.
It's funny how when you already know the solution, you can find so much info, but when you don't, nothing comes up since you are searching wrong.
frantisek.nesveda said:
OK, I found the cause of the problem and the solution.
The implementation of the exec command in Android init scripts is missing from the init binary by default - the source looks like this:
Code:
int do_exec(int nargs, char **args)
{
return -1;
}
So there are two options - either write the do_exec function yourself, or use a trick to execute your programs.
Writing it yourself would be probably cleaner, but it would mean compiling the init binary again and not everyone wants to do that, so I'll be using the trick.
The trick is to register your program as a service and then invoke it via the start command.
Example init.rc:
Code:
# service invocation - where you need it
start my_awesome_program
.
.
.
# service declaration - along with other declarations at the end of the file
service my_awesome_program /sbin/my_awesome_program
disabled
oneshot
If you want to implement the do_exec function and use the exec command, you can use for example CyanogenMod's implementation.
There may be a third option, but I haven't tested that - you can copy the init binary from a kernel which has the exec command working - I suppose all CM kernels should, but I haven't tried.
It's funny how when you already know the solution, you can find so much info, but when you don't, nothing comes up since you are searching wrong.
Click to expand...
Click to collapse
Oh my, many thanks! So stupid exec always return ;D, wouldn't have thought one sec on checking the implementation of those functions.
Khaon said:
Oh my, many thanks! So stupid exec always return ;D, wouldn't have thought one sec on checking the implementation of those functions.
Click to expand...
Click to collapse
A small warning - starting the program as a service will not wait for the program finish, so its results will not be available immediately after the start call. I learnt this the hard way after a few hours of debugging just now.
I added this info to my previous post too.
frantisek.nesveda said:
A small warning - starting the program as a service will not wait for the program finish, so its results will not be available immediately after the start call. I learnt this the hard way after a few hours of debugging just now.
I added this info to my previous post too.
Click to expand...
Click to collapse
I always use
Code:
class core
user root
in addition to oneshot.
Haven't you com accross SElinux restrictions using busybox? Because I do I need to set permissions.
I have this issue

Categories

Resources