Working with su.d - SuperSU

Hi @Chainfire,
So, a while ago, I posted in the Liveboot thread inquiring as to how I'd go about incorporating liveboot into a ROM so that it could just run on first boot.
Your instructions were to chmod 0770 both the files and folders in su.d, and it should work:
If /system/su.d/0000liveboot.script exists (chmod 0644, not 0700 like other files in /system/su.d/ !), this script will be run instead of logcat and dmesg, and its output will be shown in white (stdout) and red (stderr).
Click to expand...
Click to collapse
However, I tried this, and never got it to work, and essentially moved on to other stuff for a while.
Today, I tried to revisit it, and while I was at it, replace my current init.d stuff with su.d.
So, I created the folder in /system which gets copied with t he rest of the ROM on install. I'm setting folder and file permissions to 0700, owner and group to root, SE context to ubject_r:system_file:s0, which, is exactly the same as what I'm seeing on 0000liveboot when I look at it's info.
This leaves two questions.
One, the above quote you say to set it to 0644, but liveboot itself sets it to 0700 when it installs it.
Two, what is the trick to getting other scripts to work? In your "How to SU" guide, you mention this:
From versions 2.22 onwards, after the policies have been patched and the daemon is ready to go, all executables in the /system/su.d/ directory are executed (chmod 0700 both the directoy and the scripts), followed by setprop supolicy.loaded 1. This is akin to /system/(etc/)init.d/, though execution of those scripts is both kernel-dependent and they may run before the SELinux are patches and/or su is available.
Click to expand...
Click to collapse
Setprop supolicy.loaded. Where am I supposed to do that? You say execution of those scripts is kernel-dependent - you're referring to init.d, yes? So, again, what am I missing?
This is 5.0.1 GPE for M8VZW. I have selinux set to permissive via boot image in init.rc, and verify that "getenforce" returns "permissive" from shell.
Any help you could lend would be greatly appreciated - which is also why I'm posting this as a thread...because su.d sounds like an awesome idea, and I bet more devs would like to start using this method over init.d.
Thank!

digitalhigh said:
One, the above quote you say to set it to 0644, but liveboot itself sets it to 0700 when it installs it.
Click to expand...
Click to collapse
liveboot sets the script that gets run by SuperSU to 0700. The script which I said to be set 0644 is a different script, and is not executed by SuperSU, but by liveboot.
Setprop supolicy.loaded. Where am I supposed to do that?
Click to expand...
Click to collapse
You don't. SuperSU sets this. Kernel developers can hook this event to run their own code.
You say execution of those scripts is kernel-dependent - you're referring to init.d, yes?
Click to expand...
Click to collapse
Yes, not all kernels support init.d, and init.d stuff generally runs before SuperSU patches policies, so there's no guarantees about any SELinux state.
So, again, what am I missing?
Click to expand...
Click to collapse
I don't know. Make sure you are running the latest version of SuperSU (2.46 at the time of writing). Make sure /system/su.d is chmod 0700. Make sure the scripts you want to run are also chmod 0700 and #!'d to a working shell executable. Keep in mind that the scripts are called one-by-one, in a blocking way. So if a script never exits, the next script isn't run.

Deleted

Say I have SU v2.62. I have 2 files in my /system/su.d folder. The first file doesn't have an exit, neither does the second. The second file DOES get executed as it sets selinux to permissive at boot as directed. First file is 0700 (text file), second is 0755 (a .sh file).
Now, I want to take an init.d setprop script and try it via su.d.
1) Do the other files need exit commands?
2) What should the third file (setprop file) be set to, 0755? A .sh or text file?
3) Are the other two set to the correct chmod?
Thank you for any input!
EDIT: Left it as text, and 0755. No exits, and it worked?

Using su.d to disable doze
Is it possible to use su.d in order to load a script that disables Android doze mode?
I'm trying to run this script:
Code:
#!/system/bin/sh
dumpsys deviceidle disable
Script file is located in root\su\su.d
Permissions are set to 0700.
However, script is not loaded automatically during the boot, because if I run the script manually in SManager I get a response Idle mode disabled, which means su.d script wasn't loaded.
Currenlty I use SManager to execute this doze disabling script automatically on every boot, but I wonder why wouldn't the same script work using su.d?
I use another su.d script that disables LED back-lights of hardware navigation buttons and the script works just fine.
I'm using SuperSU v2.82
Thanks for your input.

Related

