[INFO] Edify scripts in CWM recovery - Atrix 4G Android Development

Hi, I haven't seen any good resources for how to edit edify scripts, so I thought I would create this thread so we can pool our knowledge on the subject.
Intro
Inside your typical CWM zip there is a folder called META-INF, inside that there is a folder called com and come CERT files, inside that com folder there is a google folder, inside that is an android folder containing an update-binary file and an updater-script. If you only see an update-script, that means you are back in the Android 1.5 era and need to move on.
The updater-script
The updater-script file is a text file, it is linux formatted with regard to end of line conventions. If you use Windows then you have to edit the file using a program that keeps line feeds the way they are and has options for doing the conversion from <CR><LF> to just <LF>.
Like lisp, the contents of the text file evaluate to one big expression, but it does have the ";" end of command convention to make things more familiar, it just means perform the action on the left. (ref. google source README) You can ignore that and just treat everything as a series of commands for all practical purposes. I mention it because you need not worry about having too large a procedural block or worry about having extra spaces or worry about ending on a line boundary. You could have your entire script on one giant line and it wouldn't matter.
There are around a dozen commands, it's not terribly difficult to learn.
The updater-binary
There are a lot of updater-binary files out there in the wild, each manufacturer basically compiles there own with every other OTA update. Success in flashing your CWM zip is determined by picking the right one that works with what you are trying to do. If your knowledge says mount needs 4 arguments and the binary only supports 3, then you need to change your script to use 3 and vice versa. If you are trying to flash a radio, the updater-binary might have been recompiled to allow for that specific functionality and you will get a status 6 error when trying to flash it unless you use that update-binary. You will see the write_raw_image() function not supporting "/dev/block/mmcblk0p8" but instead "logo.bin".
However, by and large, the generic functionality is the same across the board.
​Updater-script functions (In order of interest)​
ui_print(msg1, .. msgN); This is the means you have to display something on the screen in CWM, it takes a series of comma separated arguments, each comma needs to have a space after it, this applies to all commands.
Ex. ui_print("Your version is: ", file_getprop("/system/build.prop", "ro.build.id"));
show_progress(TOTALAMOUNT, TIMEINSEC); This command and the following command control what you see in the progress bar at the bottom. It is not necessary to use it, it's just another way to display information.TIMEINSEC refers to how long it will take for the progress bar to move to the AMOUNT specified. You would use this perhaps when something is taking a long time, you know approximately how long and want the screen to keep showing something while it is going on. If you use zero for TIME then nothing is done, you have just set the maximum amount for use with set_progress. The amount is a decimal number, 0.5 would be half the progress bar being filled.
Ex. show_progress("0.300000", 10);
set_progress(AMOUNT); This command sets the pointer or fill amount of the progress bar according to the last show_progress command. It should never be greater than the total of the show_progress amount.
Ex. show_progress("0.300000", 0);
set_progress("0.15");
mount(TYPE, DEV, PATH); This is one version of the mount command. The TYPE arg is usually "MTD", which refers to memory technology device. The DEV for a MTD would be something like "system", "userdata", "cache", and the PATH would be "/system", "/data", or "/cache". You will also see TYPE be "vfat".
mount(FSTYPE, TYPE, DEV, PATH); This seems to be the more current mount command. It adds in the file system type. Ex. "ext3", "yaffs". TYPE with this command can be "MTD" or "EMMC". You would use "EMMC" with "/dev/block/mmcblk0p8".
umount(PATH); This simply removes a previous mounted PATH from the system. Ex. umount("/system"); You'll notice the double quotes around command arguments, they are not strictly necessary. Unless it's a reserved word (if then else endif) then they can be anything. "consisting of only letters, numbers, colons, underscores, slashes, and periods". So if you just spend 10 minutes uploading your zip to your phone and notice that your unmount command is umount(/system);, it will work just fine.
sleep(SECS); Simply pauses for SECS seconds.
package_extract_file(FILE, FILEWITHPATH); This command extracts one of your files from the CWM zip package and save it to the phone.
Ex. package_extract_file("bootanimation.zip", "/system/media/bootanimation.zip");
package_extract_dir(ZIPPATH, PATH); This command extracts an entire folder in your CWM zip to a folder on your phone.
Ex. package_extract_dir("system", "/system"); *This is where having system mounted would be handy, without it being mounted, the files would be copied to the ramdisk /system.
write_raw_image(PATH, PARTITION); This is one of those tricky ones, the PATH is somewhere on your phone with the image to be flashed to a PARTITION on your phone. The trouble is, how do you specify what partition gets flashed? Is there any restriction on where the file has to be? If MTD conventions are used, you are looking for "system", "boot", "recovery", "logo.bin". (All this means that each partition has a name stored somewhere, and if you know it, you can write to it.) Maybe it will accept device references like /dev/block/mmcblk0p8. This depends on the update-binary file you are using.
Ex. write_raw_image("/tmp/logo.bin", "logo.bin");
Ex. write_raw_image("/tmp/logo.bin", "/dev/block/mmcblk0p8");
write_firmware_image(PATH, PARTITION); You would think it would be the same as write_raw_image. Not sure what the difference is.
run_program(PROG, ARG1, .., ARGN); Pretty self explanatory, This command allows you to execute a program or script on the phone. Instead of all the bits of the command being separated by spaces, commas are used. It returns an error code as a string.
Ex. run_command("ls", "-R", "/system");
Assert(condition); You'll see this one a lot in OTA updates, all it does is abort the script if something goes wrong. If condition is false, the script ends displaying a description on the phone of what command caused the exit. You can put in more than one statement here, separated by ";", if any one of them returns with an error, the script exits.
Ex. Assert(mount("ext3", "EMCC", "/dev/block/mmcblk0p12", "/system")); *If you can't mount /system and your CWM zip only writes to system, you might as well stop it before continuing on to write to the ramdisk.
ifelse(condition, true path, false path); This is your basic conditional statement, the tricky bit is to figure out what statements in edify can trigger a true of false condition. As for the rest of it, the commas separate the two blocks.
Ex. ifelse(file_getprop("/system/default.prop", "ro.build.id") == "OLYFR1.2.3.4", ui_print("yes"), ui_print("false"));
abort(); This stops the script, useful with ifelse.
file_getprop(PATH, VALUE); This command looks for a text file containing A=B pairs and returns B if it can find an A.
Ex. file bob.txt exists in /tmp, it contains cool=yes, and dorky=true123 each on separate lines.
file_getprop("/tmp/bob.txt", "cool") == "yes"
file_getprop("/tmp/bob.txt", "dorky") == "true123"
getprop(VALUE); Functions the same as file_getprop, without the file part. It looks through the system value pairs for a matching value.
Ex. getprop("ro.build.id") == "OLYEM1.2.3.4"
delete(PATH1, ...,PATHN); Nothing to see here, just a delete command, full path to the file(s) as argument(s).
delete_recursive(PATH1, ...,PATHN); It's a delete everything in a folder, including subfolders command. The folder itself is deleted as well.
set_perm(UID, GID, MODE, PATH1, ..., PATHN); Set the linux permissions on a file, ownership and flags at the same time. Equivalent to chown and chmod in the one command.
Ex. set_perm(0, 0, 06755, /system/bin/su, /system/bin/shsu); *0 stands for root, so it would be owned by root, of the group root, with suid bit set and standard executable bits set.
set_perm_recursive(UID, GID, DIRMODE, FILEMODE, PATH1, ...,PATHN); Same as above except with folders instead of files. Use the DIRMODE to set the permissions and ownership of the folders themselves, and FILEMODE to set the permissions of the files within them.
symlink(TARGET, LINK1, ...,LINKN); It's the equivalent to the linux ln -s command. For our purposes, it might as well be called busybox install.
Ex. symlink("/system/bin/busybox", "/system/bin/awk", "/system/bin/wget", "/system/bin/sed");
To Be Continued..
​
References
http://devphone.org/development/edify-script-syntax-explained/
http://www.synfulgeek.com/main/index.php/articles/76-scratchpad-documenting-edify-commands-for-android-updater-scritps-based-off-of-kernel-source-code
https://github.com/koush/android_bootable_recovery/blob/eclair/edify/README
http://tjworld.net/wiki/Android/UpdaterScriptEdifyFunctions​

Tips:
You can use the abort() command to step through your updater script, for instance if you wanted to check various combinations on syntax for write_raw_image();
In /tmp there is a text file called recovery.log, do a cat /tmp/recovery.log to see extra output of your script from failed commands.

NFHimself said:
The updater-script file is a text file, it is linux formatted with regard to end of line conventions. If you use Windows then you have to edit the file using a program that keeps line feeds the way they are and has options for doing the conversion from <CR><LF> to just <LF>.
Click to expand...
Click to collapse
If you are in windows, I have found that notepad++ does the job just fine.
http://notepad-plus-plus.org/

what about the FORMAT command?
actually i have error on a CM installation, its says
Code:
format() expects 3 args, got 2.
but my format command have 3 args:
Code:
format("ext4", "/dev/block/mmcblk0p10", "/system");

