[GUIDE] SManager - How to use Commands - General Questions and Answers

Hi,
I want to learn some of the commands for use in SManager (Script Manager) for ANDROID.
https://sites.google.com/site/devwom/script-manager
Does anyone know a suitable thread with guide or commands for SManager? I tried searching the web and XDA but did not find anything myself.
Specifically I want to know the cmd line to start an app.
EDIT 1:
Spent a good few hours trying to google a solution but drawn a blank.......Maybe Shell Scripts for Linux are not same as for Android...?
I would like to be able to run a script that does the following:
Checks if a directory exists on the sdcard
then executes a command (renaming of 2 directories)
then starts a program
EDIT 2:
well a few emails with the author of SManager and I was able to write my first script to check if the app is running and then if not, to rename folders and start the other version of the app. (I have Navigon Europe as well as Navigon Australia and was looking for a solution to allow both to co exist on my One-X at the same time. As both apps share the same directory structure the issue was that starting one version would overwrite the critical files of the other).
Now with my script installed as a widget I can toggle between each version without problem.
Here is some useful information on shell language for others (credits to the author of SManager Devwom):
http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Here are some critical bits of info received during my emails with him:
Thanks a lot for your interest in SManager.
The requested commands is a mix between linux commands and android os commands.
To get info about each command you can search in google and select the preferred page.
But the commands available in each Android device depends on running rom.
To get all available commands in your device, simply execute a ls (lower case LS) in system directories, that is:
ls /system/bin
ls /system/sbin
ls /system/xbin
ls /system/usr/bin
ls /system/usr/sbin
ls /system/usr/xbin
These are the most common directories where binaries resides in android devices.
May be you also can have commands at:
ls /bin
ls /sbin
ls /usr/bin
ls /usr/sbin
usually android rooted roms have the well known busybox, to get a list all comands inside it simply execute
busybox
to get all installed packages (and running names) from your device you can execute:
pm list packages
to get info about running process
ps
or
ps aux
or
ps -aux
depending on ps version installed
If conditions are based on test bash command this command is a bit confused, because usually it is named as [, and other times it is built-in inside shell
read "test man page" to get a full list of test command flags.
To check if an app is running:
if [ -n "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is running
fi
To check if app is NOT running:
if [ -z "$(ps|grep os.tools.scriptmanager)" ] ; then
echo SManager is NOT running
fi
To check if a file exist:
if [ -e /sdcard/file ] ; then
echo /sdcard/file exists
fi
To check if a file exist and it is a directory:
if [ -d /sdcard/file ] ; then
echo /sdcard/file exists and is directory
fi
To rename a directory simply use mv command:
I hope you can build your script with this info.
Start app it is very easy but getting correct info to start app is a bit confused.
starting app uses "am command"
To get correct info to start app you should execute:
logcat |grep Starting
in a terminal on device
then go to launcher and launch desired app
then go back to the terminal and you will see a line with info about how to fill am command.
For example if you execute SManager
in
logcat|grep Starting
output you will see
I/ActivityManager(* 275): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=os.tools.scriptmanager/.launcherActivity } from pid 377
so to start scriptmanager you need the following command
am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n os.tools.scriptmanager/.launcherActivity
I do not know how to stop apps from command line, I usually use killall command:
killall os.tools.scriptmanager
if you do not have killall command you can use grep and awk or cut commands
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|awk '{print $2;}')"
or
kill "$(ps|grep os.tools.scriptmanager|grep -v grep|cut -f5 -d" ")"
may you need adjust -f5 flag
To execute script as shortcut install SMWidgets.
Scripts usually ends with last line , ie, not special action is required, it will exit with the last executed command return code
Also you can add
exit 0
or preferred exit value, but 0 usually means OK
To end script in the middle use
exit value
where value usually it is not 0
Also it is better use mv command instead rename command.
rename command it is not linux standard, but mv command is in all linux shells.
Android shell programing it is not equals to linux shell programming but this was one of my first scripting documents many years ago and it can be used as a guide. http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
Best regards,
Devwom

Thanks, this is valuable information! It's a shame this thread didn't get more replies
I've been looking to change my wallpaper by script, but so far I haven't been succesful. With your guide, I guess I'm a step closer to my goals!

Hi.
Perhaps developer of smanager or any expert is reading...
I would like to write a script for 2 purposes. Both handle with samba share running on my ubuntu.
1st situation.: I would like to move my media, download and documents files from android to the desired folder on my Ubuntu, which is shared by samba in my LAN.
The goal is to start this script with just touching a widget.
2nd situation: I would like to copy files from my samba shared folder in ubuntu to a specific folder on sdcard in android. All files in folder on sdcard should be deleted before copying. Again just by touching a widget.
Shared folder on samba are with password and rw.
Till now I am doing it manually with esexplorer...
I would like to do it with script.
Sent from my Incredible S using xda app-developers app

Related

A Real Linux Android System