[MOD][P905] enable init.d support for stock rom LTE QUALCOMM ONLY!

At first, I am not liable for any harm or damage that may happen to your device!
If you have su and didn't trigger knox, I CANNOT guarantee that running this script won't cause 0x1!
Requirements:
1) P905/viennalte/Qualcomm based model ONLY (won't work on Exynos devices. MIGHT work on other Qualcomm LTE deices from Note Pro and Tab Pro series - feel free to repost but give credits!) running 4.4.2 stock;
2) root access with SuperSU (using cf-root - credits to chainfire);
3) busybox installed (I do recommend this paid installer: https://play.google.com/store/apps/details?id=stericson.busybox.donate , MOST PROBABLY free version will be more than enough, too, but I haven't tested it as I have license...)
4) Android Terminal Emulator installed ( free at: https://play.google.com/store/apps/details?id=jackpal.androidterm )
Installation:
1) download file init.d_qcom.sh using below link and put it in the root of internal memory (so it will be placed in: /sdcard/init.d_qcom.sh)
2) run Android Terminal Emulator
3) at command line, type:
Code:
su -c /sdcard/init.d_qcom.sh
(give it an access if requested)
4) voila.
Additional info for advanced users:
1) scripts in /system/etc/init.d shall be root:root 755 (and NOT 777 as stated in A LOT of sources, thou has to be a heavy idiot to give write access for system files to "world"...)
2) init.d is handled from one of the /system/etc qualcomm additional scripts as it refused to work using regular install-recovery.sh method...
3) scripts are triggered paralelly but I am using different method (find/nohup/su combination...), as this damn rom refused to simply execute "run-parts" applet...
4) init.d permission helper script included (just put your scripts in init.d and they'll receive proper permissions on reboot)
Download:
http://www12.zippyshare.com/v/32009778/file.html
Nice to see some developement for this tab!
Anyway to port it to exynos? :fingers-crossed:
prohackerbro said:
Nice to see some developement for this tab!
Anyway to port it to exynos? :fingers-crossed:
Click to expand...
Click to collapse
+1
sent from my amazing NotePro 12.2 via Tapatalk
Criminal23 said:
+1
sent from my amazing NotePro 12.2 via Tapatalk
Click to expand...
Click to collapse
I might try, however I do not own the device and the file structure is completely different.. Can you first enter via Android Terminal:
Code:
su
ls -l / >/sdcard/content.txt
ls -l /system/etc >>/sdcard/content.txt
And post the /sdcard/content.txt file which will be created (or its contents only)?
Also, i would be glad if you copy every *.rc file from root of filesystem to a dir , compress it to one file and post it too
esgie said:
I might try, however I do not own the device and the file structure is completely different.. Can you first enter via Android Terminal:
Code:
su
ls -l / >/sdcard/content.txt
ls -l /system/etc >>/sdcard/content.txt
And post the /sdcard/content.txt file which will be created (or its contents only)?
Also, i would be glad if you copy every *.rc file from root of filesystem to a dir , compress it to one file and post it too
Click to expand...
Click to collapse
Here you are
Criminal23
Criminal23 said:
Here you are
Criminal23
Click to expand...
Click to collapse
Criminal23 said:
Here you are
Criminal23
Click to expand...
Click to collapse
After looking into sent (and posted) files, I have to say that the init process in our devices are ABSOLUTELY different.
Qualcomm version triggers about 7-8 scripts lying in /system, which are provided by Qualcomm, which are pointed in configuring all the hardware provided with their chipset - in addition to init.???.rc files from the kernel. The clue was to add init.d execution command at the very end of one of those scripts (and that is done automatically with script attached in the first post).
Exynos version does not launch (almost - see below) ANY external script during the boot. Whole process seems to be performed by rc files lying in root of the filesystem, which are embedded in kernel's ramdisk and any edits won't preserve the reboot, so it cannot be done without repacking the kernel and that is something far more troublesome to perform without device in hand, without the firmware on disk and without a plenty of time.
BUT
it still runs /system/etc/install-recovery.sh which is an Android standard and which genuine purpose was to reflash recovery back to stock if a custom one was detected. Now, it is sometimes utlized to run somehing at boot, especially: it is used by SuperSu (in addition with other methods) to run its daemon. The problem is that kitkat introduced enforcing SELinux, that Samsung SELinux policy adds special security context for this file, that install-recovery.sh won't be launched if the file has no proper security label - and that while installing SuperSu, the context is set in a different way and in final, install-recovery.sh isn't launched, until we restore /system context, and restoring context to the system ends with... non working su, so we have to flash it again, breaking install-recovery.sh context... Did you get it? - it's a loop as fixing one thing breaks the second, and fix to the second breaks the first That is why on my qualcomm device i have chosen another script file to run the init.d - and as you don't have any other script except install-recovery.sh, I don't know where it might be put...
BUT also I cannot guarantee that the behavior above is not qualcomm-exclusive and it is possible that on exynos device everything will work without problem!
That's why you may want to try standard method for all the devices (term init - uses install-recovery.sh method described above):
http://forum.xda-developers.com/showthread.php?t=1933849
and if it won't work then you have to wait for - at least - repacked kernel with init.d support embedded into init.rc files or run your script by an external app, ie SManager. Just be aware that even if term init work, it may stop working every time you flash SuperSu, so remember to run the script again then.
Sorry for not being too helpful.

[Magisk][Module][Deprecated] Unified Hosts Adblocker

This mod has since been discontinued in favor of Adaway. Read on for information on how to use Unified Hosts with Adaway
What are Unified Host Files?
Unified host files combine many reputable sources into a single hosts file (with duplicates removed). Some examples include adaway, mvps, yoyo.org, and malware domain list (see Steven Black's page here for a complete list).
Adaway Installation for Magisk:
Adaway version 4.x now works properly with magisk systemless hosts. To enable it, just install the latest version from here (the main xda thread for it hasn't been updated for it yet). Then go to Preferences -> Enable systemless mode. This automatically enables the Systemless hosts option in magisk manager so no need to bother with that. Then use the app as normal.
How to Add Unified Hosts to Adaway:
In the adaway app, go to Preferences -> Redirection IP (NOT Allow Redirects). Change the value to 0.0.0.0. Read the readme on Steven Black's GitHub linked above for why.
Then go to Hosts Sources. Then add the url of the unified hosts you want (ONLY CHOOSE 1):
Master: https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
Master+FakeNews: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews/hosts
Master+Gambling: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling/hosts
Master+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn/hosts
Master+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/social/hosts
Master+FakeNews+Gambling: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts
Master+FakeNews+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn/hosts
Master+FakeNews+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-social/hosts
Master+Gambling+Porn: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn/hosts
Master+Gambling+Social https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-social/hosts
Master+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/porn-social/hosts
Master+Fakenews+Gambling+Porn (This is the one I use): https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn/hosts
Master+Fakenews+Gambling+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social/hosts
Master+Fakenews+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-porn-social/hosts
Master+Gambling+Porn+Social: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/gambling-porn-social/hosts
Master+Fakenews+Gambling+Porn+social: https://raw.githubusercontent.com/S...lternates/fakenews-gambling-porn-social/hosts
You can then uncheck the host sources already added by default to adaway since they're included in unified hosts sources already
**Note that the 'Social' filter does exactly what you think: blocks social networks. So if you use any kind of social networking, DO NOT CHOOSE THIS ANY SOURCE WITH THIS IN IT**
Using a APN that uses a proxy server or a subsidiary provider and unable to get adblocking working? See here for a fix
Original Mod Information:
Description
Blocks ads by using Steven Black's Unified Hosts
Comes with a small utility based off of LarappsOfDongle's RP modular host module that allows you to choose which kind of host file you want (adware/malware, fakenews, gambling, porn, social, or any combination)
Installation
Go to Settings in Magisk Manager and enable 'Systemless Hosts'
Flash module
Open terminal and type:
Code:
su
hosts
Then follow the prompts to install the host file of your choice.
OR
- Open terminal and type:
Code:
su -c hosts arg1 arg2 arg3
- The script will apply your arguments all at once and close. Useful for automation purposes
- For example: `su -c hosts m wr b`
- Script will apply the master filter, then your regex whitelist, then your blacklist
Updating Hosts:
Just run the hosts file again in terminal and it'll overwrite the old one
Note: The script will now notify you to say if you need to update or not at the top of it
Disabling Host Mod:
Just toggle the enable systemless hosts option in magisk manager
Whitelist Instructions:
Create an empty file on sdcard card called "whitelist"
Either add exact lines you want remove to it -> Run hosts script and choose whitelist option
For example:
Code:
0.0.0.0 facebook.com
Will unblock facebook.com
Or add regex for lines you want removed -> Run hosts script and choose whitelist regex option
For example:
Code:
.*facebook.*
Will unblock all domains with "facebook" in them
Blacklist Instructions:
Create an empty file on sdcard card called "blacklist"
Add exact lines you want to remove it (do not include the 0.0.0.0 -> so for example: "facebook.com")
Run hosts script and choose blacklist option
For example:
Code:
google-analytics.com
Will block the google-analytics.com domain (it will add the entry "0.0.0.0 google-analytics.com" to the hosts file - note the lack of the 0's here. The script takes care of it automatically for the blacklist feature)
To Remove Whitelist:
Just run hosts script and reinstall host file of choice
Latest Magisk Version Compatibility:
15.x
Source
Can't Boot?
Try rebooting into the bootloader, then boot into system. Thanks @rignfool for the tip
Bonus!
I made a quick automate flow to update the hosts file. Just import it, add a shortcut to your home screen, and you can update it in one click
Just change the 2nd block to whatever options you want
@Didgeridoohan made a tasker profile here for any who use tasker: https://forum.xda-developers.com/showpost.php?p=73369050&postcount=451
Download
How does this differ from AdAway?
serubin323 said:
How does this differ from AdAway?
Click to expand...
Click to collapse
The unified hosts file combine many sources including AdAway, mvps, malware domains, and more. Check out steve black's page in the op for a full list.
Also, for some reason, adaway wouldn't detect the systemless hosts file for me so i had to set a custom path and symlink it
Updated module for latest magisk manager update (required changes to the readme). Doesn't change the functionality of the module at all so if you're in 1.1, there's no need to upgrade since these readme changes will only be reflected in magisk manager once this module is approved into the repo.
Damnit... Wrong thread...
OK...
Syntax...
su -c hosts ______
Please fill in the blank...
rignfool said:
Damnit... Wrong thread...
OK...
Syntax...
su -c hosts ______
Please fill in the blank...
Click to expand...
Click to collapse
Code:
su
Give root permissions
Code:
hosts
Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
Code:
fg
The reason for not including the master (adware/malware) in the arguments is that it's already included by default in each host file. So the fakenews host file is actually master + fakenews. It's how steven set it up so I have no control over it (and who wouldn't want the malware block anyways)
Found a typo in the directions for the host file. Once again doesn't effect functionality at all but does eliminate confusion so uploaded fixed version (sorry)
Zackptg5 said:
Give root permissions
Program will prompt for input. For example, if you want malware/adware (master) + fakenews + gambling, you're input would be:
Click to expand...
Click to collapse
I'm looking to execute as a one line shell command with tasker...
So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...
Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...
rignfool said:
I'm looking to execute as a one line shell command with tasker...
So I'm using 'su -c' cuz SU detection in tasker with magisksu is broken...
Then hosts... But I want to run with an argument so I don't need to interact with the script... Just have it update the hosts file...
Click to expand...
Click to collapse
I've never used tasker (use automate instead). Perhaps
su -c; hosts; sleep 1; fgps; sleep 2; q
Not sure if the sleep command works for tasker (linux thing) but if there's a way to have it wait a half a second or so before inputting the next command, and then waiting 2 seconds or so to quit after the hosts is applied (not sure on the time, just guessing).
Edit, just saw you didn't want to deal with the script. The 'hosts' command is the script. If you look my source for the hosts script, it lists each url for the file and what it does. So all of the terminal code for fgps would be:
Code:
su -c
cd /magisk/.core
wget -O hosts --no-check-certificate https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-porn-social/hosts
This will replace the systemless hosts file with the one you want. Note you will at least need the wget portion of the module (system/bin) since it's not included in most roms
v1.3 update: Noticed that the disable option was broken so I removed it since it's not needed (see OP for disable instructions)
Using ze551ml, after rebooting, module disappeared. I can't find hosts command anywhere.
danzel said:
Using ze551ml, after rebooting, module disappeared. I can't find hosts command anywhere.
Click to expand...
Click to collapse
Does magisk manager say root is enabled? There's been an ongoing issue where root will disappear and so all modules will disappear as well. This isn't a module issue but a magisk issue
Automating hosts update?
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
The menu is part of the command line. I don't have tasker however, maybe this post will help: https://forum.xda-developers.com/showpost.php?p=71117156&postcount=9
You can circumvent running the script completely and just wget your host of choice. In that post, I have a link to the source for the hosts file with all of the urls. For fg for example, it would be: https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling/hosts
Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
As @Zackptg5 says, to automate with Tasker it's easier to just circumvent the script altogether...
I have a Tasker profile set up to fetch the hosts file directly from Steven Blacks GitHub and save it to /magisk/.core/hosts. I couldn't get wget to work properly with Taskers Run Shell, so I used the HTTP Get instead to fetch it to /sdcard and then Run Shell to move it to /magisk/.core/hosts (and to remove it from /sdcard afterwards).
Is there a possibility of whitelists?
ChronoReverse said:
Is there a possibility of whitelists?
Click to expand...
Click to collapse
In theory, you shouldn't need a white list with these hosts files. I chose them because they are gone over with a fine tooth comb so you shouldn't have any issues. However, when I get on spring break, I could attempt to add a whitelist option to the script. I was thinking the easiest way to do this would be to read a text file (would be a blank one in the module folder by default but is editable the uses to add whatever) and remove any matches from the host file. Have any better ideas to implement this? I have no experience with GUI development and that would add unnecessary overhead anyways
Does this module work currently? I disabled adaway and enabled this but it's not blocking ads that adaway blocks.
Testcase: root check by Jrummy
Adaway blocks the in app ads. This module does not
EDIT: apparently I can't read... Lol. Followed the Op and now it works great!
Neat module. It's working great! Thanks for sharing it!
Yom said:
Hi Zack!
Love your module, thank you!
Is there a way I can update with FG running a shell command from Tasker?
When I try
Code:
echo fg|hosts
it does download the fg file, but then it infinitely loops and never quits, until I send a CTRL-C to the terminal.
Could you please make it so hosts accepts arguments from the command line, instead of a menu?
Thank you!
Click to expand...
Click to collapse
I have a profile set up to do this every 12 hours. If you still need it, I updated it to use your preferred settings and exported it. All you need to do is import it in Tasker (long-press Profiles header) and turn it on.

[Q] How to change a build.prop value using resetprop

Hello guys. I'm trying to make some modifications in my build.prop using magisk's systemless interface. In a module, I saw that resetprop can add lines in build.prop, but, I need to change a specific line in build.prop and resetprop in a module intercafe can't do that (or can, I don't know ). I was thinking in creating a script using su + resetprop to delete and include again, and I'll put in a .sh file inside /magisk/.core/service.d/ to run in every boot.
Code:
su
resetprop --delete [my build.prop line]
But I don't know to to include a line using this interface (script in terminal).
So, I need you, guys haha
Just put whatever resetprop commands you want inside a file, put that file in service.d and give it execution permissions (755). You don't need "su" in there... It's Magisk executing those scripts and it already has escalated privileges.
If it doesn't work, try putting the file in post-fs-data.d instead.
To do this with a module, simply put your commands inside the service.sh file (or post_fs_data.sh) in the common folder.
https://github.com/garethwza/TheFla...mmit/25fb6a451a4d5280c26dbd67f4c5dfad7a3f20fc how to do this with resetprop? resetprop is binary here. how to make it?
Didgeridoohan said:
Just put whatever resetprop commands you want inside a file, put that file in service.d and give it execution permissions (755). You don't need "su" in there... It's Magisk executing those scripts and it already has escalated privileges.
If it doesn't work, try putting the file in post-fs-data.d instead.
To do this with a module, simply put your commands inside the service.sh file (or post_fs_data.sh) in the common folder.
Click to expand...
Click to collapse

[MODULE HELP] How to execute a script only once when module is installed/uninstalled?

The question title can't be much longer but I basically need to execute a script only once when each of the following events happen:
Module is installed.
Module is uninstalled.
Module is enabled.
Module is disabled.
In other words:
When the user first installs my module, I need to execute a script just once.
If the user eventually disables the module, I need to execute the same script again just once.
If the user eventually re-enables the module, I need to execute the same script again just once.
When the user decides to uninstall my module, I need to execute a script just once.
That script is basically removing a particular app's dalvik cache (rm -rf /data/dalvik-cache/<(arm|arm64)>/<app_specific_folder>), and user data (rm -rf /data/data/<package_name>).
I need some pointers on how to do this properly for those 4 events mentioned above and in a way compatible with most devices (for the record, I'm only supporting Nougat and above, if that's relevant).
Installation is easy. Make a function with your script in config.sh and call that from update-binary. Also make sure to let the module install a boot script (post-fs-data.d or service.d, depends on what you want to do) that takes care of the rest for you.
Whenever a module is disabled, there'll be a file named disable in the module folder, so you can let the boot script check for that and then run whatever code you need for the "module disabled" scenario. If you also let that code add a check file to the module folder you can let the code only run once. If both the disable and check files are present, don't run the code...
If the module then is enabled again, the disable file will be deleted. In that case you'll only have the check file, which will mean you should then run the "module enabled" code (which should also delete the check file, of course).
Also let the boot script check for the module folder. If it isn't found it means the module has been uninstalled and you can safely run your "module uninstalled" scenario, do some cleanup, and then let the boot script uninstall itself.
That should work...
There are several modules that do something similar, my MagiskHide Props Config is one of them. Look around for more examples.
I see what you mean but I need to test my code with logging to make sure I'm doing things correctly. What's the best way for me to print to logcat from my Magisk module?
Use exec with xtrace.
Code:
exec 2>/path/to/log/file;
set -x;
It will redirect the command (execution) tree and their errors to the log_file.
Regards.
@JayminSuthar Sorry, I don't understand. Where should I place that code? And are you saying that all the commands (outputs and errors) on my module will be redirected to that file, no exceptions?
You should place this code in your script from where you want logging to start (mostly the beginning). This will print the command (execution) tree in the log file, and all errors (if any), It will not print the output, but the command executed itself.
The format of the logs should be like
Code:
+ >&2
+ echo 'Here logging starts, I'm stderr'
Here logging starts, I'm stderr
+ rm -f /some/non/existent/file
rm: Can't remove file: No such file or directory

[Help] Modifying and replacing existing files

Hi! I need to modify build.prop in /vendor partition. As i understood system.prop can't affect it. So i decided to edit it with "sed" cmd. But i got stuck on boot script. It is executed in magisk logs, but there is no code executed (i added one copy+paste cmd to test).
How should i properly modify /vendor files?
Should i modify it in post-fs-data.sh or service.sh?
I'm noob in magisk module making
Bash:
# This script will be executed in post-fs-data mode
# More info in the main Magisk thread
MODDIR=${0%/*}
#testing and no result
cp /system/build.prop /storage/emulated/0/build.propes
cp /system/build.prop /sdcard/build.propes
#i want to do this
sed -i 's/ro.product.system.brand=Xiaomi/ro.product.system.brand=Google/g' ${$MODDIR}/system/build.prop
sed -i 's/ro.product.system.brand=Xiaomi/ro.product.system.brand=Google/g' ${$MODDIR}/vendor/build.prop
Why do you need to edit the actual build.prop file? Isn't it enough to use the resetprop tool (system.prop in the module).
Didgeridoohan said:
Why do you need to edit the actual build.prop file? Isn't it enough to use the resetprop tool (system.prop in the module).
Click to expand...
Click to collapse
I've tried to do this via system.prop, but got negative result. When i do replace modified files through recovery, i get positive result. Idk whats the problem, cuz i even tried to mount files in moddir/system/ folder. Seems android somehow detects any changes
So i have to copy files to module folder, modify, and replace them in original directory. Now the problem is in editing file, i successfully copied file but "sed" doesnt seem to work lol
What do you mean with "negative results"? Does the prop value not change? Have you tested with the getprop command (because you can't look in the prop file, it won't change when using the resetprop tool)?
Using a Magisk module to magic mount the prop files is likely not going to work since that will happen way too late for the files to be read by the system.
Didgeridoohan said:
What do you mean with "negative results"? Does the prop value not change? Have you tested with the getprop command (because you can't look in the prop file, it won't change when using the resetprop tool)?
Using a Magisk module to magic mount the prop files is likely not going to work since that will happen way too late for the files to be read by the system.
Click to expand...
Click to collapse
Negative result for me - app does not recognize me as another device. There is some protection in it that doesnt simply read system props. It read the build props in root directory. (last android security patch)
I just need to modify files in module directory and thats all. I have only this problem now.
No apps can read the build.prop files directly (unless they're root apps, of course)... Apps will be reading the values, not the file, which is why the resetprop tool works without changing the prop file.
If you really want to go for it though your sed command looks fine, except that I would use ${MODDIR}/system/vendor/build.prop since I don't think the ${MODDIR}/vendor symlink will be available when post-fs-data.sh is executed.
Not sure why you're copying the files to the internal storage and why you're naming them .propes, so can't say much about that.

Categories

Resources