[ZIP] Dynamic automated build.prop editing

What about an app? See post #90 for more infos, let me know what you think!


  • Total voters
    141

kl3

Senior Member
Sep 9, 2013
145
175
0
Hey,

since I'm flashing nightlies on a regular basis and also want to use my own custom /system/build.prop file, there are a few ways to accomplish both things as easy as possible:

Backing up /system/build.prop through a script in /system/addon.d
Flashing my own file using a zip after every update
Restoring previous build.prop using a Editor app and reboot
Manually change or add every desired entry and reboot

For most of you one of these ways should absolutely do the trick, but my problem was either things like build version, date, etc. got stuck at my custom file's one or I had to reboot after manually updating it, which got really annoying after several times.

So I decided to create my own flashable zip which works as follows:

Somewhere on the device is a simple text file in which are all those entries that shall be changed,added to or removed from /system/build.prop (In my case it's /sdcard/tweak.prop)
After mounting /system and /data (not if they are already) and setting write permissions to /system/build.prop the zip extracts a shell script to /tmp/tweakprop.sh
It This script scans the text file (aborts if not found) and looks for changed, new or unwanted entries in /system/build.prop in order to apply them. Changed entries will be overridden, new ones will be added, unwanted get removed and entries existing in /system/build.prop but not in your personal file will be ignored
When tweaking is done, it just removes /tmp/tweakprop.sh and unmounts /system and /data (only if they weren't mounted before) and reverts /system/build.prop's permissions to rw-r--r--

-> (See content of example.txt for more detailed examples and syntax!)

Using this method, you can not only forget about manually updating versions and/or lame reboots after updates for changes to take effect, but also edit your personal text file at any time without root rights beeing required. Once set up to be flashed after every update, your /system/build.prop is always tweaked as you wish and looks like a stock one (ROM version, etc. under About Phone).

The zip flashes well on all recoveries. Make sure your tweak.prop file ends with an empty line, otherwise the last line will be ignored!

I hope some of you can use this zip, it's free to modify. If you have any suggestions, let me know.

This project has been moved to a git repo at https://notabug.org/kl3/tweakprop. Please refer to it in the future to get updates as this is much easier for me to maintain. Upcoming changelog can be found here.
 
Last edited:

kl3

Senior Member
Sep 9, 2013
145
175
0
Changelog

Changelog
version 0.1:

  • initial release


version 0.2:

  • ignore lines in personal file not matching a valid entry pattern (someVAR=someVAL) to not mess up /system/build.prop and support personal structuring inside the file like "# media tweaks #", "# dalvik section #", etc.
  • code cleaned up


version 0.2.1:

  • typo fixed in line 24 of tweakprop.sh so the if-statement asks for the correct file (thanks to the_pirate_predator)


version 0.3:

  • changed the while-loop to get it's input directly from sed, which makes a second buffer file obsolete


version 0.3.5:

  • example.txt provided as tweak.prop template
  • ignore lines beginning with # or being empty


version 0.4:

  • instead of a fixed path, the personal file gets searched on internal storage (file name can be set in the script) so you can put your file anywhere - no more problems with /sdcard/ or /sdcard/0/ on different devices
  • personal file must not be empty, otherwise script aborts#
  • only override really different entry values in order to prevent "... value of someVAR overridden" spam in recovery log


version 0.4.5:

  • fixed last line of personal file being ignored due to deleting all empty lines before
  • speed up search for personal file, now looking on internal storage and even on external SD card if nothing was found before (ext. SD neither gets checked if present, nor mounted or unmounted, just trying to search on it silently)


version 0.4.5a:

  • same as 0.4.5a, but personal file is inside the zip and gets extracted to /tmp/tweak.prop, no need to have one on the internal storage


version 0.4.6(a):

  • output not shown in TWRP fixed, now works as it should


version 0.5:


  • code cleanup: everything's now in the update-binary, resulting in much less code and faster execution time
  • output to recovery should now work on all device-recovery combinations


version 0.5.1:


  • lines beginning with ! will be removed globally
  • little code-cleanup


version 0.5.2
:


  • lines beginning with @ will append the string after | to values of existent entries
  • slight changes in code structure


version 0.5.3
:


  • lines beginning with $ will change the value to the string after | only if the entry already exists, hence $telephony.lteCdmaDevice|1 is nothing but a more explicit approach of telephony.lteCdmaDevice=1, as the first one will only make changes but no new entries


version 0.5.4
:


  • the build.prop file can now be backed up before editing using a BACKUP= line, see example.txt for details
  • tiny bug fixed


version 0.5.4a
:


  • tweak.prop file (example.txt) is included, no personal file on your device's storage is used. Edit the zip's content before flashing!


version 0.5.9(a)
:


  • Error handling fixed, script properly exits now if anything failes and won't make further changes
  • More verbose output
  • Date and tweak.prop version added to backup files to keep track of them
  • Special characters like / are now escaped and handled correctly by sed
  • Slight changes in coding style as it's good practise
 
Last edited:

jonwgee

Senior Member
Apr 26, 2009
77
22
0
Dekalb
What should my text file look like if I just want to add one line of text at the end of my build.prop? For example,
qemu.hw.mainkeys=0
to activate softkeys on a device with capacitive buttons?
Thanks

Sent from my XT912 using Tapatalk
 
T

the_pirate_predator

Guest
Need some information

I need explanation for the following lines of code.
Code:
## your personal file with tweaks and custom entries/values
tweak=/sdcard/0/tweak.prop
## abort execution if $tweaks not found
if [ ! -e $tweaks ]
then
	ui_print "ERROR: Personal file not found. No changes were made."
	ui_print "Script aborted. Check file path and flash again."
	exit 0
fi

## read only lines matching any valid entry pattern (someVAR=someVAL), e.g.
## net.bt.name=Android, omni.device=n7100, url.legal=http://www ...
sed '/.*=.*/!d' $tweak > /tmp/tweak.prop
tweaks=/tmp/tweak.prop
You are giving a condition loop without even declaring the variable "tweaks" at first. You have declared only after the loop ends. Then that means, the code in the loop never executes. I think this is a small mistake you did with the code. Make sure you correct those.

But else, a great work!! :good: :good:
 
Last edited:

kl3

Senior Member
Sep 9, 2013
145
175
0
What should my text file look like if I just want to add one line of text at the end of my build.prop? For example,
qemu.hw.mainkeys=0
to activate softkeys on a device with capacitive buttons?
Just a simple text file containing your mentioned line. Any other empty or non-entry lines will be ignored by my script anyway.

I need explanation for the following lines of code.
Code:
## your personal file with tweaks and custom entries/values
tweak=/sdcard/0/tweak.prop
## abort execution if $tweaks not found
if [ ! -e $tweaks ]
then
    ui_print "ERROR: Personal file not found. No changes were made."
    ui_print "Script aborted. Check file path and flash again."
    exit 0
fi

## read only lines matching any valid entry pattern (someVAR=someVAL), e.g.
## net.bt.name=Android, omni.device=n7100, url.legal=http://www ...
sed '/.*=.*/!d' $tweak > /tmp/tweak.prop
tweaks=/tmp/tweak.prop
You are giving a condition loop without even declaring the variable "tweaks" at first. You have declared only after the loop ends. Then that means, the code in the loop never executes. I think this is a small mistake you did with the code. Make sure you correct those.

But else, a great work!! :good: :good:
You're right. It's a typo, I'm correcting it now. Thanks for your advice.

Sorry, but stick to one variable, "tweak", or "tweaks".

Otherwise, its a very simple, yet efficient algorithm. :good:
I use a second buffer file that is a cleaned version of the original one. If I find a smarter way, I will.
 

oguh

Senior Member
Nov 26, 2008
79
4
28
Lisboa
I was searching for something like this for ages.

But i have a nob question! lol

I need to create a text file with all the lines i want to add to my built.prop file, so where I put the text file? And i have to give a certain name to that file or any name will do?

Hugo
 

kl3

Senior Member
Sep 9, 2013
145
175
0
I need to create a text file with all the lines i want to add to my built.prop file, so where I put the text file? And i have to give a certain name to that file or any name will do?
My script searches for a file called tweak.prop located at your internal storage (storage/emulated/0/tweak.prop or sdcard/tweak.prop or sdcard/0/tweak.prop), but you can freely change the line
PHP:
tweak=/sdcard/0/tweak.prop
to any path you want your personal file to be.
 

oguh

Senior Member
Nov 26, 2008
79
4
28
Lisboa
My script searches for a file called tweak.prop located at your internal storage (storage/emulated/0/tweak.prop or sdcard/tweak.prop or sdcard/0/tweak.prop), but you can freely change the line
PHP:
tweak=/sdcard/0/tweak.prop
to any path you want your personal file to be.
Thx for the quick response, and for your great work.

hugo
 

bnbagiz

Senior Member
Nov 27, 2011
110
19
48
Sorry but i don't get it.
i need to create a txt file called tweak.prop and place it where i want, for example /sdcard/tweak.prop
after extracting the tweakprop-0.3.zip for editing the line /tmp/tweakprop.sh

Code:
## your personal file with tweaks and custom entries/values
tweak=/sdcard/tweak.prop
zipping meta-inf and tmp folder and finally flashing this zip.. am i doing something wrong ?
because it takes no changes.

got this line in tweak.prop at /sdcard/tweak.prop

Code:
ro.sf.lcd_density=400
sorry, i really dont get it.
 
Last edited:

kl3

Senior Member
Sep 9, 2013
145
175
0
Sorry but i don't get it.
i need to create a txt file called tweak.prop and place it where i want, for example /sdcard/tweak.prop
after extracting the tweakprop-0.3.zip for editing the line /tmp/tweakprop.sh

Code:
## your personal file with tweaks and custom entries/values
tweak=/sdcard/tweak.prop
zipping meta-inf and tmp folder and finally flashing this zip.. am i doing something wrong ?
because it takes no changes.
As my script already shows, changing the path to /sdcard/0/tweak.prop again should do the trick.
 
Last edited:

sauron82

Senior Member
Jun 12, 2012
624
178
0
Toronto
I just want to change my DPI with this. What do I need to change in your default tweak.prop to be able to do that?

Click thanks if I helped you.
Sent from my SM-N900W8 using XDA Premium mobile app
 

bnbagiz

Senior Member
Nov 27, 2011
110
19
48
Code:
As my script already shows, changing the path to /sdcard/0/tweak.prop again should do the trick.
did not work ! :/ you mean changing the path for the tweak.prop in the unzipped tweakprop.sh in /tmp/, aren't you ?

Code:
build=/system/build.prop
## your personal file with tweaks and custom entries/values
tweak=/sdcard/0/tweak.prop


---------- Post added at 02:41 PM ---------- Previous post was at 02:34 PM ----------

I just want to change my DPI with this. What do I need to change in your default tweak.prop to be able to do that?

Click thanks if I helped you.
Sent from my SM-N900W8 using XDA Premium mobile app
that is what i am trying to do
you need to change the line

Code:
ro.sf.lcd_density="value you like to have, i.e. 400"
 
Last edited:

kl3

Senior Member
Sep 9, 2013
145
175
0
Code:
did not work ! :/ you mean changing the path for the tweak.prop in the unzipped tweakprop.sh in /tmp/, aren't you ?

Code:
build=/system/build.prop
## your personal file with tweaks and custom entries/values
tweak=/sdcard/0/tweak.prop

Yes, that's what I meant. Then just try any other path. I guess the internal storage's path is a device specific thing. Which device do you? I would try locating your personal file at /system as this path exists on all devices/ROMs.
 

bnbagiz

Senior Member
Nov 27, 2011
110
19
48
Yes, that's what I meant. Then just try any other path. I guess the internal storage's path is a device specific thing. Which device do you? I would try locating your personal file at /system as this path exists on all devices/ROMs.
I am using a LG G2 Intern. D802
PAC-Man ROM (but thing thats irrelevant)
so if i place my tweak.prop in /system/ i need to edit the path in tweakprop.sh right ?

edit:
personal file is in /system/tweak.prop
editting tweakprop.sh line to
/system/tweak.prop
does not work :( don't get it .. sounds so simple, actually it is, but i don't know what i am doing wrong :(
 
Last edited:

sauron82

Senior Member
Jun 12, 2012
624
178
0
Toronto
that is what i am trying to do you need to change the line

Code:
ro.sf.lcd_density="value you like to have, i.e. 400"
I know that, but where do I put it in the provided tweak.prop? What do I remove from the provided tweak.prop so that's the only change? I really don't know what any of this code actually means. Thanks to the OP for providing this, but instructions aren't very clear.

Click thanks if I helped you.
Sent from my SM-N900W8 using XDA Premium mobile app
 

kl3

Senior Member
Sep 9, 2013
145
175
0
edit:
personal file is in /system/tweak.prop
editting tweakprop.sh line to
/system/tweak.prop
does not work :( don't get it .. sounds so simple, actually it is, but i don't know what i am doing wrong :(
Hm.. Which recovery? Maybe it's a problem with the updater-script doesn't get executed correctly. Sadly, I have no possibilities to test those scenarios.

I know that, but where do I put it in the provided tweak.prop? What do I remove from the provided tweak.prop so that's the only change? I really don't know what any of this code actually means. Thanks to the OP for providing this, but instructions aren't very clear.
I didn't provide any personal file. If you only want to change this line, create a file called tweak.prop containing only this line and place it right on your internal storage.

Sent from my GT-N7100 using Tapatalk
 
  • Like
Reactions: sauron82

my95z34

Senior Member
Apr 18, 2007
728
400
0
Wayne MI
I am using a LG G2 Intern. D802
PAC-Man ROM (but thing thats irrelevant)
so if i place my tweak.prop in /system/ i need to edit the path in tweakprop.sh right ?

edit:
personal file is in /system/tweak.prop
editting tweakprop.sh line to
/system/tweak.prop
does not work :( don't get it .. sounds so simple, actually it is, but i don't know what i am doing wrong :(
If you put it in /system/ it'll get erased when you flash a new nightly anyways, as most .zip scripts wipe the /system partition... So... it would be best to keep it on the SD card.
 
  • Like
Reactions: kl3