[Dev Help] Is it possible to run an "uninstall script" when removing a module?

Search This thread

Ssayerr

Senior Member
Oct 23, 2015
145
56
[Dev Help] Is it possible to run an "uninstall script" when removing a module?

Hey all. I'm working on a module, and I'm planning on using the late-start service to make some changes to the system to detach the app I'm including in the module from the Play Store to prevent accidental updates or a persistent update nag. This part is working fine. The part I'm having troubles with is the uninstall portion. When removing the module, the changes persist since they weren't systemless. So, my question is this: is it possible to have Magisk run an "uninstall script" when it has been marked for deletion? I've done some digging through the documentation and haven't found anything indicating this is possible, but I'm hoping it's either an undocumented feature or somebody will know a way to achieve the same effect.
 

Didgeridoohan

Retired Senior Moderator
May 31, 2012
12,300
1
14,850
Gone
Google Nexus 4
Nexus 6
You could let the module also install a boot script in post-fs-data.d or service.d (service.d is preferred, but if that doesn't work try post-fs-data.d). Let that script look for the module folder in /magisk. If it isn't found, let the script revert the changes and then delete itself.
 
Last edited:

Ssayerr

Senior Member
Oct 23, 2015
145
56
You could let the module also install a boot script in post-fs-data.d or service.d (service.d is preferred, but if that doesn't work try post.fs.data.d). Let that script look for the module folder in /magisk. If it isn't found, let the script revert the changes and then delete itself.

You mean in Magisk's core? Yeah, that's a good idea, and probably easily implemented.
 

Ssayerr

Senior Member
Oct 23, 2015
145
56
You could check the file called "remove" in the module folder.

Unless the "remove" file itself can be set up to run a script, that wouldn't work. If that file is present, the module as a whole would be gone before my script would run. I'm currently planning on just having a script check for the existence of the module itself, once I have time to mess with it some more.
 

Deic

Senior Member
Feb 4, 2012
540
987
Madrid
www.xiaomiadictos.com
Unless the "remove" file itself can be set up to run a script, that wouldn't work. If that file is present, the module as a whole would be gone before my script would run. I'm currently planning on just having a script check for the existence of the module itself, once I have time to mess with it some more.

Must keep in background a loop to check the existence of that file obviously. So in your module script for example:
Code:
background function() {
    while :; do
        [ -f /magisk/$MODDIR/remove ] && {
            #here the stuff you want to do
            break
        }
        sleep 1
    done
}

background &
 

ahrion

Retired Forum Moderator / Recognized Developer
Jul 19, 2013
3,101
5,128
Hey all. I'm working on a module, and I'm planning on using the late-start service to make some changes to the system to detach the app I'm including in the module from the Play Store to prevent accidental updates or a persistent update nag. This part is working fine. The part I'm having troubles with is the uninstall portion. When removing the module, the changes persist since they weren't systemless. So, my question is this: is it possible to have Magisk run an "uninstall script" when it has been marked for deletion? I've done some digging through the documentation and haven't found anything indicating this is possible, but I'm hoping it's either an undocumented feature or somebody will know a way to achieve the same effect.


You could let the module also install a boot script in post-fs-data.d or service.d (service.d is preferred, but if that doesn't work try post-fs-data.d). Let that script look for the module folder in /magisk. If it isn't found, let the script revert the changes and then delete itself.
My Unity (Un)Installer has this includes.

Essentially you can run a .core service.d script to delete any left over files such as scripts if the conditional says that the specified mod folder does not exist, and then have the script delete itself once done.


https://github.com/therealahrion/Audio-Modification-Library
This isn't just for AML or audio projects, as it uses the Unity Installer.
 

ahrion

Retired Forum Moderator / Recognized Developer
Jul 19, 2013
3,101
5,128
Sure, the Unity stuff (Copyrigth © 1337 Canonical Ltd.) is lesser complicated than a few basic command lines in the module script.

Sarcasm intended.
That was not my intention. Lol I knew that was gonna happen. Unity has a lot of features that allows people to make quick edits without having to touch the update-binary.

I was using the /common/moddid-service.sh as an example.

Here's a more refined example minus Unity mumbo jumbo:
if [ ! -d /magisk/$MODID ]; then
rm -f /magisk/.core/service.d/$MODID.sh
fi
 
Last edited:

Didgeridoohan

Retired Senior Moderator
May 31, 2012
12,300
1
14,850
Gone
Google Nexus 4
Nexus 6
My Unity (Un)Installer has this includes.

Essentially you can run a .core service.d script to delete any left over files such as scripts if the conditional says that the specified mod folder does not exist, and then have the script delete itself once done.


https://github.com/therealahrion/Audio-Modification-Library
This isn't just for AML or audio projects, as it uses the Unity Installer.

I do the same on a couple of my own modules. Post-fs-data.d or service.d scripts that doesn't run if the disable file is present in the module folder and cleans up and deletes itself if the folder isn't found, etc. It's really handy...
 

Top Liked Posts