NFHimself said:
Hi, I haven't seen any good resources for how to edit edify scripts, so I thought I would create this thread so we can pool our knowledge on the subject.
Intro​
Click to expand...
Click to collapse
Thanks for this... but I do have a question....
I am attempting to see if busybox is installed on a device, and if not install it, or proceed
so, so far I have:
Code:
ifelse(
BUSYBOX DOESNT EXIST,
(
ui_print("* Did not find it. Installing...");
set_perm(0, 1000, 0755, "/system/xbin/busybox");
symlink("/system/xbin/busybox", "/system/bin/busybox");
run_program("/system/xbin/busybox", "--install", "-s", "/system/xbin");
),
(
ui_print("* Found it. Proceeding...");
)
);
You can see where I'm lost I was thinking of using assert to run_program("/system/xbin/busybox", "vi", "/system/xbin"); just as a simple check... but from what I can see, if the assertion fails it will stop the script, and print out the failure message, which of course is not what I am after here... or maybe I am, can it be used to do a check rather than stop the script?​

Just an idea (ie. untested):
Code:
ifelse(
run_program("/system/bin/sh", "-c", "test -e /system/xbin/busybox")
...
)

ravilov said:
Just an idea (ie. untested):
Code:
ifelse(
run_program("/system/bin/sh", "-c", "test -e /system/xbin/busybox")
...
)
Click to expand...
Click to collapse
trying to run that in adb sheel, and don't get a response, but it does seem like a good idea... I assume Edify would return a 1/0 or true/false string from it, and I can just check for that?
EDIT: Maybe I do get something back... after running that in adb shell my next line looks like the following:
Code:
1|[email protected]:/ #
Am I right in assuming that "1" is the output?

Yes. The command won't ever return any output, it only returns the exit status. Your shell is obviously set so it includes a non-zero exit status in the prompt. (Non-zero traditionally means error.)

ravilov said:
Yes. The command won't ever return any output, it only returns the exit status. Your shell is obviously set so it includes a non-zero exit status in the prompt. (Non-zero traditionally means error.)
Click to expand...
Click to collapse
that prompt means that the test failed, and I don't have busybox installed?
I'm just a tad confused... (this is my first full-on edify script), and I do have busybox installed
I appreciate the help, and once I get my tapatalk working right on my phone, I'll give ya all the "thanks" for the help with this
Eh... everything I 'test' returns the same thing
Code:
1|[email protected]:/ #

Hm, weird. It works for me...
Code:
# /system/bin/sh -c 'test -e /system/xbin/busybox'; echo $?
0 [color=silver]<-- no error - file exists[/color]
# /system/bin/sh -c 'test -e /system/xbin/busybox1'; echo $?
1 [color=silver]<-- error - file does not exist[/color]
I didn't try it in an edify script because I don't feel like rebooting my phone right now, but I don't see why it wouldn't work.
Try running the "sh -c test ..." command in adb shell while in recovery and see what happens.
Also, just a side note: backslash is NOT the same as slash. If you are going to write shell/edify scripts, you need to know at least that distinction. That is why your
Code:
tags are not working right.[/b][/i][/size]