Before reading.
This article requires that your phone is Rooted and has Busybox installed.
HTC owners, S-off your phone as well.
Android is a great operating system for SmartPhones. Only problem with it (From a more technical users point of view) is the small useless bad excuse of a linux system running behind the UI. Some of the smaller issues can be fixed by installing Busybox that provides a better basic set of tools to work with, but it's not enough. What I would like is to be able to use almost any real linux cli application, daemon, library etc. Also some compilers would be great. I'm using an HTC desire which has more than enough power to do things like compiling (I know, I have done it.), and so has a lot of other SmartPhones. Why would one need this when there is cross compilers you can use on regular and faster machines? Well, because It's fun, why else. I did not spend all that money on a SmartPhones just to make a few phone calls and write a few text messages. My old Sony Ericsson did that quite well. I spend that money to get a phone with many possibilities that I could play with.
I tried to search the web for some helping instructions on how to port a real linux system to this phone. What I mostly got, was people who ported linux systems that would run as an extra OS on the phone, some even with an Xserver accessible via VNC. Sounds fun, but not what I was after. I did not want an extra OS using CPU and unnecessary RAM. I just wanted some extra tools, libs etc to work with and the regular linux user management. I managed to find an old article from someone using Debians armel version on an old G1 phone. I thought that if it worked on that phone, it would be possible to do so on mine. So I started playing around with that.
The way this works is by installing a bare minimum debian on an second partition. This will not boot anything up since it will just work as extra tools and lib using the already booted android linux system.. You will still only have one OS but more tools (Including the nice APT package system) to work with.
Now there is two ways of using debian on android.
The first way is to setup the Debian in an chroot environment. This has some flaws like I have not yet been able to make the chroot start second jobs, which means that you will be able to start applications and daemons running in the current shell session. But you will not be able to make them run in the background. But as an development environment it will still work great, as you will be able to use the Debian libs and compilers.
The second way (The way I was after) is to setup Debian using the UAFS kernel module. This is used to merge directories into one with different rules for each. For an example you would be able to merge /debian_root/etc and /system/etc into a shared /etc with RW on Debians etc and RO on Androids forcing any changes to be made in /debian_root/etc. Using this option you will use Debian to extend the Android Linux part. Android UI with Debian Shell.
This article is split into 3 parts. The first part is the setup of Debian. Must be done whether you want chroot or a merged system. In the second part we will cover the setup of the chroot environment.
The third part is the setup of the merged system. This will require one thing in order to work.
You will need a kernel with the uafs module which is not default in most android kernels. You will need to compile your own kernel. People using the Thalamus kernel, can download a kernel with this module kernel-2.6.37.2_AUFS.zip. A big thanks to Thalamus for providing this. Note that this kernel was a special request from me that he was kind enough to provide. It comes with absolutely no guaranties. Do not email spam him about errors you might encounter using it as this is not an official release.
Note that once you mount the Debian system, you will not be able to mount the SD Card when connecting it to your PC. You can download the App “Multi Mount SD-Card” from Market which will be able to mount your SD Card on your PC while mounted on your phone. This app should also speed up transfers on 2.6.37 kernels, or so I have heard.
Part 1: Building Debian
We are going to run debian from a file containing a ext2 filesystem. If your SD Card is big enough you might be able to create an extra partition and force it to mount as something else other than ext-sd, but in this article we are going to use a partitioned file.
Also, this will require that you have the tool “debootstrap” on your PC. This is found in Ubuntu and Debian, dont know about other Linux distro's or Operating systems. If you don't use Linux or an distro with debootstrap you can download a Ubuntu Live CD from the Ubuntu website. This can be run on CD, DVD and USB disks without installing it. For this article I have used Ubuntu 10.10.
Open a terminal on your Ubuntu/Debian/LiveCD PC and cd to the folder where you want to temp. store your debian. I will call this path “debian_dir”
The first thing we will do is to create the partitioned file.
I'm creating a file with 1.5GB of space. You can create the size you want.
Don't use 0 in the size, dd don't like that.
Code:
cd debian_dir
dd if=/dev/zero of=debian.img seek=1499999999 bs=1 count=1
mke2fs -F debian.img
mkdir debian
mount -o loop debian.img debian/
Now that we have created the file and mounted it, we should download and place debian inside of it. First we will install debootstrap.
Code:
apt-get install debootstrap
debootstrap --arch armel --foreign squeeze debian http://ftp.us.debian.org/debian
umount debian/
Debian Squeeze is Debian 6.0 which replaces the old Lenny.
Copy the debian.img file to your SD Card on your phone. I placed mine in the root of the SD Card.
Now open a terminal on your phone. You can download one from market. There are some free once, but the paid “Better Terminal” is the best to work with in my opinion.
Note: All shell work is done on the phone from now on.
First we need some temp. exports.
Type the fallowing:
Code:
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
export HOME=/root
export TERM=linux
export DM=/data/local/debian
export DI=/sdcard/debian.img
Now we will create the Debian dir and then create a loop device which we will use to mount the Debian image to the Debian dir.
Code:
mkdir -d $DM
mknod /dev/loop0 b 7 0
mount -o loop,noatime $DI $DM
Now that we have debian mounted in our debian folder, we need to finalize the installation. Not all files as been installed yet. Don't forget to activate Mobile Network or Wifi.
chroot $DM /debootstrap/debootstrap –second-stage
We also need to insert the debian repository and a DNS (I use OpenDNS).
You can use whatever you want for the DNS, you routers IP for an example. It should have some default Ips configured.
Code:
echo “deb http://ftp.us.debian.org/debian squeeze main contrib non-free” > $DM/etc/apt/sources.list
echo “208.67.222.222” > $DM/etc/resolv.conf
Now change the root to the debian dir and set a root password and make sure that certain folders already exists.
Code:
chroot $DM /bin/bash
passwd root
mkdir root
exit
Now we need to make sure that certain variables exists and that the values is as they should be. So we will alter the /system/bin/sh that android uses as login shell.
Code:
cd /system/bin
mv sh sh0
Create a new /system/bin/sh file with the fallowing content.
This will ensure that these variables is created and/or changed every time you enter a new shell session. You can call another shell like bash or ash instead /system/xbin/sh, just make sure to use ash or sh at the top, since bash does not seam to understand [email protected]
Warning: It is very important that the /system/bin/sh file is made correct. Android will not boot if anything is wrong with this file. It should be exactly like the one I posted, and you cannot make it on your PC and push it to the phone. Don't know why, it works fine with other shell scripts, but not that one.
Enter an adb shell from your PC and use vi or nano (You can download nano here here) to copy and paste the content directly into the ADB Shell.
Note: ADB from the recovery will always work. It does not use /system/bin/sh
Code:
#!/system/xbin/sh
/system/xbin/sh --login [email protected]
Make sure that it has execute rights. Then type sh in the terminal to make sure that it works before you close your ADB Shell session.
Code:
chmod a+x /system/bin/sh
sh
sh0 will not be used, it's up to you wether you want to save it or not. Just make sure that /system/xbin/sh exists, otherwise
copy /system/bin/sh0 to /system/xbin/sh.
Now we need the profile file that is needed by this method. This file will make sure that we have all our variables and the data that they should contain.
Android does not keep very good track of these things. Place this data in the file /system/etc/profile
Code:
export TERM=linux
export TERMINFO=/etc/terminfo
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/vendor/bin:/system/bin:/system/xbin
if [ "$EUID" == "0" ]; then
if [ -z "$HOME" ] || [ -z "$USER" ] || [ -z "$GROUPS" ]; then
export HOME=/root
export USER=root
export GROUPS=0
fi
else
# Make sure that this user id variable exists.
if [ -z $EUID ]; then
export EUID=$(echo $(id | cut -d "(" -f 1) | cut -d "=" -f 2)
fi
# If we have an /etc/passwd file available,
# we should also make sure to get name, group and home info from that file and
# store in the default linux variables.
if [ -f /etc/passwd ]; then
# Create the user info variables based on user id and /etc/passwd
export USER=$(grep "x:${EUID}:" /etc/passwd | cut -d : -f 1)
export GROUPS=$(grep "x:${EUID}:" /etc/passwd | cut -d : -f 4)
export HOME=$(grep "x:${EUID}:" /etc/passwd | cut -d : -f 6)
fi
fi
export ADID=$EUID
if [ "$PS1" ]; then
if [ "$BASH" ]; then
# The file bash.bashrc already sets the default PS1.
if [ ! -z $HOME ] && [ -f $HOME/.bashrc ]; then
. $HOME/.bashrc
elif [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
else
export PS1='\h:\W\$ '
fi
else
if [ "$EUID" == "0" ]; then
PS1='\w # '
else
PS1='\w $ '
fi
fi
else
PS1='\h:\W\$ '
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
We will also need an /etc/bash.bashrc which is needed because /etc/profile not always gets executed.
Code:
if [ "$ADID" != "$EUID" ]; then
# Some times /etc/profile is not executed (For an example when using Androids su command).
# /etc/bash.bashrc however it used instead. So we just execute it manually in these cases.
# If you create a local bashrc ($HOME/.bashrc), remember to include this check.
# /etc/bash.bachrc is not used when a local file exists.
if [ -f /etc/profile ]; then
. /etc/profile
# Since /etc/profile links back to this file,
# we will make sure not to start an unending loop.
# the profile file should update this, but it's better to be on the safe side.
if [ "$ADID" != "$EUID" ]; then
export ADID=$EUID
fi
fi
fi
PS1='\h:\W\$ '
And last we have some user and group configurations in order to make Debian better work with Android. Open your Android terminal emulator and make sure it opens as user and not root. Now type "/system/xbin/id".
What we need here is the uid, gid and the ids of each accosiated groups along with the names of it all. In my terminal I have "uid=10048(app_48) gid=10048(app_48) groups=1015(sdcard_rw),3003(inet)".
What we will do it create this user along with the groups in our Debian inveroment. However, I use the uid name and gid name "bterm" instead of app_48, but still with the original IDs. The inet and sdcard_rw groups will be created as system groups. Do the same for your app user and group if you don't want any login possibilities with this user. I however have assigned home and password to this user.
This needs to be doen in chroot
Code:
chroot $DM /bin/bash
groupadd --system --gid 1015 sdcard_rw
groupadd --system --gid 3003 inet
groupadd --gid 10048 bterm
adduser --home /home/bterm --gid 10048 --uid 10048 bterm
gpasswd -a bterm sdcard_rw
gpasswd -a bterm inet
exit
Now your ready for the next step. Remember that the user you have created, is the user used by your terminal emulator when you are not logged on as root. This ID is only assigned to that specific app, if you install another terminal, it will get another ID.
Part 2 – Setting up a chroot environment
The best way of doing this is to make two small scripts and place them in /system/bin or /system/xbin. One script for doing the mount after phone boot. And one script for entering the chroot when open a new shell session.
Here is the mounting script that I call mkdebian.
This needs to be executed once every time the phone has rebooted. If your ROM supports init scripts, you can add it there for auto-mount on boot.
Code:
#!/system/bin/sh
export DM=/data/local/debian
export DI=/sdcard/debian.img
# Create the loop device and mount the debian image
mknod /dev/loop0 b 7 0
mount -o loop,noatime $DI $DM
# Let's make sure that we can access our sd card from within the chroot
if [ ! -d "$DM/mnt/sdcard" ]; then
mkdir $DM/mnt/sdcard
fi
mount --bind /mnt/sdcard $DM/mnt/sdcard
# Now we make sure that the chroot has access to all the device maps
if [ ! -d "$DM/dev" ]; then
mkdir $DM/dev
fi
mount --bind /dev $DM/dev
# We also need to make proc, sys etc available from within the chroot
chroot $DM mount -t proc proc /proc
chroot $DM mount -t sysfs sysfs /sys
# And last fix the mtab
chroot $DM rm -f /etc/mtab
chroot $DM ln -s /proc/mounts /etc/mtab
echo “Debian was mounted in $DM/”
Now for the script that I called “debian”.
This script will make you enter the chroot environment using one single command. Every time you exist the debian chroot, you can enter back using the command “debian”.
Code:
#!/system/bin/sh
chroot /data/local/debian/ /bin/bash
And that is it. Open a terminal, type debian and start using your debian environment. It might be a good idea to run aptitude update or apt-get update before you start using the package manager.
Part 3 – Settings up a merged Android/Debian environment
This is the fun part to play with. A merged Android/Debian environment without the usage of chroot. This only requires a script to be executed at boot, or after boot.
Remember that this will not work unless your kernel has the aufs module.
Code:
#!/system/xbin/sh
export DM=/data/local/debian
export DI=/mnt/sdcard/debian.img
# Now we mount the debian image to our debian folder.
mknod /dev/loop0 b 7 0
mount -o loop,noatime $DI $DM
# These two directories exists in both android and debian,
# so these are going to be merged together.
mount -t aufs -o dirs=$DM/etc=rw:/system/etc=ro aufs /system/etc
# For some reason, mounting /sbin with aufs does not work.
# So we make a little cheat with symbolic links instead.
mount -o remount,rw /
mv /sbin /sbin0
ln -s $DM/sbin /
rm -rf /sbin/adbd
rm -rf /sbin/ueventd
ln -s /sbin0/adbd /sbin/
ln -s /sbin0/ueventd /sbin/
# Let's get all the debian root directories out to the real root dir.
rm -rf /root
for x in tmp root lib bin boot home media opt selinux srv usr var
do
ln -s $DM/$x /
done
if [ -f /system/xbin/bash ]; then
mount --bind /bin/bash /system/xbin/bash
mount --bin /system/xbin/bash /system/xbin/sh
else
mount --bind /bin/bash /system/xbin/sh
fi
echo "Debian has been merged with Android..."
Run this at startup and start using all of debians possibilities (Don't run it yet).
The / dir is left with RW permissions. If this is set to RO then apt-get will not work. It writes tmp log files to this dir when running. It does not matter since all changes to this dir is restored to default on every boot.
Also dont forget to run apt-get update or aptitude update to update the package list.
You are now able to install and run almost anything (CLI Only) that runs on debian systems and other linux dists. Personally I'm currently running OpenSSH Server and Lighttpd with PHP. A perfect small transportable web server.
You can use either /etc/init.d/[your service] start
or
service [your service] start
to start daemons you have installed.
Now you can use the "mkdebian" command to merge your new Debian with Android.
Note: The command “su” from debian works differently than the android “su” command.
The debian command uses the regular linux management to provide access which means that it will ask for your root password that you created in the first part. The android command will just provide you with su rights without a password. Both commands provides su rights to both android and debian, so it is possible to remove the android command and create a new Android/Java based SU app for the Android UI that will require root password.
Note: There is a small problem with the Android "su" command. It does not recheck the /etc/profile.
That means that if you log on using the regular user, and then uses the "su" command, user variables does not get updated with su paths.
Using the Debian "su" command will work fine, just note that this command will promp for password. Also logging in using the root account
directly works fine.
Good luck
[Edit: 2011-03-09 11:06]
- Changed the /etc/profile script in Part 1
- Added /etc/bash.bashrc script in Part 1
- Changed User and Group setup and moved it from Part 3 to Part 1
- Fixed error in /system/bin/sh
All of this will fix some permission problems with Debian
[Edit: 2011-03-08 11:21]
- Fixed problems with user management by adding an /etc/profile and changing /system/bin/sh and the debian merge script. Using the "login" command is no longer needed.
[Edit: 2011-03-07 08:49]
- Fixed bug in Part 1 sh script.
[Edit: 2011-03-07 00:20]
- Added a new /system/bin/sh script to Part 1
- Added the way we create missing users and groups in Part 3
[Edit: 2011-03-06 19:36]
- Inserted a warning text in part 1 about avoiding problems when creating a new /system/bin/sh.
Applying Host name
If you want to set a custom hostname for your phone, you can create an init script (If your ROM supports it).
Code:
#!/system/bin/sh
# Get the hostname if it exists, or set it to localhost
if [ -f /system/etc/hostname ]; then
_HOSTNAME=$(cat /system/etc/hostname)
if [ -z $_HOSTNAME ]; then
_HOSTNAME=localhost
fi
else
_HOSTNAME=localhost
fi
# Update the Hostname
echo "$_HOSTNAME" > /proc/sys/kernel/hostname
# Update the hosts file
echo "127.0.0.1 localhost.localdomain localhost" > /etc/hosts
# If the hostname is not localhost, we add one more line to the hosts file
if [ "$_HOSTNAME" != "localhost" ]; then
echo "127.0.0.1 $_HOSTNAME" >> /etc/hosts
fi
This will look in /system/etc/ for the regular linux hostname file. If it exists, it will take the hostname from that file and set as the global hostname.
If it does not exist, "localhost" is used instead. Also it creates the /system/etc/hosts file.
Add or Edit your hostname like this.
Code:
echo "myhostname" > /system/etc/hostname
Note: Remember to delete the hosts and hostname files in your debian /etc/ dir when using merged environment. Otherwise they will overwrite the once in /system/etc/ as debian has first priority.
Manipulating the Android Permissions
Androids permissions works by providing a User ID for each application. This user (Application) can then get a range of different permissions by being added to groups with the permissions required by the app. For an example an app that needs to write to the SD Card, should be a member of Androids sdcard_rw group which translates into 1015 in a Linux group id. Using the numeric values of the Android groups, we can assign these permissions to shell users, daemons etc.
An example:
I had problems with my Http Server because I wanted my www folder on my sdcard. But, the www-data user and group could not be allowed to write to the SD Card, which I needed it to do, because Android controls what permissions the SD Card should have, not even root can change that.
What I did was creating a system group that I named sdcard_rw (Same name as the android, just to better keep track of the groups) with the same Id as the Android sdcard_rw (1015). I then assigned that group to my www-data user (gpasswd -a www-data sdcard_rw) and now my lighttpd had Read/Write access to my sdcard.
You can use the same example for creating a regular SSH User by using the Android shell group or for any other type of user that needs some Android permissions to work properly.
[Edit: 2011-03-08 21:13]
- Added an permission example
Great...
I was just looking into this myself for the last few days.
strange how there isn't more of this being talked about.
at least I have been unable to find anything.
Omg this sounds awesome,
Will try this when u get home and will report back
Sent from my Nexus One using XDA App
I'm still trying to work out some problems with User Rights on SD Card. Can't get lighttpd to be allowed to create files in my SD Card www dir (Does not matter what user and group I set it to use). I can't even get the root account to be allowed to change permissions on SD Card files and folders. It's not the biggest problem, but will report back when I figure it out.
Nice! I've been constantly disappointed for the past year at how un-Linuxy Android is under the hood and unimpressed with the old chroot tricks. This looks much better and I'll try it soon.
I have added a new /system/bin/sh script that can be found in Part 1. This script will automatically look for bash and, if that exists, try to find bash.bashrc, .profile or .bashrc in /etc or the users home dir. If bash does not exist, it looks for sh instead. If you have both one of the Android specific compiled bash, then Debians bash is used when available as this is made to work in a real linux environment. Android bash does not seam to work that way. Also debians packages gets updates via APT.
Also I changed the way groups and users is created in Part 3. Manually inserting them to /etc/passwd, /etc/shadow and /etc/group did not seam to be enough. The users and groups where only half registered. For an example the command "login" gave me a lot of errors, and i had problems with user rights. By using adduser and addgroup in a chroot before the first merge, the user management seams to work as it should now.
I was playing with Debian on my phone just a few days ago too. I've found that same G1 article you mentioned, and installed Lenny in a chroot environment. Background daemons work fine for me, I've installed OpenSSH and I'm using ConnectBot connecting to 127.0.0.1 to get a terminal, so I don't have to chroot every time. I even have X with tightvnc server + android-vnc-viewer. Running the desktop Firefox on my phone is fun Although not very useful. I'm still thinking about what awesome things we could do with this that we couldn't otherwise.
Anyway, great howto.
Do you have any details on the Thalamus kernel? What phone is it for? Overclocked, audio hack, etc? Or is it just a vanilla kernel with the extra module?
What applications can we dream up?
The first thing that springs to mind is could this be used to create a low power server running bittorrent and the like?
Would a cheap device like the Vodafone 845 be under-powered for this?
Can you connect to a usb hub to allow multiple devices to be connected to it? I'm thinking usb network adapters, external storage, etc.
How much additional effort on top of this guide would be needed?
Just curious...
will not... - -!
Well I learned one thing. Don't make Shell scripts when you are tired. I started a shell loop on phone bootup with my /system/bin/sh fix (Which had been changed). When using the merged environment, you need (for now) to enter /bin/login when you open a new shell and login as user with the password you created in Part 3. This will make Debian take over the user management which among other things will make sure that the right variables etc. exists. I have tried to locate where android controls new shell sessions, but I cant seam to find it.
When you make Debian take over, you can use your Linux shell as any other. .bashrc, .profile, /etc/bash.bashrc, /etc/profile files, change default shell (bash, sh, ash) in /etc/passwd and so on.
#9 Well the kernel is the same that is found in the Oxygen 2.0.1, so it's an gingerbread rom (2.3.3). If it works only in Oxygen, I don't know but I don't think so.
#10 He he, Could not say. For now I'm just trying to make it work as I want it to work. After that I might start playing around with different things.
The "login" command is no longer needed. I finally found a way to successfully control user variables and management, making Android and Debian work together as one when merging the two.
This is amazing. Totally going to do this later tonight when I get home.
If you merge using AUFS instead of making a chroot, you should perhaps use the system user (Id: 1000, Group: 1000) as the regular user.
There are only two static users in Android, 0 and 1000.
Android just isn't made to work as an multi-user system. This is how the Java UI is made, and we really need to Linux part to be compatible with that part of the OS. Instead of multi-users, android uses it's apps as users. Each app works as one user with different id. So the 10048 I used as regular user is just the ID of mine "Better Terminal". Switching to another terminal app changed the EUID.
Use the root and only root to work with in the shell. And then delete Debians "su" command and stick with the one from android. Debians need all users that execute "su" to be written to the /etc/passwd.
All GNU tool and library, that's Great. thanks a lot.
I have added an example of how to apply Android rules to shell users, daemons etc. Some daemons will need this in order to function.
I have added this in Thread 2 below the hostname example.
I also changed the main Thread. Found a fix for the rest of the permission problems, including the Android "su" command issue.
I have tested this Android/Debian merge using several methods (ADB, SSH, different local terminals) and it worked on most. I had one problem with one local terminal app that did not execute /etc/profile and some Debian users in /etc/passwd that didn't either.
To fix this I changed /system/bin/sh from using "/system/xbin/sh --login [email protected]" to instead use "/system/xbin/sh --rcfile /system/etc/profile [email protected]". I then moved the Debians /bin/bash to /usr/bin/bash and made a similar script file in /bin/bash > "/usr/bin/bash --rcfile /etc/profile [email protected]". You can make the same for /bin/sh if you don't like using bash for your /etc/passwd users.
Remember to change the bash bind mount in the mkdebian script from /bin/bash to /usr/bin/bash
Use whatever method works on your phone.
This looks like a ton of fun, and could be very useful. I'd like to try this on my NookColor (N2Acard, CM7.1), probably using The Guardian Project's lilDebi image as a base. They go the chroot route with their installer, and I'm going to have to do some hacking on their scripts to make them work with the NookColor. I figure if I'm going to have to hack on it, I might as well put my efforts toward a more ideal solution.
Question: It doesn't look like the CM7.1 kernel supports aufs. That is,
Code:
cat /proc/filesystems
doesn't return aufs as one of the supported filesystems.
Aside from a lack of elegance, is there any reason we can't apply your /sbin workaround to "merging" the whole filesystem? [I recognize there's a certain amount of ignorance behind the question; I figure there's only one way to cure that: Ask.]
OR, how difficult might it be to take a complete CM7.1 kernel and add aufs support to it?
'preciate any help I can get!
mailman1175 said:
This looks like a ton of fun, and could be very useful. I'd like to try this on my NookColor (N2Acard, CM7.1), probably using The Guardian Project's lilDebi image as a base. They go the chroot route with their installer, and I'm going to have to do some hacking on their scripts to make them work with the NookColor. I figure if I'm going to have to hack on it, I might as well put my efforts toward a more ideal solution.
Question: It doesn't look like the CM7.1 kernel supports aufs. That is,
Code:
cat /proc/filesystems
doesn't return aufs as one of the supported filesystems.
Aside from a lack of elegance, is there any reason we can't apply your /sbin workaround to "merging" the whole filesystem? [I recognize there's a certain amount of ignorance behind the question; I figure there's only one way to cure that: Ask.]
OR, how difficult might it be to take a complete CM7.1 kernel and add aufs support to it?
'preciate any help I can get!
Click to expand...
Click to collapse
here's where you get aufs patches.
you'll have to build the kernel yourself to make it work.
to the OP:
using the aufs mount method instead of a chroot...
I have a small problem, I don't know if it shows up with your .img filesystem method, but with an sd-ext partition used intead of the .img file, apt-get fouls massively when trying to update/upgrade libc6.
it complains about the libc6*.so existing in two places at once, and requests the existing one be removed. If it's removed, then nothing in the Linux install works, because just about everything is compiled against libc. I can use busybox to manipulate files with the libc6 removed or hidden away, but can't seem to get past the error since dpkg and apt don't work without some version of libc installed.
Any hints/suggestions? I like your scripts a lot better than the chroot ones I cobbled together from everyone else's work last year for similar purposes before I got aufs working in a kernel.

[SCRIPT] Pause command in Bash (Shell scripts)

For those of you who write scripts in bash, I have come up with a simple quick solution to adding the "pause" command easily.
This is meant for linux users to use to make writing scripts easier
In order to do this, follow these simple steps:
1) Open Gedit
2) add the following code:
Code:
#!/bin/bash
read -n1 -r -p "Press any key to continue..." key
exit 0
This starts the script, waits for a key to be pressed, and then ends, and the script accessing it continues.
3) Now we need to save it, so save it to your desktop as
Code:
pause //WITH NO EXTENSION
4) now we need to copy it to /bin. To do this, open your teminal window with CTRL+ALT+T, then type:
Code:
cd Desktop
sudo mv pause /bin
5) Now, make the file executable:
Code:
sudo chmod +x pause
And that's it! Now, whenever you are writing scripts, just write "pause" without quotes and it will work
**NOTE**
If you are writing this for release, you cannot simply write pause in your scripts or they will fail on the user's machine (if they don't have the pause script installed). In release scripts, just write the line:
Code:
read -n1 -r -p "Press any key to continue..." key
Thanks for looking!

