Search code examples
macosshellinstallationpackagemaker

Remove package identifier file during installation


I'm a newbie in OSx development.

I'm creating an installer package using Packagemaker 3.0.4. Since I want to remove the local settings of my app during installation, I decided to remove the com.identifier.plist. However, I'm not that good in scripting and I'm just starting to explore what Packagemaker is capable of.

Ideally, I want my implementation to be as simple as this:

  1. Check if the .plist file exists
  2. Remove it.

I have tried:

#!/bin/sh
defaults delete ~/Library/Preferences/com.identifier.AppName.plist

Then I saved the delete.sh file to the Desktop. I opened the Packagemaker app and provided the path to my Desktop: /Users/MyName/Desktop/delete.sh in the Scripts Postflight. Then I executed build & run. It didn't work. I thought that it might probably be the script, so I changed it to:

#!/bin/sh
rm ~/Library/Preferences/com.identifier.AppName.plist;

Then I loaded the delete.sh file the same way as I did on the script above. But I received this error:

Mar 29 20:50:54 Mac-mini installd[5425]: PackageKit: Install Failed: PKG: post-flight scripts for "com.testIdentifier.test.AppName.pkg"\nError Domain=PKInstallErrorDomain Code=112 UserInfo=0x100404220 "An error occurred while running scripts from the package “test.pkg”." {\n NSFilePath = "./postflight";\n NSLocalizedDescription = "An error occurred while running scripts from the package \U201ctest.pkg\U201d.";\n NSURL = "./Contents/Packages/test.pkg -- file://localhost/Users/MyName/Desktop/AppName.mpkg/";\n PKInstallPackageIdentifier = "com.testIdentifier.test.AppName.pkg";\n}

If anyone who has a Step-by-Step implementation of creating & adding script to the Packagemaker, and perhaps, my scripts aren't correct, it would be awesome if you could help me out.

Thank you so much in advance! :)


Solution

  • I've got it...

    Here's my script:

    #!/usr/bin/env bash
    
    file=~/Library/Preferences//com.identifier.AppName.plist
    if [ -e "$file" ]
    then
    # file is found
    /usr/bin/defaults delete ~/Library/Preferences//com.identifier.AppName
    else
    # file not found."
    fi
    
    exit 0
    

    I then added it to PackageMaker. I'm not really sure if I'm right but I might have just forgotten to add the script's file into the contents. That's why it never worked earlier. I just put the script's path on the postflight.

    Anyway, thanks a lot to everyone for the tips.