ravilov said:
Hm, weird. It works for me...
Code:
# /system/bin/sh -c 'test -e /system/xbin/busybox'; echo $?
0 [color=silver]<-- no error - file exists[/color]
# /system/bin/sh -c 'test -e /system/xbin/busybox1'; echo $?
1 [color=silver]<-- error - file does not exist[/color]
I didn't try it in an edify script because I don't feel like rebooting my phone right now, but I don't see why it wouldn't work.
Try running the "sh -c test ..." command in adb shell while in recovery and see what happens.
Also, just a side note: backslash is NOT the same as slash. If you are going to write shell/edify scripts, you need to know at least that distinction. That is why your
Code:
tags are not working right.[/b][/i][/size][/QUOTE]
I see, I wasn't doing the echo, and what you posted shows exactly what you posted. DOH on the CODE :good:
So I have it on record (for my own personal reference)
[CODE]
ifelse(
((run_program("/system/bin/sh", "-c", "test -e /system/xbin/busybox; echo $?") == 1 ||
(run_program("/system/bin/sh", "-c", "test -e /system/bin/busybox; echo $?") == 1 ||
(run_program("/system/bin/sh", "-c", "test -e /system/xbin/busibox; echo $?") == 1 ||
(run_program("/system/bin/sh", "-c", "test -e /system/bin/busibox; echo $?") == 1),
(
ui_print("* Did not find it. Installing...");
set_perm(0, 1000, 0755, "/system/xbin/busybox");
symlink("/system/xbin/busybox", "/system/bin/busybox");
run_program("/system/xbin/busybox", "--install", "-s", "/system/xbin");
),
(
ui_print("* Found it. Proceeding...");
)
);
and yes, I meant the 'busibox' part, because I have seen that in some roms
Click to expand...
Click to collapse

You guys know way more about this stuff than I do... although i am a programmer
could I get some insight over here: http://forum.xda-developers.com/showthread.php?t=2796055
having an issue getting my shell scripts to actually run...
Rockin' it from my Smartly GoldenEye 35 NF1 (muchas gracias:* @iB4STiD @loganfarrell @muniz_ri @Venom0642 @ted77usa @rebel1699* @iB4STiD) ~ 20GB free cloud https://copy.com?r=vtiraF
Check me out online @ http://kevin.pirnie.us
note: the scripts do run in adb shell

published API docs
NFHimself said:
Hi, I haven't seen any good resources for how to edit edify scripts, so I thought I would create this thread so we can pool our knowledge on the subject.
Click to expand...
Click to collapse
I found some official documentation of the API on the Android Web site here:
https://source.android.com/devices/tech/ota/inside_packages.html
NFHimself said:
[*]write_raw_image(PATH, PARTITION); This is one of those tricky ones, the PATH is somewhere on your phone with the image to be flashed to a PARTITION on your phone. The trouble is, how do you specify what partition gets flashed? Is there any restriction on where the file has to be? If MTD conventions are used, you are looking for "system", "boot", "recovery", "logo.bin". (All this means that each partition has a name stored somewhere, and if you know it, you can write to it.) Maybe it will accept device references like /dev/block/mmcblk0p8. This depends on the update-binary file you are using.
Ex. write_raw_image("/tmp/logo.bin", "logo.bin");
Ex. write_raw_image("/tmp/logo.bin", "/dev/block/mmcblk0p8");
[*]write_firmware_image(PATH, PARTITION); You would think it would be the same as write_raw_image. Not sure what the difference is.
Click to expand...
Click to collapse
I didn't do a line by line comparison between your description and theirs, but I noticed this part because I was trying to find information about these functions. Only write_raw_image() is a published API function. This is the description:
write_raw_image(filename_or_blob, partition)
Writes the image in filename_or_blob to the MTD partition. filename_or_blob can be a string naming a local file or a blob-valued argument containing the data to write. To copy a file from the OTA package to a partition, use: write_raw_image(package_extract_file("zip_filename"), "partition_name");​
Probably write_firmware_image() is used internally. It could be removed at any time, or it even could be a stub - not a good idea to use it.

Related

How to install ubuntu on the Droid 4

How to install ubuntu on the Droid 4
Note to mods: this thread is a branch off of this thread
Huge thanks to zacthespack for creating the ubuntu installer app and original boot script and to zeroktal for modifying the script to work on the D4 and helping me get it working on my device.
I decided to take my experience in setting this up and put it into a how-to so that others could enjoy the experience of having ubuntu on the Droid 4. If zackthespac or zeroktal have any problems with me making and putting this guide up, please let me know and I will remove it.
Knowledge Required:
working knowledge of command line
working knowledge of vi
OR the ability to learn how to use both
Tools Required:
A rooted Motorola Droid 4
BusyBox (Android Market)
Terminal Emulator (Android Market)
Android VNC Viewer (Android Market)
Ubuntu Installer App (Android Market)
zeroktal's ubuntud4.zip file (attached to this post and mediafire)
Vi Cheat Sheet (lagmonster.org)
Step by Step:
Install BusyBox, Terminal, and Android VNC Viewer
Install and run Ubunutu Installer App
Follow the on-screen instructions and click next
Download either the Small or Large image to your phone, (use zeroktal's ubuntud4.zip file instead of the boot script provided in the guide) after the image downloads (will take a while because the file is HUGE) click next
For this screen, the instructions differ from the app.
1. With your D4 plugged into your PC in USB Mass Storage, create a directory (folder) called ubuntu in the EXTERNAL sdcard's root*
2. Extract the image you downloaded to that directory
3. Download and extract the attached .sh (ununtud4.zip) to that directory
4. Disconnect your phone from your PC
5. Open terminal and run the following commands:
su [ENTER]
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext [ENTER]
cd /mnt/sdcard-ext/ubuntu [ENTER]
sh ubuntud4.sh [ENTER]
960x540 [ENTER]**​If you get an error message: ubuntud4.sh: 45: syntax error: end of file unexpected (expecting "then") see troubleshooting section below.​killall -TERM Xtightvnc [ENTER]
vncserver :1 -geometry 960x540 [ENTER]**​6. Open androidVNC app and enter the following settings:
Nickname: Anything you want
Password: ubuntu
Address: localhost
Port: 5901
Color Format: 24-bit color (4 bpp)
7. Hit connect
8. Hit your menu soft button and then set input mode to touchpad
9. You have ubuntu on your Droid 4!
To "shut down" ubuntu:
press the menu button, select disconnect in VNC
In terminal type this command 3 times (terminal will close itself when you are done):
exit [ENTER]
To "start up" ubuntu again:
Follow steps 5-8 above
Troubleshooting:
If you get the error message: ubuntud4.sh: 45: syntax error: end of file unexpected (expecting "then") you are about to have fun with vi at the command line.
Do the following from inside terminal:
su [ENTER]
cd /mnt/sdcard-ext/ubuntu [ENTER]
vi ubuntud4.sh [ENTER]​If you see ^M or ^ at the end of any line (remember to scroll all the way to the right to see the end of long lines) remove it. once you do that, everything should work just fine. (See the Vi Cheat Sheet above for help with Vi)
Note: Vol Up + E is [ESC] by default in this terminal emulator
Notes:
* It does not have to be on the external SD, but if you put it on the internal SD you will have to modify things as needed-- if you dont know what needs to be changed, just put it on the external SD.
** Screen size can be whatever you want it to be, but 960x540 is the size of the D4 screen.
*** This is a fairly involved process... especially when it comes to editing the .sh file in vi things can get very frustrating and hard, but just take your time and you will get it. As always, doing anything with root access on your phone, especially on the command line has risks. I am not responsible if anything goes wrong with your phone... proceed at your own risk!
greekchampion04 said:
Notes:
* It does not have to be on the external SD, but if you put it on the internal SD you will have to modify things as needed-- if you dont know what needs to be changed, just put it on the external SD.
** Screen size can be whatever you want it to be, but 960x540 is the size of the D4 screen.
*** This is a fairly involved process... especially when it comes to editing the .sh file in vi things can get very frustrating and hard, but just take your time and you will get it. As always, doing anything with root access on your phone, especially on the command line has risks. I am not responsible if anything goes wrong with your phone... proceed at your own risk!
Click to expand...
Click to collapse
I actually got it up and running on my internal sdcard partition. Pretty much just have to modify the Mount remount command, and a few lines in the script.
Here's the original command
Code:
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext
And the modified one
Code:
mount -o remount,rw,exec,suid /dev/block/vold/179:57 /mnt/sdcard
Only things you have to change are the device location(179:57) and mount location(drop the -ext after sdcard)
Now, after that you also have to modify the script a bit. Just go through it, and anywhere that you see sdcard-ext, drop the -ext off the end.
thanks for putting that up for everybody! like i said, if you know what you are doing its not a hard swap to make.
Is anyone else getting just a gray screen when they remote in? What could be causing this?
i had that same problem at first... did you use zeroktal's ubuntud4.zip file? or did you use the ubuntu.sh file included in the app?
I used the sh file included. I did however fix the problem, when mounting at the start i confused vold with void. I did not get the file system mounted properly. This method does work!! however I am currently trying to get bash on my droid to replace sh as the shell. I've checked the forums but have not found anything yet about someone installing bash on the droid 4. With no way for nandroids I feel i should wait before I kill sh.
Sent from my DROID4 using XDA App
If you mod your init.sh in your root directory to the following, your vnc will work on startup without issue. It will also shutdown vnc on exit.
#!/bin/bash
#############################################
# Asks User to screen size and saves as REZ #
#############################################
#echo "Now enter the screen size you want in pixels (e.g. 800x480), followed by [ENTER]:"
#read REZ
##############################################
# Pick which desktop environment to use, this#
# is done by having a xstartup file for each #
# desktop, then renaming the one you want to #
# use to 'xstartup' before boot #
##############################################
echo "Please select which Desktop environment you want to use, type the number to select it then press [ENTER]"
echo "1 - LXDE"
echo "2 - Gnome"
echo "Make your Selection:"
read DESKTOP
if [ $DESKTOP == 1 ]
then
mv /root/.vnc/lxstartup /root/.vnc/xstartup
fi
if [ $DESKTOP == 2 ]
then
mv /root/.vnc/gxstartup /root/.vnc/xstartup
fi
###########################################
# Tidy up previous LXDE and DBUS sessions #
###########################################
rm /tmp/.X* > /dev/null 2>&1
rm /tmp/.X11-unix/X* > /dev/null 2>&1
rm /root/.vnc/localhost* > /dev/null 2>&1
rm /var/run/dbus/pid > /dev/null 2>&1
############################################################
# enable workaround for upstart dependent installs #
# in chroot'd environment. this allows certain packages #
# that use upstart start/stop to not fail on install. #
# this means they will have to be launched manually though #
############################################################
dpkg-divert --local --rename --add /sbin/initctl > /dev/null 2>&1
ln -s /bin/true /sbin/initctl > /dev/null 2>&1
###############################################
# start vnc server with given resolution and #
# DBUS server, (and optionally an SSH server) #
###############################################
dbus-daemon --system --fork > /dev/null 2>&1
/etc/init.d/ssh start
vncserver :1 -geometry 960x540
echo
echo "If you see the message 'New 'X' Desktop is localhost:1' then you are ready to VNC into your ubuntu OS.."
echo
echo "If VNC'ing from a different machine on the same network as the android device use the 1st address below:"
##########################################
# Output IP address of android device #
##########################################
ifconfig | grep "inet addr"
echo
echo "If using androidVNC, change the 'Color Format' setting to 24-bit colour, and once you've VNC'd in, change the 'input mode' to touchpad (in settings)"
echo
echo "To shut down the VNC server and exit the ubuntu environment, just enter 'exit' at this terminal - and WAIT for all shutdown routines to finish!"
echo
###############################################################
# Spawn and interactive shell - this effectively halts script #
# execution until the spawning shell is exited (i.e. you want #
# to shut down vncserver and exit the ubuntu environment) #
###############################################################
/bin/bash -i
#########################################
# Disable upstart workaround and #
# kill VNC server (and optionally SSH) #
# Rename used xstartup to its first file#
#########################################
killall -TERM Xtightvnc
/etc/init.d/ssh stop
Also save the follow lines between ### as remount.sh on your system partition. Then chmod 755 /system/remount.sh. Now you can just run run from a terminal /system/remount.sh and voila it remounts correctly and starts ubuntu(with the above fixes). Im still working on the unmounts.
####### for the internal sd card
mount -o remount,rw,exec,suid /dev/block/vold/179:57 /mnt/sdcard
/mnt/sdcard/ubuntu/ubuntu.sh
######
OR
####### for the external sd card
mount -o remount,rw,exec,suid /dev/block/vold/179:1 /mnt/sdcard-ext
/mnt/sdcard-ext/ubuntu/ubuntu.sh
#######
great stuff!
feel free
Feel free and take, modify, repost or edit anything I touch.
QUESTION:
After I delete all the ^M and ^ what do i do next? I try to hit the command ":x" to exit and save changes but it just creates another line. Also when I press VOL UP + E to escape nothing happens.
PhanTuhC said:
QUESTION:
After I delete all the ^M and ^ what do i do next? I try to hit the command ":x" to exit and save changes but it just creates another line. Also when I press VOL UP + E to escape nothing happens.
Click to expand...
Click to collapse
In vi, the command to save and exit is :wq (probably short for write and quit).
remember, read up on the vi quick-reference guide: http://www.lagmonster.org/docs/vi.html
OK I fixed it but now its not letting me connect with androidVNC. All the settings entered is correct but when I try to connect it says:
"VNC connection failed!" localhost/127.0.0.1:5901 - Connection refused"
ok, i've gone thru this a few times (slowly and deliberately) and must be missing something...the directions seem pretty straightforward! here's what i know...
busy/terminal/vnc are all installed
small 2.5gb image is unzipped in /sdcard-ext/ubuntu directory
the attached .sh file from page 1 is in the same directory
i removed all ^M using vi
but when I try sh ubuntud4.sh i get an error...
"mkdir failed for /data/local/mnt/ubun, No such file or directory"
(plus a few other errors)
should the directory be "ubun" or "ubuntu"? am I typing something incorrectly?
copy and paste new script
Copy and paste the new scripts I posted. They will fix your problem. Remember to use the remount script from /system/ the rest will work perfectly if you are root. I'll check back later on your progress.
Ok, well I started from scratch (deleted both .img and .sh files) and it's still not working.
I have all the apps installed (and yes rooted, SU works just fine)
I used Ubuntu Installer app to download the image zip (tried both the large and small img)
I downloaded the .sh file from the first post
The /sdcard-ext/ubuntu/ folder now has two files: "ubuntu.img" and "ubuntud4.sh"
All ^M characters have been removed from .sh file
Still no joy...
Ideas? What am I missing?
In terminal, I can set SU permissions and the mount/cd commands work just fine...it's the last sh command that spits out a bunch of errors about not being able to create/find the directories.
I'm going to format the sdcard and try again...any help is appreciated.
Update: Even after re-formatting the SD and following the steps exactly, no luck!
Did you remember to remount the sdcard with exec and suid permissions?
Andbuntu will work much better than this method. It works on every single phone with modification to the "environmental variables".
http://code.google.com/p/andbuntu/
Follow the directions in the script to make the process much easier than the first post.
instructions:
generate an image with rootstock on an ubuntu computer.
put it on /sdcard/ubuntu/ubuntu.img
run the script on your phone with "sh /path/to/script"
Here is the script. http://andbuntu.googlecode.com/svn/trunk/uboot
Also, run "firstRun" to make things like terminals work properly.
Adamoutler: That didnt work for me. The permissions were incorrect on the mounted partitions.
Sent from my DROID4 using XDA App

[RECOVERY/BOOTSTRAP]Tweaked Safestrap v2.00a (ICS Leak) 06-13-2012

************************************
************************************
Note: Please uninstall Hashcode's Safestrap before you try installing this one. To accomplish this properly, you have to do two things:
1. Open up the Safestrap app from your launcher, and choose "Uninstall Recovery". Let it finish. It'll tell you whether or not it worked.
2. Then, go to Settings - Apps and find Safestrap. Click "Uninstall".
************************************
************************************
Installation of this app requires root privileges. If the installation does
not work, it is likely because you either:
a) don't have busybox installed.
b) you do have busybox installed but it doesn't have the functions we
need.
No problem. Just do this through adb or a terminal on the phone:
Code:
$ su
# mount -o remount,rw /system
# cp /system/xbin/busybox /system/xbin/busybox.old
# cp /data/data/com.hashcode.droid4safestrap/files/busybox /system/xbin/
# chmod 755 /system/xbin/busybox
# exit
Now it should work without a hitch.
************************************
************************************
Those of you who came from the Droid 3 might remember my customized version of Hashcode's Safestrap, which included a console, improved user-interface, non-safe flashing, etc.
I've finally got it to the point where I think it would be okay to release out in the wild. That being said, I'm not responsible for anything dumb you do to your own device.
I wouldn't bother using the non-safe flashing capabilities yet, seeing as how there hasn't really been any official releases using the new ICS kernels that have been leaked as of late. This feature is handy if you're a developer testing out update.zips for /systemorig, but for the average person you'd best pay heed to the warnings and just use Safestrap as it was originally intended; that is, leaving your /systemorig partition intact and only mess around with your "safe" /system. (Or /preinstall, actually, but that's not really important.)
The console is beyond useful. Editing build.prop settings on the fly without having to boot up and do it in a terminal emulator or via adb on the phone is much easier. If you know what you're doing, you can even extract single files from your old backups, modify your old backups, etc. That's just a small fraction, but those of you who would care about this functionality don't need me to say how important it can be.
I've included statically compiled versions of "bash" and "vim" so that there aren't any dependencies on the libraries usually found in /system/lib. Thus, you can use all of these utilities without having either /system or /systemorig mounted. You're free to add your own binaries in your home folder, which is located at /cache/.safestrap/home, or just pop them onto your sdcard.
Also, I have a battery monitor running so it will tell you what level your battery is at, and have put a lot of work into the visual appearance of the user-interface. There are so many things I've modified that it would be impossible for me to list them all here.
Anyways, try it out and let me know what you guys think. I hope you like it!
For those of you who are interested, I always post my sources on Github. You can find my code repositories here:
https://github.com/buddyrich
The .APK can be downloaded from my DropBox via the link below:
http://db.tt/tZdmUHl1
=========================
RECOVERY MENU REFERENCE
=========================
Select Highlighted Item - Enter or Power
Scroll Up - Volume Up or Left Arrow
**Note: The Left/Right Arrow keys may sound weird but since the menu is displayed in portrait mode, it just feels like you are pushing Up/Down.**
Scroll Down - Volume Down or Right Arrow
Direct Menu Selection - Hit the corresponding number/letter at the beginning of each menu item.
**ie: from the main menu, hit "6" to jump to the advanced menu.**
Go Back / Cancel - Caps Lock
===================
CONSOLE REFERENCE
===================
Keys:
--------------------
Tab - Tab
** Note: The Tab key is your best friend when using bash. It will auto-complete file/directory names for you, or list out the possible choices if you double-tap it after entering a few letters.
SYM - Alt
Shift - Shift
OK - Control
Caps Lock - ESC
OK+Shift - Toggle Caps Lock
OK+SYM - Toggle Alt Lock
** Note: The LED beside the Caps Lock button will illuminate when either Caps Lock or Alt Lock is enabled.
OK+Backspace - Force exit
OK+A - Home
OK+E - End
OK+C - Stop current process, ie: if a program you are running chokes up.
=========================
bash Commands:
--------------------
Here are a few of the more useful bash commands that you will use:
===========
ls, ls -a, ls -l, ll
===========
Code:
/ {}$ ls
- "ls" lists the files and directories within the current directory.
- You can also add a path after it to look for certain files or directories.
Code:
/ {}$ ls -a
- "ls -a" will list all files and directories, including hidden ones starting with a ".", ie: .bashrc in /cache/.safestrap/home. (The bash startup script).
Code:
/ {}$ ls -l
- "ls -l" will do a long listing, showing permissions, file sizes, etc.
Now, instead of using those parameters, I've made aliases within the .bashrc script so you will probably just want to type:
Code:
/ {}$ ll
- "ll" is an alias for "ls -a -l", so it will list all files/directories, hidden or not and list their properties.
Code:
/ {}$ ll
- By putting a path after "ll", it will single out the file. Add a "*" in there to act as a wildcard to list multiple files with the same first few characters.
- ie: "ll /system/lib/libc*" would display all the files and directories starting with "libc" within /system/lib as well as their properties.
========
cd
========
Code:
/ {}$ cd (path)
- Change directory. Pretty self-explanatory. Try doing:
Code:
/ {}$ cd ~/
- This takes you to the home folder. Pretty useless here but this is usually pretty handy in other scenarios.
Code:
/ {}$ cd ../
- Using "../" as your target will cause you to drop down a single directory in the tree.
**** Don't forget to hit tab to auto-complete directory/file names for you whenever you've already entered the first few characters. More accurate and much less typing. ****
=======
mv
=======
Code:
/ {}$ mv (source) (destination)
- "mv" is short for move. The source is the path to the file/directory you want to move, and I don't think i need to tell you what the destination is.
=======
rm
=======
Code:
/ {}$ rm (-r -f) (target)
- "rm" is used to delete the targetted files.
- "-r" means to recurse, or go into every inner directory automatically, erasing as it goes.
- You'll use the -r flag a lot, because you can't delete directories without it unless you use "rmdir", which is just more typing.
"-f" means force in case of permission errors, as long as you are root.
========
cp
========
Code:
/ {}$ cp (-f -a) (source) (destination)
- Copy the source file or directory to the destination.
- Use "-f" to force the copying, in the event of a potential overwrite.
- Use "-a" to maintain permissions of the original, you'll want to use this whenever you are copying anything important. I just use it all the time, but sometimes it won't work, such as when copying from an /sdcard to either the /system or /data partition.
-This is because the file system of your /sdcard doesn't care about permissions.
=========================
============
[VIM REFERENCE]|
============
Vim deserves, and has, entire websites devoted to it's use. Here are some of the basics.
------------
Using Vim|
------------
From the console, simply type:
Code:
/ {}$ vim
Where is obviously replaced by the name of the file you are editing.
Multiple files can be opened at once by just adding them as parameters to vim:
Code:
/ {}$ vim file1 file2 file3 file4 filen
---------------
Insert Mode |
---------------
This is the mode you want to be in to make any visible changes to the file you are editing.
- Enter Insert Mode by pushing "i" when vim opens.
- Exit Insert Mode by pushing Capslock.
Keys:
------
Backspace - In insert mode, deletes the previous character.
Capslock - Exits insert mode
---------------
Visual mode |
---------------
By typing in "v" instead of "i", you will enter visual mode; this is Vim's fancy way of saying you will be selecting text.
Keys:
------
- Copy or Cut text by hitting "y" or "d" after you've made a selection
- Paste with "p" or "P" (that is, Shift+p). Shift-"p" puts the text before the cursor whereas plain lowercase "p" will paste it after.
- When you're done highlighting what you want to either cut or copy, just hit Capslock to go back to Command Mode.
-------------------
Command Mode |
-------------------
Vim starts out in Command mode. It seems confusing but once you get used to it, you can't help but hate Notepad.
Some of the more common commands are listed below.
Keys:
------
u - Undo
Shift+r (Usually denoted as R) - Enter Replace Mode, where you are replacing text instead of inserting it.
[#]yy - Yank (copy) the current line if you just entered "yy", or copy "#" lines if you enter #yy, ie: 5yy to copy 5 lines.
[#]dd - Delete (cut) the current line, or delete # lines if preceded by a #.
p - Pastes after the cursor
Shift+p (usually denoted as P) - Pastes before the cursor
:[#] - (Ignore the square brackets; a colon followed by a number goes to that particular line in the text file you are editing. eg: ":5" goes to line 5. (Obviously, don't type the quotation marks in.)
Note: - If you are in Insert mode, you will have to push Capslock to exit and be allowed to enter Command Mode by entering a ":"
- It's fairly common practice to just hit Capslock twice whenever you're done inserting so that you are sure to be able to hit ":" and proceed to enter another command.
:w - Write (save) the currently open file.
:q - Quit. If you haven't saved since making any changes, it will prompt you to either save your changes or append a "!" after "q" to quit without saving. (See below)
:q! - Force quit without saving.
:wq - Save and then quit.
:e [path to filename] Opens up another file; you can use bash command-line completion to scan the current directory, or otherwise just enter another path.
:next or rev - Aptly named, move to the next or previous file if you opened vim with two or more files as parameters, ie:
Code:
/ {}$ vim file1 file2
:/[text] - Search for "text". ie: ":/search" will find instances of the text "search" in the current file and highlight them.
Note: You need to make sure you are aware of regular expressions/escape characters before using this reliably; it's not broken if you can't seem to search for a quotation mark or other special characters, you need to precede them by a \. ie: to look for a double-quote symbol " you would enter :/\". The \ tells it that the next character is meant to be taken literally and not symbolically.
:/[text]/[moretext]/gc - Replace "text" with "moretext" everywhere in the file and ask confirmation for each change. If you forget to type in the "gc" at the end, it'll just replace everywhere without asking you for confirmation.
That's all I'm going to put here. There are tons of guide out there and I've already preloaded a pretty awesome configuration (.vimrc located at /cache/.safestrap/home) and runtime files. If you want to quickly access the configuration file, you can type ",,e" in Command Mode and it will automatically pop open.
================
COLOR CHANGING
================
1. If you want to change the color scheme, you need to figure out what the RGB code for the color you want is. Here's a website that provides a large table of colors and their corresponding RGB color code:
http://web.njit.edu/~kevin/rgb.txt.html
For example, let's say we like the "SlateGray4" color from the table linked above want to use it for the menus in both Safe and Non-Safe mode. As you can see, in the "R;G;B; Dec" column, the three codes we are interested in are 108, 123 and 139.
2. Now that you know the color codes, in our case 108, 123 and 139, we simply do the following:
a) Push 7 from the main menu, or scroll down and select "console menu".
b) Push 1, or scroll down and select "open console"
(Don't panic if it takes a few seconds to load the console; on the first initialization or after wiping the /cache partition, it will take a few seconds to reconfigure itself.)
c) At the prompt, enter the following:
Code:
/ {}$ ns_rgb 108 123 139
/ {}$ s_rgb 108 129 139
/ {}$ cc
/ {}$ exit
Now, it'll take another second or two and when the menu pops back up, you'll see that it is the color we chose from the table. The "ns_rgb" command takes three parameters, each of which correspond to the R, G and B values of the color code, and uses them for the "Non-Safe" (hence the "ns") menu color.
Similarly, the "s_rgb" command, (well technically, it's a bash function but anyways...) takes the same three parameters. It is applied to the "Safe" menu color.
The "cc" command actually sets the color, so don't forget to enter it. Otherwise, you won't notice a change when you exit out from the console.
Feel free to experiment with different colors! If you don't what you've done and just want to reset it back to the way it way, just wipe the cache partition:
a) Push 3, or scroll down to "wipe menu".
b) Push 1, or just hit Enter on "wipe cache".
c) Confirm your selection by pushing 8 or scrolling down and selecting "yes - wipe cache".
=================================================
More to come as I have more time.
Awesome, just a couple questions:
1) where is the dropbox download
2) if I already have the hashcode safestrap installed, how does one install yours? And what happens if I am already running a custom ROM?
Sent from my XT894 running ICS
Good call, I should make that clear.
Make sure you uninstall Hashcode's Safestrap, both inside the app and from the Android Settings menu before you install this .APK.
- download the pimped apk, uninstalled safestrap recovery, uninstalled old safestrap
- installed pimped safestrap, install new safestrap recovery, reboot
looks fine
anyone who restorerd a full backup of ics leak with safestrap 2.0?
friend got a problem, and system was unbootable and lost root....
Yeah, I've done it about four times today. No problems using either my modified version or Hashcode's original Safestrap v2.00.
It was no problem recovering from a busted /system partition either; just fastbooted the /system and /preinstall partitions only from the .219 leak, then rebooted the phone into the stock recovery and re-applied the .208 leaked update .zip file. Re-rooted with the technique I posted the other day without a hitch.
Didn't even lose any data...
Rick#2 said:
Yeah, I've done it about four times today. No problems using either my modified version or Hashcode's original Safestrap v2.00.
It was no problem recovering from a busted /system partition either; just fastbooted the /system and /preinstall partitions only from the .219 leak, then rebooted the phone into the stock recovery and re-applied the .208 leaked update .zip file. Re-rooted with the technique I posted the other day without a hitch.
Didn't even lose any data...
Click to expand...
Click to collapse
I mean full restore in safestrap, not advanced restore.
After restore from systemorig cames an "error while restoring systemorig!" And system damage.
...Tapatalk
Rennert said:
I mean full restore in safestrap, not advanced restore.
After restore from systemorig cames an "error while restoring systemorig!" And system damage.
...Tapatalk
Click to expand...
Click to collapse
I'm not following you here, this happened to you using my version?
I've done it countless times while testing this before I released it and have been working with this code for a long time; it's pretty foolproof.
Rick#2 said:
I'm not following you here, this happened to you using my version?
I've done it countless times while testing this before I released it and have been working with this code for a long time; it's pretty foolproof.
Click to expand...
Click to collapse
No, this was tested with hashcodes safestrap. Restore in your version doesn't tested, but not need at time;-)
...Tapatalk
Having some issues with getting safestrap installed in the 208 ICS leak. The app installs fine, click install and it says install complete, but I have no safestrap. Even after a reboot it still says "Not Installed" in the safestrap app. Anyone else experiencing this issue?
Sent from my DROID4 using Tapatalk
jgardner said:
Having some issues with getting safestrap installed in the 208 ICS leak. The app installs fine, click install and it says install complete, but I have no safestrap. Even after a reboot it still says "Not Installed" in the safestrap app. Anyone else experiencing this issue?
Sent from my DROID4 using Tapatalk
Click to expand...
Click to collapse
make sure u installed/updated busybox
That was exactly it. Realized shortly after posting it. Thanks!
Sent from my DROID4 using Tapatalk
So I have tried to restore 2 different backups using your safestrap and I keep on getting MD5 mismatch errors. I have tried deleting and regenerating the checksum file via ADB, disabled signature check, changed the folder name, pretty much everything I could think of. So whats going on?
An MD5 error would indicate that your backup files don't match the checksum that was generated at the time the backups were initially generated, which most likely means that your backup files may have become corrupted... unfortunately, this can happen with any files stored on an SD card.
Don't worry too much though, there still a really good chance that you can manually restore your data, although if your MD5's aren't matching there's a tiny possibility that your backup files are toast.
*** I'll assume you are trying to restore a "safe" system backup. If it's a "non-safe" backup, then just interchange "/systemorig" and "non-safe" for "/system" and "safe", respectively. ***
You have to manually wipe your /data and /cache partitions in the wipe menu, then format "/system" in the mounts menu. This way you have a clean slate to extract your backups to.
Try this from within the console in the recovery. (Depending on whether you backed up to the internal (/emmc) or external (/sdcard) card, just mount the required partition as follows:
*** Don't worry if you get a message saying the device can't mount because it is busy, that just means it's already mounted. ***
Internal card:
Code:
{}$: mount /emmc
External card:
Code:
{}$: mount /sdcard
(To be sure, it won't hurt if you just mount both of them.)
I'll assume you used the external sdcard which is mounted at /sdcard. Now:
Code:
{}$: cd /sdcard/safestrap/backup
If you list this directory (using "ll", or "ls -l"), you'll see a list of backup directories, prefixed by either "safe" or "nonsafe" and followed by the date and time of the backup. Remember, you can use the Tab key to autocomplete file/directory names so you don't have to type in the entire path. Here's an example:
Code:
/sdcard/safestrap/backup {}$ ll
total 192
d---rwxr-x 6 1000 1015 32768 Jun 24 04:42 ./
d---rwxr-x 3 1000 1015 32768 Jun 6 04:41 ../
d---rwxr-x 5 1000 1015 32768 Jun 6 04:41 nonsafe-2012-05-25.19.22.55/
d---rwxr-x 2 1000 1015 32768 Jun 8 20:42 nonsafe-2012-06-08.13.35.00/
d---rwxr-x 2 1000 1015 32768 Jun 20 03:13 safe-2012-06-19.20.10.44/
d---rwxr-x 3 1000 1015 32768 Jun 24 13:17 safe-2012-06-23.16.25.49/
/sdcard/safestrap/backup {}$
Let's use "safe-2012-06-19.20.10.44" for my example, substitute your own directory name as I'm sure it'll be different.
Go ahead and list the contents by entering the next two commands:
Code:
/sdcard/safestrap/backup {}$: cd safe-2012-06-19.20.10.44
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$: ll
You should see something like:
Code:
/sdcard/safestrap/backup {}$: cd safe-2012-06-19.20.10.44
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ ll
total 1117760
d---rwxr-x 2 1000 1015 32768 Jun 20 03:13 ./
d---rwxr-x 6 1000 1015 32768 Jun 24 04:42 ../
----rwxr-x 1 1000 1015 74135552 Jun 20 03:13 cache.ext3.tar*
----rwxr-x 1 1000 1015 225547776 Jun 20 03:12 data.ext3.tar*
----rwxr-x 1 1000 1015 201 Jun 20 03:13 nandroid.md5*
----rwxr-x 1 1000 1015 280272384 Jun 20 03:12 system.ext3.tar*
----rwxr-x 1 1000 1015 564430848 Jun 20 03:11 systemorig.ext3.tar*
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$
Now that you're at the proper path for the backup you want to restore, we can manually extract the files from the backups. (If you haven't already done so, remember to wipe /data, /cache and /system.)
We have to mount /system, /data and /cache:
Code:
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ mount /system
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ mount /data
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ mount /cache
*** Don't worry if you get a message saying the device can't mount because it is busy, that just means it's already mounted. ***
Code:
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ tar xvf system.ext3.tar -C /
Wait a minute or two for it to finish, then:
Code:
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ tar xvf data.ext3.tar -C /
Wait some more... then:
Code:
/sdcard/safestrap/backup/safe-2012-06-19.20.10.44 {}$ tar xvf cache.ext3.tar -C /
Done. If you want, you can restore your /systemorig partition now but you probably don't want to do that, not if your MD5's don't match up.
Assuming you just restored a "safe" system backup and you are in "safe" mode, you can cross your fingers and reboot. If you aren't in safe mode, switch over to it from the safe-boot menu before you reboot.
At this point, you should have restored that backup manually. Hope that helps, it's always a bummer to lose your data.
You sir need a medal. That was the best response I could have expected. I will try this later at work. I regenerated the checksum file but like you said, it has to be at the time of the backup.
Hey man, no prob. I figure I might as well do it step by step so that others can reference this in the event of a similar situation. Hope it works out for you.
To be honest, I got frustrated and gave up. I have discovered that on the 7-4 AOKP build, if I lose data all I have to do is wipe cache and dalvik cache and boom, I have have 4G. Now if only I can get a init.d tweak to clear both on startup then all I would have to do is reboot the phone to restore data. So long story short, I'm sticking with the non ICS-Leak AOKP, no need to risk going off the upgrade path and alot less of a hassle.
@Rick#2
new Safestrap 2.10 for Droid4 is out, can you pimp this one too?

[DEV/Add-On]bash for android.

Hello all.
This is my first share at the Android forums:
On my first device -- Samsung Galaxy S2 - I9100 Intl. -- I have BASH shell, so I've got used to working with it so i was missing it on my second device -- LG Nexus 4 -- the installer from the market was not working on the last one...
So I've remembered seeing here a post by nubecoder saying he compiled bash 4.2.2 for android, ang gave it a shot, but it was not working as expected on my device...
I've decided to recreate it for my Nexus 4.
All credit goes to nubecoder, I've only re-created the ZIP installer.
So, I hope someone else will enjoy nubecoder (I've tested it on my device and it is working) work remake by me.
Highlights and remarks are most welcome...
1.1:
Fixed mounting order error...
If it worth a donation, PM me and I'll give my paypal donation details (I have not done it ever, so when it will be relevant, I will...)
dmagician said:
Hello all.
This is my first share at the Android forums:
On my first device -- Samsung Galaxy S2 - I9100 Intl. -- I have BASH shell, so I've got used to working with it so i was missing it on my second device -- LG Nexus 4 -- the installer from the market was not working on the last one...
So I've remembered seeing here a post by nubecoder saying he compiled bash 4.2.2 for android, ang gave it a shot, but it was not working as expected on my device...
I've decided to recreate it for my Nexus 4.
All credit goes to nubecoder, I've only re-created the ZIP installer.
So, I hope someone else will enjoy nubecoder (I've tested it on my device and it is working) work remake by me.
Highlights and remarks are most welcome...
If it worth a donation, PM me and I'll give my paypal donation details (I have not done it ever, so when it will be relevant, I will...)
Click to expand...
Click to collapse
thank you for this! i tried to install it. however i am running in to some problems. the installation partially fails with twrp. the update script tries to set the permission on some files in /data/local but the files are not there:
Code:
set_perm(0, 2000, 0666, "/data/local/.bash_history");
set_perm(0, 2000, 0666, "/data/local/.editor");
set_perm(0, 2000, 0666, "/data/local/.inputrc");
set_perm(0, 2000, 0666, "/data/local/.minttyrc");
these files are in the zip, but no permissions are set via the update-script:
Code:
.bashrc
.bashrc_support
.bashrc_user
.profile
can you help me out?
-- 1st Reserved --
-- 1st Reserved --
-- 2nd Reserved --
-- 2nd Reserved --
Fixed -- I Hope
UnitedOceanic said:
thank you for this! i tried to install it. however i am running in to some problems. the installation partially fails with twrp. the update script tries to set the permission on some files in /data/local but the files are not there:
Code:
set_perm(0, 2000, 0666, "/data/local/.bash_history");
set_perm(0, 2000, 0666, "/data/local/.editor");
set_perm(0, 2000, 0666, "/data/local/.inputrc");
set_perm(0, 2000, 0666, "/data/local/.minttyrc");
these files are in the zip, but no permissions are set via the update-script:
Code:
.bashrc
.bashrc_support
.bashrc_user
.profile
can you help me out?
Click to expand...
Click to collapse
Fixed mounting.
Explanation:
The data partition was mounted AFTER expanding contents, so the content was lost on mounting data partition.
Some changes failed
Hi there, I've tried to apply it on my N4 (4.4.2 stock with MultiROM, Dalvik / Bionic patches and 4Way Reboot / Volume Wake) and I got stuck in an error.
Here is my log:
* Mounting '/system'
* Mounting '/data'
/data is already mounted.
Extracting files
minzip: Extracted 318 file(s)
minzip: Extracted 2 file(s)
Setting permissions on /system/xbin/bash4.2.0.1
Setting different instalation shell scripts to be used...
about to run program [/sbin/sh] with 2 args
Creating 'b' shell excutable file for quick launching BASH
in /system/bin/
run_program: child exited with status 1
Created '/system/bin/b'
Creating symlink for BASH as /system/bin/bash
Setting permissions on directories:
/system/etc/terminfo
Setting permissions for /system/etc/bash.bashrc
and /system/etc/profile
Creating symlink for BASH as /system/xbin/bash
Settings '/data/local' owner to UID to 0 (root) and GID to 2000 (shell)
Settings '/data/local' owner to UID to 0 (root) and GID to 2000 (shell)
Settings permissions on '/data/local/bin' to 0755 (a=rwx)
Settings permissions on '/data/local/sbin' to 0755 (a=rwx)
Settings permissions on '/data/local/xbin' to 0755 (a=rwx)
Settings permissions on '/data/local' to 0755 (u+rwx,go+rx)
set_perm: chown of /data/local/.bash_history to 0 2000 failed: No such file or directory
set_perm: chmod of /data/local/.bash_history to 666 failed: No such file or directory
script aborted: set_perm: some changes failed
Settings permissions on '/data/local/.*' to 0666 (a=rw)
set_perm: some changes failed
E:Error executing updater binary in zip '/sdcard/Bash4.2.x-Installer(Nexus4)-v1.1.zip'
Error flashing zip '/sdcard/Bash4.2.x-Installer(Nexus4)-v1.1.zip'
Updating partition details...
Iata backup size is 2098MB, size: 13231MB, used: 8904MB, free: 4326MB.
I:Unable to mount '/usb-otg'
I:Actual block device: '', current file system: 'vfat'
I:Set page: 'flash_done'
I:Set page: 'clear_vars'
I:Set page: 'main2'
I:Set page: 'settings'
I:Set page: 'main'
I:Set page: 'clear_vars'
I:Set page: 'main2'
I:Set page: 'advanced'
I:Set page: 'confirm_action'
I:Set page: 'action_page'
I:Copying file /tmp/recovery.log to /data/media/0/recovery.log
Click to expand...
Click to collapse
Thank you for your help!
@dmagician thank you for the update. i just noticed the zip files contains ssh, scp, vim, nano, 7z and more :good::good: thats really aewsome!
i took a look at the scripts and i can't find anywhere a reference to these files.
Code:
/data/local/.bash_history
/data/local/.editor
/data/local/.inputrc
/data/local/.minttyrc
i need your help configuring bash. if i start bash from the default shell with "bash" the profiles is not loaded. is it possible to "symlik bash to "bash -l"? the
@Grushteniak
easiest quick fix
open terminal add this commands:
Code:
su
cd /data/local/
touch .editor
touch .inputrc
touch .minttyrc
after that flash the zip again
Worked now
@UnitedOceanic
I have created the files you asked and I had to create the '.bash_history' file too.
After that, successfully flashed it. Thank you for your help!
UnitedOceanic said:
@dmagician thank you for the update. i just noticed the zip files contains ssh, scp, vim, nano, 7z and more :good::good: thats really aewsome!
i took a look at the scripts and i can't find anywhere a reference to these files.
Code:
/data/local/.bash_history
/data/local/.editor
/data/local/.inputrc
/data/local/.minttyrc
Click to expand...
Click to collapse
These are mainly not required (I think I've packed them accidentally...), the files .bash_history and .editor are created automatically, so all of these can be safely deleted (from the device).
I will remove then sometime later - when I'll have some free time - from the ZIP...
UnitedOceanic said:
i need your help configuring bash. if i start bash from the default shell with "bash" the profiles is not loaded. is it possible to "symlik bash to "bash -l"? the
Click to expand...
Click to collapse
1st:
You can't...
Unless it is a multi-call binary like BusyBox (I'm not Linux expert... but as of my understanding -- By far: Any EXPERT that knows Linux better than me, PLEASE: Correct me if I'm wrong) -- You cannot link a binary with its switches in any way...
You can only link the the binary itself, any command line switch should be via the command line or shell script.
2nd:
There should be a small executable shell script named “b” located in /system/bin/ (its whole target is executing “/system/xbin/su -c /system/bin/bash --login” -- for ease of running and saving some taps).
Check if it exists, as the installer itself SHOULD have created it.
In case the file does not exist, you can try the following:
Open terminal emulator - any of those are good:
If you don't have any terminal emulator installed and/or don't want to install one...
ADB shell
PuTTY Tray - by Chris West (Faux):good:<--strongly recommended
If you have one installed already, open it.
If you don't have any (and/or you want one to be always available to you), IT'S TIME TO GET ONE
Open Google Play Store and search "terminal emulator", pick one and install it.
Then execute (one by one):
In case of using ADB command (option 1 listed above)
Code:
adb root
adb remount
In case of using terminal emulator (e.g. any one of options 2 or 3 as listed above)
Code:
su
mount -o remount,rw /system
and the rest: (if using ADB (e.g. option 1 listed above), prefix the commands with "adb shell" noobs: [no quotes, and with trailing space])
Code:
cd /system/bin
rm /system/bin/b
echo '#!/system/bin/sh' > /system/bin/b
echo '/system/xbin/su -c /system/bin/bash --login' >> /system/bin/b
chown 0.0 /system/bin/b
chmod 0755 /system/bin/b
remount -o remount,ro /system
exit
In some (pretty rare - I believe...) cases, you may need to add /sbin/busybox or /system/xbin/busybox
before the commands above:
As exmple, line 3:
instead of echo '#!/system/bin/sh' > /system/bin/b would be something like
/system/xbin/busybox echo '#!/system/bin/sh' > /system/bin/b​OR
/sbin/busybox echo '#!/system/bin/sh' > /system/bin/b​
UnitedOceanic said:
easiest quick fix
open terminal add this commands:
Code:
su
cd /data/local/
touch .editor
touch .inputrc
touch .minttyrc
after that flash the zip again
Click to expand...
Click to collapse
If so, (and I'm not sure of it because you are basically extracting files from a ZIP archive to location and then executing commands over them... BUT I'm neither Linux nor Edify expert... Enlightments, Corrections and Learning new things ARE ALWAYS welcome!), It is good to know that executing touch on the files will cause the installer to forcibly update them...
You meant "execute these commands" not "add this commands" -- right?
Sorry, I've misunderstood -- You ware CREATING the file by the touch command, NOT CHANGING DATE/TIME....
Could I ask what does this do? Isnt this the same thing that we can have using terminal emulator?
bamsbamx said:
Could I ask what does this do? Isnt this the same thing that we can have using terminal emulator?
Click to expand...
Click to collapse
It is not related to terminal emulator itself, but to the underlying Android shell layer.
To be specific:
It is adding SOME of the advanced BASH style capabilities to Android's shell scripting.
SOME - since not ALL (as I remember, but the most important and used, do exist) - of bash capabilities are implemented in this (small) binary.
It is an alternative to the Android's basic shell.
dmagician said:
It is not related to terminal emulator itself, but to the underlying Android shell layer.
To be specific:
It is adding SOME of the advanced BASH style capabilities to Android's shell scripting.
SOME - since not ALL (as I remember, but the most important and used, do exist) - of bash capabilities are implemented in this (small) binary.
It is an alternative to the Android's basic shell.
Click to expand...
Click to collapse
Thanks for the quick reply!!!
I do not understand too much about linux...
Could you tell me some examples of how this would benefit us??
Thanks
bamsbamx said:
Thanks for the quick reply!!!
I do not understand too much about linux...
Could you tell me some examples of how this would benefit us??
Thanks
Click to expand...
Click to collapse
It is mainly used by users - some may add - who've rooted their devices, - and ment as a low level for doing stuff that cannot be done via GUI (graphical user interface).
This is what you probably know as "hacking" - not necessarily for doing bad suff,
but for low level control of the device or for learning purposes.

Reduce shell code (and/or debug)

Could you give me a little hand to reduce this code and make it more bearable because they (codes) will be a series of consecutive actions, and in a single command line in Tasker.
What I want to do in short?
1. Compress a file (or folder)
2. Add a name to the final file
3. Apply compression to the generated file
4. Delete ONLY contents of the folder that ended compress
5. Move the file was created before to the empty folder
Here is the code:
Code:
cd /xxx && tar -cf xxx_%DATE.xxx "$$$" && gzip -x xxx_%DATE.xxx && cd "###" && rm -r * .* && cd /xxx && mv -f xxx_%DATE.rar.gz "€€€"
And this is the description that I will offer users who use it:
Code:
[cd /'xxx'] = path to backup folder (parent dir) ; ['xxx'_%DATE] = file name (no name spaces) ; ['$$$'] = folder with files to back up ; [gzip -'x'] = compression level (1-9) ; [%DATE.'xxx'] = files container (.zip/.rar/.tar) ; ['###'] = same as -> '$$$' ; ['€€€'] = same as -> '###' & '$$$'
Mmmm, I'm sure you have several questions, so I will try to answer all possible question you could ask:
- What is the path that you think to work on?
-> If possible, in the external memory (SD Card)
- Why did you use in all commands the '&&' concatenation?
-> Just because I don't want to run the following command if the above fails for X reason. Just for security.
- What the variable '% DATE' does in your generated files?
-> All the code you see above is part of a larger task that will be used to create backups of various things, in short: BACKING UP. Well I include that variable because I want Tasker to add to the file name the date when the backup was created.
- Why do you offer the ability of choose the container file extension?
-> At first I thought it would not be possible and that failure or something would occur, but as I tested it, nothing happened. So I offer users the ability to generate the container they want. And as the final file (.gz) after compression, you can easily open it, so...
- Why do you use the quotes in some parts of the code that refer to a directory to compress, or to dump the created contents (move)?
-> Not really would take, well at least that I've experienced. But I decided to added it because, in my case, I have folders which their names have spaces, and without adding those quotation marks ("...") I can not find the directory that want to access, I guess it can happen to other people.
- When you begun using the command to create file container, like moving file, why do you position yourself in the directory first and then do the action, rather than perform all in the same code?
-> This is what I've tried so far, but do not know why I couldn't. Every combination I tested: FAILED, then I decided to separate positioning directory commands of leading compression actions, moving files, etc.
Well, I think the rest of you get the idea of that or how it works, but if not, ask to me.

[SOLVED] Cannot change LMK minfree values with script in /magisk/.core/service.d

Dear Community, dear Developers outside..
I'm using Magisk 14.0 on a Redmi Note 4 Snapdragon and super satisfied with it.
I just want to make simple changes like changing the lowmemorykiller minfree parameters - just like an init.d script in Kernel Adiutor..
Most of the commands are effective - but some of them are not..
This is what I want to apply for example:
chmod 666 /sys/module/lowmemorykiller/parameters/minfree
chown root /sys/module/lowmemorykiller/parameters/minfree
echo '7283,14566,21849,28928,36415,43698' > /sys/module/lowmemorykiller/parameters/minfree
..but does not work..
But these, for example.. these are working just fine:
echo '30' > /proc/sys/vm/swappiness
echo '0' > /sys/module/lowmemorykiller/parameters/enable_adaptive_lmk
echo '80' > /proc/sys/vm/overcommit_ratio
echo '400' > /proc/sys/vm/vfs_cache_pressure
echo '2430' > /proc/sys/vm/extra_free_kbytes
echo '4096' > /proc/sys/kernel/random/write_wakeup_threshold
echo '1024' > /sys/block/mmcblk0/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk0/queue/iostats
echo '1' > /sys/block/mmcblk0/queue/add_random
echo '1024' > /sys/block/mmcblk1/queue/read_ahead_kb
echo '0' > /sys/block/mmcblk1/queue/iostats
echo '1' > /sys/block/mmcblk1/queue/add_random
swapoff /dev/block/zram0 > /dev/null 2>&1
echo '1' > /sys/block/zram0/reset
echo '0' > /sys/block/zram0/disksize
echo '1' > /sys/block/zram0/max_comp_streams
echo '524288000' > /sys/block/zram0/disksize
mkswap /dev/block/zram0 > /dev/null 2>&1
swapon /dev/block/zram0 > /dev/null 2>&1
echo '4096' > /proc/sys/kernel/random/read_wakeup_threshold
echo '4096' > /proc/sys/vm/min_free_kbytes
echo '0' > /proc/sys/vm/oom_kill_allocating_task
echo '90' > /proc/sys/vm/dirty_ratio
echo '70' > /proc/sys/vm/dirty_background_ratio
I do know that all I have to do is to put my script to one of these dirs - depending on when I want to run the scripts:
/magisk/.core/service.d
/magisk/.core/post-fs-data.d
But, as I mentioned - most of them has effect, some of them has no..
Any comment, any suggestion is more than appreciated.
Thank you!
[SOLVED] - solution is in post #5
Desperate bump..
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
@sheraro
https://github.com/topjohnwu/Magisk/blob/master/docs/README.MD
First of all: the solution for my issue was a simple sleep 30 in the services.sh to delay the start.. and I used an auxiliary file as well to make the changes (called from services.sh with 30sec delay, copied with the update-binary file directly, set permission to 0777 via config.sh) after that is all started working..
sheraro said:
I searched for help docs for service.d and post-fs-data.d but counldn't find them, can I ask you when each folder is executed, also does the scripts inside them must have .sh extension or not ?
I want to restart my systemui after boot complete, can you tell me if this script is ok ?
Code:
#!system/bin/sh
sleep 20
su
pkill -l TERM -f com.android.systemui
ps : the pkill command works fine after an "su" in terminal emulator
sorry for the offtopic !
Click to expand...
Click to collapse
So, second thing, @sheraro, I think you should delete the command su from your script because Magisk scripts are running as root anyway and if you issue su command it will start a shell with elevated privileges - an interactive shell, not what you want here, a sudo like command.. it works in the terminal because it is interactive but in the shell script if you start su it starts an interactive shell and it halts your script because it won't exit the shell you started.. and the next command will never run.. if you know what I mean.. but you don't need it anyway, because - as I mentioned - it is running as root anyway. +1: The syntax of the shebang is bad in your example, it is missing an exclamation mark. Can you re-test it like this:
Code:
#!/system/bin/sh
sleep 20
pkill -l TERM -f com.android.systemui
exit 0
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
crok.bic said:
.sh extension is not needed, the thing is: you have to set the correct permission in the config.sh like this:
Code:
set_permissions() {
# Default permissions, don't remove them
set_perm_recursive $MODPATH 0 0 0777 0777
[..omitted..]
Thing is: the files must have execute priv. and you can execute them like
Code:
$MODDIR/./desiredfilename
in the services.sh script.
Hope this helps.
Click to expand...
Click to collapse
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
sheraro said:
I'm just pasting my script in service.d only, set permissions manually to 0777, corrected !#/system typo, removed su command, but no luck...
Where's services.sh and config.sh ?
Click to expand...
Click to collapse
Reading your comment I think you are not developing a Magisk module, do you?
I do and this is why you have no idea where is config.sh, services.sh and the others I think.
If you just want to have some kind of "init.d script" support and run the script in your own phone *only* then your script should be in the folder /magisk/.core/service.d and it should have execute permission. That's all what you need - probably the sleep 20 is not enough, increase it to sleep 30 for instance.
If this is still not enough info I would suggest to read the Magisk documentation thoroughly (linked in post #4) and if you still stuck I suggest you to open your own thread, describe your problem thoroughly (what is your goal? what would you like to achive? how did you already try? what is happening but should not or not happening but you think it should happen? you know what I mean..) and ask the community. Probably you will be able to solve your issue in minutes/hours.
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
nicorg3221 said:
It seems that sleep will delay the run of other modules' service.sh. is there any solution that will not affect other module?
Click to expand...
Click to collapse
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
sheraro said:
I changed it to sleep 100, same problem, you're right I should create a new thread for this.
I have a theme installed that mimics oreo style, but the systemUI is not themed until it's restarted, so I thought about a script executed after boot, anyway thanks for your help
Click to expand...
Click to collapse
Pleased to help you - but honestly, if the only task you need is to kill and restart systemUI then I would do it via init.d script run by an app that mimics init.d scripting, or using a kernel that supports init.d scripts (if only you want to use that theme). It's just less complex for you I think, but honestly, a simple script file that has execute permission in /magisk/.core/services.d/ gives you 100% the same solution.
crok.bic said:
I don't experience this behavior - what you described is the post-fs-data behavior.
I did the trick with a separate ("auxiliary") file and tried to explain how in post #5 but let me try again:
- created a file in the module's common folder (I gave the name `tweak`)
- this file starts with a shebang (it's a script..) and continues with a sleep 30 then comes my commands..
- then copied the file from the module to the Magisk module directory into /magisk/$MODDIR with the module file META-INF/com/google/android/update-binary (I added it to the copy section, manually.. I know, I know, it should work automagically anyway, but did not work and I was fed up with the coding, so hardcoded it.. sorry)
- I set the default file permission to 0777 in config.sh (yes, 0777, this is loose AF but works.. and I don't really care, the file contains code that can make the device *better* and has no suid bit set, so there is only little to no room to harm anything..)
- then I included a call in my module's common/service.sh like $MODDIR/./tweak to start my script
- when the tweak script starts it will start with the sleep 30 so implements the delay.. BUT!
- Because services.sh files from the modules are called parallelly by Magisk (by default, by it's nature, by it's code.. you got it) my module does not delays others - but still has the delay.
Hope this helps.
Click to expand...
Click to collapse
I have my script in starting in .Core. Maybe that's the problem
nicorg3221 said:
I have my script in starting in .Core. Maybe that's the problem
Click to expand...
Click to collapse
..then it is in the wrong dir.. it is clearly described in the Magisk documentation.
I have researched a bit. I think you can use getprop sys.boot_completed to check if boot is completed. We should run init.d scripts after boot is completed instead of just wait for 30/100 seconds.
I place all my init.d scripts I want to run in /magisk/.core/service.d/init.d.
Then, I have a service.d script [exec_init_d.sh] in /magisk/.core/service.d. Magisk will run exec_init_d.sh when boot.
exec_init_d.sh will wait for sys.boot_completed and run all the files in /magisk/.core/service.d/init.d after boot completed
exec_init_d.sh
Code:
#!/system/bin/sh
# Please don't hardcode /magisk/modname/... ; instead, please use $MODDIR/...
# This will make your scripts compatible even if Magisk change its mount point in the future
MODDIR=${0%/*}
# This script will be executed in late_start service mode
# More info in the main Magisk thread
if [ "$1" != "1" ]; then
$0 1 &
log -p i -t Magisk "start new instance to let Magisk boot stages proceed"
exit
fi
#param
RUNLOG=0
RETRY_INTERVAL=5 #in seconds
MAX_RETRY=60
EXEC_WAIT=3 #in seconds
INIT_D_DIR=$MODDIR/init.d
LOG_PATH=$MODDIR/debug.log
#init
retry=${MAX_RETRY}
#wait for boot completed
log -p i -t Magisk "wait for boot completed"
while (("$retry" > "0")) && [ "$(getprop sys.boot_completed)" != "1" ]; do
sleep ${RETRY_INTERVAL}
((retry--))
done
if (("$retry" == "0")); then
log -p i -t Magisk "boot not completed within maximum number of retry"
else
log -p i -t Magisk "boot completed"
fi
sleep ${EXEC_WAIT}
log -p i -t Magisk "init.d execution started from ${INIT_D_DIR}"
if (("${RUNLOG}" == "1")); then
/data/magisk/busybox run-parts $INIT_D_DIR &> $LOG_PATH
log -p i -t Magisk "init.d execution output written to $LOG_PATH"
else
/data/magisk/busybox run-parts $INIT_D_DIR
fi
log -p i -t Magisk "init.d execution completed"

Categories

Resources