[UBUNTU][DEBIAN]Common Commands used in Linux

Common Commands used in Linux.
Since, Android is based on Linux, there is much possibility that there is a need to use a Linux based OS. For such use, UBUNTU
is favoured, for its easy and more user friendly.
Today, I am going to Post a few commands that are very useful to the newbies to development
I myself am new, and have faced many problems with this, so I am posting a this thread, to help all the noobs/newbies find what they need in a single place
Okay so, lets start with some basic commands, which can be classified as general commands, and each Linux user MUST KNOW ALL OF THEM !!
Code:
sudo
It simply means "Superuser do". It requires password.
Code:
sudo apt-get install APPLICATION_name
This installs the application finding it on the internet, and gives you the suitable output(If the app exists or not).
Code:
sudo apt-get remove APPLICATION_name
It Removes the application
Code:
sudo apt-get update
it updates the repositories
Code:
sudo apt-get upgrade
upgrades your installed application with their latest versions from Ubuntu repositories
Code:
killall APPLICATION_NAME
kills (terminates) an application
Code:
ps -e
displays currently running processes
Code:
kill APPLICATION_PID
kills an application; where APPLICATION_PID.
NOTE: YOU CAN FIND "PID" USING EARLIER CODE.
Code:
wget http://path_to_file.com
downloads a file from the web to current directory
Code:
cd /PATH/TO/DIR
changes current directory to DIR. Use cd to change the current directory into any dir
Code:
cd ..
Like ms-dos, goes up one directory
Code:
dir
OR
Code:
ls
lists directory content
Code:
man COMMAND
Displays manual for command.
eg: man sudo
Code:
cp ORIGINALFILE NEWFILE
Copy a file
Code:
mv SOURCE DESTINATION
Moves a file
NOTE: YOU CAN ALSO RENAME A FILE WITH THIS.
EG: mv old_filename new_filename
Code:
mkdir FOLDERNAME
Make a directory/folder
Miscellaneous: Level 2
Code:
du -sh folder name
This calculates the size of the folder
Code:
ps -aux
This shows all the running processes
Code:
chown -R User:User dir
Change owner of files and directories
Code:
chmod 777 yourScript
This makes a shell script ".sh" extension
Code:
netstat -anltp | grep "LISTEN"
See all open ports on your machine
Code:
sudo apt-get install ufw
sudo ufw allow 80/tcp
sudo ufw allow 22/tcp
sudo ufw allow 443/tcp
sudo ufw allow 21/tcp
sudo ufw enable
Ubuntu provides a uncomplicated firewall (ufw). To install it and only allow SSH, FTP, and webtraffic use the following command.
Network Commands
Code:
ifconfig
Shows the network connections
WILL UPDATE REGULARLY AS MUCH I COULD.
Code:
passwd
Run after installing Linux when you see "[email protected]:~$" to set your root pass word
Code:
adduser
Replace and run to add a new user
Code:
adduser sudo
Replace and run to add that user to sudo
Code:
sudo apt-get purge
Replace and run to purge your system of that package
Code:
apt-cache search
Replace and run to search for new packages to install
Note: "wild cards" eg "*" are acceptable
Code:
find -type f -iname 'some-compressed-file*' -print0 | xargs -0 sudo tar -vxpzf
Replace with at least the "root" directory you want to search through and Replace " some-compressed-file " (leave the single quotes ' ' and the wild card *) and run to find every file under the given directory that has that name and the pipe " | " it out to tar so that'll extract to your current directory
Note: "find" does the finding, the "-type -f" tells find to only look for files, the "-iname" tells find to search parts of file names, the ' ' around "some-compressed-file" keeps the * from doing bad things, the "print0" tells find to "scrub" for spaces and such before outputting a result, the " | " pipes the results of find to xargs, the "-0" is because of "print0" in the find side of the pipe, and "sudo tar - vxpzf" is where tar extracts the findings of find.
Code:
find $HOME -type f -iname '*zip' -print0 | xargs -0 ls
Run to find and list every zip file under the home folder
Say you want to make a file to contain some notes wile in the command line
Code:
sudo cat > $HOME/someNotes.txt <<EOF
# place a command here
echo "hello world, I update aptget"
sudo apt-get update -q
EOF
Try editing the part after $HOME; type it in or write a file that contains the combo of " cat > $HOME/someNotes.txt <<EOF " some text or commands " EOF " and you'll find making custom scripts of varying complexity to be easy.
.......
Hope some of these are also found to be useful for others.
Thanks for starting this here thread.
Hit the link in my signature for more help with Linux for new and seasoned users
Edit 08082013- added another useful tip and reformatted commands to better fit the OP's formatting.
Sent from either my SPH-D700 or myTouch3Gs
Debian Kit/QEMU Linux Install guide for all android devices that I'm writing:
http://forum.xda-developers.com/showthread.php?t=2240397
Now have working Installers for ARM Java 7 JDK + Maptools + jMonkey
Yo ! Nice Share
To delete contents of a large text file ..
Code:
cat /dev/null > NameOfTheFile
Useful variations of ls command :
Show dir content in a list
Code:
ls -l
Show dir content in a list sorted by modification time (newer first)
Code:
ls -lt
Show dir content in a list sorted by modification time (older first)
Code:
ls -lrt
Show subdirectories recursively
Code:
ls -R
If you want to show files starting with . (hidden file), you can add -a option.
More options with command :
Code:
man ls
Useful variations of grep command :
grep is used to print lines matching a pattern.
Find the entry for current user in file /etc/passwd :
Code:
cat /etc/passwd | grep $USER
Find all the entry except current user entry in file /etc/passwd :
Code:
cat /etc/passwd | grep -v $USER
Find all the numbers in file /etc/passwd :
Code:
cat /etc/passwd|grep '[0-9]*'
Add color to grep command :
Code:
cat /etc/passwd | grep --color $USER
(You can add
Code:
alias grep='grep --color=auto'
in ~/.bashrc to always have colored grep)
Useful variations of tar command :
Create archive_name.tar from dirname :
Code:
tar cvf archive_name.tar dirname/
Create archive_name.tar.gz (compressed) from dirname :
Code:
tar zcvf archive_name.tar.gz dirname/
Extract archive_name.tar.gz :
Code:
tar zxvf archive_name.tar.gz
Useful variations of mkdir command :
Create directory and subdirectories if not existing :
Code:
mkdir -p /tmp/a/b/c
(mkdir /tmp/a/b/c will fail if /tmp/a and /tmp/a/b don't exist)
Useful tip :
Use bash variable "!$" to get the value of the last argument of the last command interpreted.
For example :
Code:
mkdir /tmp/test_a
cd !$ (equivalent cd /tmp/test_a)
or,
Code:
mv /tmp/a /tmp/b
ls !$ (equivalent ls /tmp/b)

[Q] how to launch an app from the terminal, opening specified file?

From the terminal, I would like to learn how to open a file in an android app.
As an example, how would I open /storage/emulated/0/Download/test.txt in Ted lightweight text editor?
When I try this:
Code:
am start -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d /storage/emulated/0/Download/test.txt
I get an error that includes "Permission Denial: startActivity asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL"
I'm not sure exactly what that's about, so I try to work around it with this:
Code:
am start --user 0 -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d /storage/emulated/0/Download/test.txt
Now Ted editor starts, but it opens a new file and not the specified file. I tried multiple times; one time there was a message at the top saying something to the effect that the specified file could not be opened. I've also tried different test files to exclude the possibility that test.txt is corrupt.
I'm stuck. Please help!
P.S. Ted's AndroidManifest.xml is available on github. I tried posting the link but, being new to the forum, I was not permitted to do so.
------------------
OS: CM11
Device: Moto G
Relevant apps: Terminal Emulator (jackpal.androidterm 1.0.65), Ted (fr.xgouchet.texteditor 1.8.1)
1) After countless hours of trial and error, I figured it out. Entering this command in the terminal opens the file for editing in Ted:
Code:
su -c "am start -a android.intent.action.EDIT -n fr.xgouchet.texteditor/.TedActivity -d file:/storage/emulated/0/Download/test.txt"
If you are reading this thread and like to write your own shell scripts, these two commands might also come handy if your script uses both CLI and GUI utilities:
2) To see the name of the app currently in the foreground:
Code:
su -c "dumpsys window windows" | grep mCurrentFocus | cut -d'/' -f1 | cut -d' ' -f5
3) To put the terminal in the foreground again:
Code:
su -c "am start -n jackpal.androidterm/.Term"
If you know how to do 1) (see my previous post) without root privileges, please post it here.
It doesn't make sense to me that root privileges would be required to open a user-owned file in a text editor. Android is linux, after all, so I'm hoping that anything a normal user can do via the GUI can also be done from the command line.

[GUIDE][TUT] Learn basic scripting, how to execute scripts, mod building

Hello guys, I want to share my expirience with users who wants to learn basic scripting stuff, busybox commands, how to use them, how to execute them, how to make .sh files.
Ok, let's start!!! ​
First we must to learn what is busybox. BusyBox is software that provides several stripped-down Unix tools in a single executable file. It runs in a variety of POSIX environments such as Linux, Android.
Busybox allows you or programs to perform actions on your phone using Linux (copied from Unix) commands. Android is basically a specialized Linux OS with a Java compatible (Dalvik) machine for running programs. The Android kernel is a modified version of the Linux kernel (that is why the Android kernel must always be open source). Busybox gives functionality to your phone that it does not have without it. Many programs, especially root programs such as Titanium Backup, require busybox to perform the functions of the program. Without busybox installed your phone is much more limited in what it can do.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Here is some info about busybox, you can track here release dates, you can download sources...
http://spblinux.de/2.0/doc/commands.html
Also here is busybox installer for our "linux devices" heheh ^~^ by stericson. You have two versions of it as you see paid and free.
Chose paid if you want to donate him for awesome job.
Free:
https://play.google.com/store/apps/details?id=stericson.busybox
Paid(PRO):
https://play.google.com/store/apps/details?id=stericson.busybox.donate
After that you need Terminal app, you can download it from playstore too.
Link: Download it from here
This app emulates Linux terminal, with it you can access to android shell.
Lets's start with learning basic terminal stuff
The most of shell commands doesn't need root access, but some of them are need it.
To give root access to the terminal app, you need to type next.
Code:
su [I](press enter)[/I]
After pressing enter, another window will popup to grant root access. Tap on GRANT
***When you typing something into the terminal window, take care because EVERYTHING IS CASE SENSITIVE.***
We all know there are three permissions per group on a file read,write,execute or rwx.
To set permissions as rw-r--r-- we use chmod 644 or 0644 but most don't know why ? Here's why
Read or r has a positional weight of 4, Write or w has 2 and Execute or x has 1. Add them up for each group and you'll get the chmod number to use. For above example, the numbers will be (4+2)(4)(4) i.e. 644 or if you want four digits, use 0644 and that's pretty much it. It comes in very handy if you're learning shell scripting because Linux revolves around permissions. (Thanks to @MSF Jarvis)
Let's go trough basic shell commands. ​
If you interested about all commands, you can check them HERE.
cat [file destination] - use this command to print everything from a file to the terminal window
Example:
Open terminal window, and type next:
Code:
busybox cat /proc/meminfo [I](press enter)[/I]
You will get output after pressing enter
Now, you can see here, if you open any file manager and go to destination which was given for example "/proc/meminfo"
You will see next file and stuff inside it
Heheh, is it same?? ^~^ for sure that it is, you can use it for any file on your device which have text in it.
Let's go to the next basic command ^~^
echo - this command can be used for printing arguments to stdout. Also you can use it for adding text in already existing file which we need here, because we are learning scripting stuff, right? ^~^
Example:
Open terminal window, and type next:
Code:
busybox echo "Scripting is awesome" > /sdcard/test [I](press enter)[/I]
Ok, let's explain this.
First you added a command echo to add something in existing file, then between "..." we need to put arguments, for our case this is "Scripting is awesome" next we see symbol " > " which will forward arguments to next added direction, in our case this is "/sdcard/test".
First we need to have a existing file (IMPORTANT)
After we agreed with that we have a file
Open terminal as I already explained and after pressing enter you will get output on the terminal window.
That is a file from our /sdcard/
Don't delete this file, we will use it later with " sh" command.
Let's go to the next basic command
clear - Use this comand to clear whole terminal window.
Example:
You have a terminal window which have a lot of stuff on it, for example stuff from previous lines, text, etc.
You can simply make it blank with just one command
Code:
busybox clear [I](then press enter)[/I]
And voila, terminal window is blank
touch [file destination] - Use this command to create a blank file on any destination on your android device.
Example:
Open terminal window, and type next:
Code:
busybox touch /sdcard/scripting_007 [I](press enter)[/I]
This will create file called "scripting_007" on "/sdcard/" in this case, you can put any.
As you can see file "scripting_007" exist on /sdcard/
mkdir [file destination] - Use this command to create one empty folder on any destination on your android device.
Example:
Open terminal window, and type next:
Code:
busybox mkdir /sdcard/development [I](press enter)[/I]
This will create folder called "development" on "/sdcard/" in this case, you can put any.
sh [path of a file] - Use this command to execute basic script
Example:
Open terminal window, and type next:
Code:
sh /sdcard/test [I](press enter)[/I]
This will execute file which you make before with "echo" command
sleep [time in secs] - Use this command to make an offset between executing lines inside script.
Example:
Open terminal window, and type next:
Code:
busybox echo "Scripting is"
busybox sleep 10
busybox echo "awesome"
This is a combination of two commands as you can see, echo and sleep.
After launching this simple script in terminal window you will get first "Scripting is" and after 10 secs you will get awesome.
rm [ -f (file) -rf (folder)] - this is a command for removing files (-f) and folders (-rf)
Example:
Create a file called "android" on sdcard, then open terminal window, and type next:
Code:
busybox rm -f /sdcard/android
This simple code will remove a file called android from sdcard.
Now do the same thing with a folder, create one with the name "android" and run terminal emulator
Code:
busybox rm -rf /sdcard/android
This will remove folder called android from your sdcard.
Now, let's go with some advanced stuff​
You need any text editor, I suggesting this one
Link: Download from here
Now, open the app and write a new file and give it a name "test1"
Inside a file write next text:
Code:
busybox echo "Android"
busybox sleep 2
busybox echo "is"
busybox sleep 2
busybox echo "Awesome"
Save the file and copy it to some location, i suggest /sdcard/.
Open up terminal emulator and type next
Code:
sh /sdcard/test1 [I](press enter)[/I]
This thing will execute your script with the name test1 from /sdcard/.
Output will be "Android", then after two seconds will appear "is" and then after two more seconds "Awesome" will appear. THATS IT!!! You learned how to make a file (script) and how to execute it with terminal emulator.
Now do the same thing make a file with the name "test2" and make another file with a name "print"
First open "test1" and write next:
Code:
busybox echo "After 5 seconds"
busybox sleep 1
busybox echo "You will get a suprice"
busybox sleep 2
busybox clear
busybox echo "1"
busybox sleep 1
busybox clear
busubox echo "2"
busybox sleep 1
busybox clear
busybox echo "3"
busybox sleep 1
busybox clear
busybox echo "4"
busybox sleep 1
busybox clear
busybox echo "5"
busybox sleep 1
busybox clear
sh /sdcard/print
I think that you already know whats happened here
You have print, then you have sleep to make offset, and after that you have clear command to make window blank
Now open file with the name "print"
Inside it write next:
Code:
busybox echo "Voila, suprise"
Save this file, and open terminal emulator, and write next:
Code:
sh /sdcard/test2
And magic happens
In this example you learned how to execute second file with first, I think that it's not difficult for you
In this example we will play a bit with colors outputs
Codes for colors are below
Code:
busybox echo -e " 1. Black \e[0;100m \e[00;37;40m"
busybox echo -e " 2. Red \e[0;101m \e[00;37;40m"
busybox echo -e " 3. Green \e[0;102m \e[00;37;40m"
busybox echo -e " 4. Yellow \e[0;103m \e[00;37;40m"
busybox echo -e " 5. Blue \e[0;104m \e[00;37;40m"
busybox echo -e " 6. Purple \e[0;105m \e[00;37;40m"
busybox echo -e " 7. Cyan \e[0;106m \e[00;37;40m"
busybox echo -e " 8. White \e[0;107m \e[00;37;40m"
Try to copy this into terminal window and see what will happened or try whing which you learned before with the executing files. Copy whole code to a file and execute it with "sh" command. USE YOUR KNOWLEDGE.
Here you can see all things based on bash script coloring
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
or
http://misc.flogisoft.com/bash/tip_colors_and_formatting
Here you can see all codes and it's nice descirbed.
Now, let's start
Make a file with the name "test3" open it and write or copy next code inside:
Code:
busybox echo " .... "
busybox echo " / / "
busybox echo " / / "
busybox echo " / / "
busybox echo " / /_._._. "
busybox echo -e " /_._._._._./ \e[00;41m SPEED MOD \e[00;37;40m v3.0"
busybox echo "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"
busybox echo -e "\e[01;32m Feel smoothness \e[00;37m"
busybox echo " "
As you can see this part was taken from mine L Speed performance/battery mod
Save the file, open terminal and type inside
Code:
sh /sdcard/test3
And you will get the same screen like in first L Speed menu.
Let's play a bit with this
You see the code
Code:
\e[00;41m SPEED MOD \e[00;37;40m v3.0
Just change one number instead of 41 write 42 and you will get green color, then give a try to other nubers. Every number is another color for example:
Code:
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
Cyan='\e[0;36m' # Cyan
White='\e[0;37m' # White
# Bold
BBlack='\e[1;30m' # Black
BRed='\e[1;31m' # Red
BGreen='\e[1;32m' # Green
BYellow='\e[1;33m' # Yellow
BBlue='\e[1;34m' # Blue
BPurple='\e[1;35m' # Purple
BCyan='\e[1;36m' # Cyan
BWhite='\e[1;37m' # White
# Underline
UBlack='\e[4;30m' # Black
URed='\e[4;31m' # Red
UGreen='\e[4;32m' # Green
UYellow='\e[4;33m' # Yellow
UBlue='\e[4;34m' # Blue
UPurple='\e[4;35m' # Purple
UCyan='\e[4;36m' # Cyan
UWhite='\e[4;37m' # White
# Background
On_Black='\e[40m' # Black
On_Red='\e[41m' # Red
On_Green='\e[42m' # Green
On_Yellow='\e[43m' # Yellow
On_Blue='\e[44m' # Blue
On_Purple='\e[45m' # Purple
On_Cyan='\e[46m' # Cyan
On_White='\e[47m' # White
# High Intensity
IBlack='\e[0;90m' # Black
IRed='\e[0;91m' # Red
IGreen='\e[0;92m' # Green
IYellow='\e[0;93m' # Yellow
IBlue='\e[0;94m' # Blue
IPurple='\e[0;95m' # Purple
ICyan='\e[0;96m' # Cyan
IWhite='\e[0;97m' # White
# Bold High Intensity
BIBlack='\e[1;90m' # Black
BIRed='\e[1;91m' # Red
BIGreen='\e[1;92m' # Green
BIYellow='\e[1;93m' # Yellow
BIBlue='\e[1;94m' # Blue
BIPurple='\e[1;95m' # Purple
BICyan='\e[1;96m' # Cyan
BIWhite='\e[1;97m' # White
# High Intensity backgrounds
On_IBlack='\e[0;100m' # Black
On_IRed='\e[0;101m' # Red
On_IGreen='\e[0;102m' # Green
On_IYellow='\e[0;103m' # Yellow
On_IBlue='\e[0;104m' # Blue
On_IPurple='\e[0;105m' # Purple
On_ICyan='\e[0;106m' # Cyan
On_IWhite='\e[0;107m' # White
On the next phase we will learn how to use variables, in bash scripts this is simple, just add a simple "tag" then what you want to connext wit this tag.
Here is an example:
Code:
file=/sdcard/test4
busybox touch $file
Ok, here is one simple thing, this is same like in touch command explaining, but there is a little difference. We added variable or you can call it shortcut if it's easier for you.
To call variable somewhere in a file you need to use a dollar sign "$" then name of your variable. Let's to next examole with variables.
As we now have file called test4 on our SD, we can go trough.
Code:
file=/sdcard/test4
busybox echo "hey file" > $file
As you can see everything is repeating from previous examples just with variable. This is much easier, and you will save a bit of time.
Now we can see what is inside file Open terminal emulator and type next
Code:
busybox cat /sdcard/test4
And you will get output "hey file"
Simple isn't it?
In this part we will learn how to use if, elif, else It's pretty simple, let's start.
Pattern for this will be:
Code:
if [what]; then
do something
fi
if [what]; then
do something
elif [what if not "if"]
do something
else
what to do else
fi
Ok what we have here?
The first part of code show us simple code which mean if for example something is true then do something and then close if with fi.
Second part of code is a bit "complicated". If somethig is true then do something, then we have elif, in case that if is false then it will do what is under elif. In case that both of them are false, everything what is under else will be executed.
Ok here is an example:
Code:
if [ -e /sdcard/test5 ]; then
busybox echo "hello" > /sdcard/test5
else
busybox touch /sdcard/test5
busybox echo "hello" > /sdcard/test5
fi
Ok, if file test 5 exists add hello to it, else(if not) then create a file and add text hello in it.
Another example with a bit of complications heheh
Code:
if [ -e /sdcard/test5 ]; then
busybox echo "file 5 exists"
elif [ -e /sdcard/test6 ]; then
busybox echo "file 6 exists"
else
busybox echo "files are not exist"
fi
Ok, here is explanation, if test5 exist then print "file 5 exists" going to the next line, if file test6 exist pri t "file 6 exists" and else if both of them doesn't exist print "files are not exist".
Donation:
http://forum.xda-developers.com/donatetome.php?u=5514152
Everyone who knows a bit of the performance/battery mods wants sometime to learn what is inside and how it's working
Here is a guide by @Paget96 (me) ^~^
As we know for every mod we need root, this is needed because we must to access to android shell.
init.d support, that is a folder which launch files from it on every boot. Init.d is included on some ROM's by default, but on some you need yo enable it by default(I will explain later how).
Next thing what you need is for sure busybox. And a little bit of free space on the /system partition.
Everyone knows how to root, I don't need to explain how to do that right?
User who doesn't have init.d will make it with next steps.
1. Flash superSU by @Chainfire (IMPORTANT)
2. In /system/etc/ make a file with the name "install-recovery-2.sh and push next code in it
Code:
#!/system/bin/sh
/system/bin/sysinit
3. Inside system/bin make a file with the name " sysinit" and push next code in it
Code:
#!/system/bin/sh
busybox sleep 30
export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
run-parts /system/etc/init.d
4. Open /system/etc and make folder with the name "init.d"
Now you need to set permissions for all of this files.
Open terminal emulator and do next:
Code:
su
This will give root access
Code:
busybox chmod 755 /system/etc/install-recovery-2.sh
busybox chown 0.2000 /system/etc/install-recovery-2.sh
With this you will set "executable" permissions.
And we need permission for sysinit
Code:
busybox chmod 755 /system/bin/sysinit
busybox chown 0.2000 /system/bin/sysinit
And that's it
To install busybox use app "busybox installer" by stericson from playstore.
***IMPORTANT*** Don't change too much things, because you will get crap in your hands
Tools which are needed is
Text editor, I suggest Turbo Editor
Terminal emulator
ES file explorer
Ok, let's start
We will start with virtual memory tweaking...
Open file manager and create one folder where you will build a mod.
Inside it we will create one file for beginning and call it "00sysmod"
Code:
#!/system/bin/sh
busybox chmod 644 /proc/sys/vm/*
busybox sysctl -e -w vm.dirty_background_ratio=3
busybox sysctl -e -w vm.dirty_ratio=15
busybox sysctl -e -w vm.swappiness=40
busybox sysctl -e -w vm.dirty_expire_centisecs=500
busybox sysctl -e -w vm.dirty_writeback_centisecs=3000
busybox sysctl -e -w vm.min_free_kbytes=4096
busybox sysctl -e -w vm.overcommit_memory=1
busybox sysctl -e -w vm.overcommit_ratio=75
busybox sysctl -e -w vm.page-cluster=0
busybox sysctl -e -w vm.panic_on_oom=0
Copy this inside file, save it and copy to init.d folder
After that set permissions to 755
Code:
busybox chmod 755 /system/etc/init.d/00sysmod
Let's explain every line:
First line is a header of every script.
Next line will change permissions (in this case read, write, read, read) of a files which are inside /proc/sys/vm/*. * means every file.
Everything below it are vm parameters.
vm.dirty_background_ratio
Contains, as a percentage of total available memory that contains free pages
and reclaimable pages, the number of pages at which the background kernel
flusher threads will start writing out dirty data.
The total avaiable memory is not equal to total system memory.
dirty_ratio
Contains, as a percentage of total available memory that contains free pages
and reclaimable pages, the number of pages at which a process which is
generating disk writes will itself start writing out dirty data.
The total avaiable memory is not equal to total system memory.
swappiness
This control is used to define how aggressive the kernel will swap
memory pages. Higher values will increase agressiveness, lower values
decrease the amount of swap. A value of 0 instructs the kernel not to
initiate swap until the amount of free and file-backed pages is less
than the high water mark in a zone.
The default value is 60.
dirty_expire_centisecs
This tunable is used to define when dirty data is old enough to be eligible
for writeout by the kernel flusher threads. It is expressed in 100'ths
of a second. Data which has been dirty in-memory for longer than this
interval will be written out next time a flusher thread wakes up.
dirty_writeback_centisecs
The kernel flusher threads will periodically wake up and write `old' data
out to disk. This tunable expresses the interval between those wakeups, in
100'ths of a second.
Setting this to zero disables periodic writeback altogether.
min_free_kbytes
This is used to force the Linux VM to keep a minimum number
of kilobytes free. The VM uses this number to compute a
watermark[WMARK_MIN] value for each lowmem zone in the system.
Each lowmem zone gets a number of reserved free pages based
proportionally on its size.
Some minimal amount of memory is needed to satisfy PF_MEMALLOC
allocations; if you set this to lower than 1024KB, your system will
become subtly broken, and prone to deadlock under high loads.
Setting this too high will OOM your machine instantly.
overcommit_memory
This value contains a flag that enables memory overcommitment.
When this flag is 0, the kernel attempts to estimate the amount
of free memory left when userspace requests more memory.
When this flag is 1, the kernel pretends there is always enough
memory until it actually runs out.
When this flag is 2, the kernel uses a "never overcommit"
policy that attempts to prevent any overcommit of memory.
Note that user_reserve_kbytes affects this policy.
DON'T CHANGE THIS VALUE, YOU WILL GET CRAP IN A HANDS, THIS IS JUST FOR INFO
overcommit_ratio
With this parameter you will set how much space will allocations use in physical RAM. (Percentage)
page-cluster
page-cluster controls the number of pages up to which consecutive pages
are read in from swap in a single attempt. This is the swap counterpart
to page cache readahead.
The mentioned consecutivity is not in terms of virtual/physical addresses,
but consecutive on swap space - that means they were swapped out together.
It is a logarithmic value - setting it to zero means "1 page", setting
it to 1 means "2 pages", setting it to 2 means "4 pages", etc.
Zero disables swap readahead completely.
panic_on_oom
This enables or disables panic on out-of-memory feature.
If this is set to 0, the kernel will kill some rogue process,
called oom_killer. Usually, oom_killer can kill rogue processes and
system will survive.
If this is set to 1, the kernel panics when out-of-memory happens.
If this is set to 2, the kernel panics compulsorily even on the
above-mentioned. Even oom happens under memory cgroup, the whole
system panics
In this part we will tweak kernel parameters
Open file manager as before and create a file with the name " 00kerneltweak"
Here we will use if statement, just for a little practise ^~^
Code:
if [ -e /proc/sys/kernel/shmmni ]; then
busybox echo "2048" > /proc/sys/kernel/shmmni
fi
if [ -e /proc/sys/kernel/shmall ]; then
busybox echo "1572864" > /proc/sys/kernel/shmall
fi
if [ -e /proc/sys/kernel/shmmax ]; then
busybox echo "33554432" > /proc/sys/kernel/shmmax
fi
if [ -e /proc/sys/kernel/msgmni ]; then
busybox echo "512" > /proc/sys/kernel/msgmni
fi
if [ -e /proc/sys/kernel/msgmnb ]; then
busybox echo "16384" > /proc/sys/kernel/msgmnb
fi
if [ -e /proc/sys/kernel/msgmax ]; then
busybox echo "8192" > /proc/sys/kernel/msgmax
fi
Copy this inside file, save it and copy to init.d folder
After that set permissions to 755
Code:
busybox chmod 755 /system/etc/init.d/00kerneltweak
Same as we learned before if file exist then do next
Let's explain this parameters:
shmall
The total amount of shared memory (in pages) which can be allocated on the system
shmmax
The maximum size of a shared memory segment (in pages)
shmmni
The maximum number of shared memory segments available on the system
msgmni
The number of IPC message queue resources allowed (by default, 16).
msgmnb
Defines the maximum size in bytes of a single message queue. The default value is 65536 bytes.
msgmax
The maxim...
Remove Google Play Services data
Code:
#!/system/bin/sh
mount -o remount,rw /data
busybox mount -o remount,rw /data
GSM=/data/data/com.google.android.gms
for i in $GSM
do
busybox rm -rf $i/*
done
make a file, and add this inside, like before
copy to /system/etc/init.d
set permissions to 755
Clear browser data
Code:
#!/system/bin/sh
mount -o remount,rw /data
busybox mount -o remount,rw /data
browser=/data/data/com.android.NAME_OF_THE_BROWSER
for i in $browser
do
busybox rm -rf $i/*
done
make a file, and add this inside, like before
copy to /system/etc/init.d
set permissions to 755
first write a name of the browser, some devices have chrome as a default, then name will be
com.android.chrome
I'm sure that its
com.android.browser for default one
Check that inside /data/data, then just change inside the script
Or you can use this package
Code:
#!/system/bin/sh
while true; do
mount -o remount,rw /data
busybox mount -o remount,rw /data
busybox echo -n "Enter a name of the browser: "
busybox read -r name
brw=/data/data/com.android.$name
if [ -d $brw ]; then
for i in $brw
do
busybox rm -rf $i/*
done
busybox echo "Clearing done"
busybox sleep 2
else
busybox echo "Browser doesn't exist, please type another one..."
busybox sleep 3
fi
done
Well, this for this file guide is different,
Call the file "ccleaner" copy it to /system/bin
Set permissions to 755 like before
Open terminal emulator
Code:
su
ccleaner
Thanks Man
Thanks @Paget96 for your Support Man It will help Many user to Learn From You :fingers-crossed::good:
And Am the First to Comment on your Forum
cheers:laugh:
axays said:
Thanks @Paget96 for your Support Man It will help Many user to Learn From You :fingers-crossed::good:
And Am the First to Comment on your Form [emoji14]
Click to expand...
Click to collapse
I hope so
This thread needs too much stuff here, I cannot finish it in one day
Sent from my Nexus 5 using Tapatalk
Wow Good Job and Good Luck @Paget96 Its willbe Awesome
Paget96 said:
I hope so
This thread needs too much stuff here, I cannot finish it in one day
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
I'm a fan of your L Speed Mod, and this tutorial clears up many things. Subscribing now for updates when you add more stuff here.
Sent from my HTC Desire 616 dual sim using Tapatalk
Evolutionzz said:
Wow Good Job and Good Luck @Paget96 Its willbe Awesome
Click to expand...
Click to collapse
Thank you mate ^~^
MSF Jarvis said:
I'm a fan of your L Speed Mod, and this tutorial clears up many things. Subscribing now for updates when you add more stuff here.
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Guys, more stuff will come tomorrow
Sent from my Nexus 5 using Tapatalk
Paget96 said:
Thank you mate ^~^
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Just 20%!!!! I'm dying to see the rest....
Paget96 said:
Thank you mate ^~^
Heh fans everywhere ^~^ Yeah, but TUT is not finished this is maybe 20% of stuff which are need to be here
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Sent from my HTC Desire 616 dual sim using Tapatalk
MSF Jarvis said:
Just 20%!!!! I'm dying to see the rest....
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
Heheh, there will be whole stuff about scripting which I used for L Speed building
Sent from my Nexus 5 using Tapatalk
For now, I think that it's enough, if you have more request, type below
Also I want to see screenshots of your attempts
Sent from my Nexus 5 using Tapatalk
Hell yeah!! Awesome Guide my bro @Paget96 Fantastic! This what people wanted from a long time. Amazing.
Sent From dark_world through my Android One
dark_optimistic said:
Hell yeah!! Awesome Guide my bro @Paget96 Fantastic! This what people wanted from a long time. Amazing.
Sent From dark_world through my Android One
Click to expand...
Click to collapse
Thank you, this is why I created it
Sent from my Nexus 5 using Tapatalk
Paget96 said:
For now, I think that it's enough, if you have more request, type below
Also I want to see screenshots of your attempts
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
I borked my phone a bit (this is a non - rooted phone ) so I'll post screenshots later when I UN-bork it.
Sent from my HTC Desire 616 dual sim using Tapatalk
MSF Jarvis said:
I borked my phone a bit (this is a non - rooted phone ) so I'll post screenshots later when I UN-bork it.
Sent from my HTC Desire 616 dual sim using Tapatalk
Click to expand...
Click to collapse
What you mean with borked?? hehh
I'm waiting for your screenshots, just to see how users understood stuff ^~^
Sent from my Nexus 5 using Tapatalk
delete
Awesome work as usual :angel:
Black_Eyes said:
Awesome work as usual :angel:
Click to expand...
Click to collapse
Thank you
I just want to share mine experience with the users
And probably to teach someone
Sent from my Nexus 5 using Tapatalk
Paget96 said:
What you mean with borked?? hehh
I'm waiting for your screenshots, just to see how users understood stuff ^~^
Sent from my Nexus 5 using Tapatalk
Click to expand...
Click to collapse
Borked means I changed my recovery and flashed a GB ROM instead of using my friends custom built CM 11 build. My trusty Tahr system also broke down, but I am resilient so I'll manage and you WILL see the screenshots before 5PM IST.[emoji16] [emoji16] [emoji16] [emoji6] [emoji6] [emoji6] [emoji6]
Sent from my HTC Desire 616 dual sim using Tapatalk

Categories

Resources