Home Forums Software InstaDMG regular expression for postflight script

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #377362
    benfeea1
    Participant

    I need a regular expression that will delete the last slash “/” in a line, and everything to the left of it.

    I want to turn the full path to a package
    /Volume/Installer/InstallerPackage.pkg
    into just the name of the package
    InstallerPackage.pkg

    I will be using this in postflight scripts if I want to delete the package reciept.

    Unless there is an Installer.app Environmental Positional Variable for the package name, I figured a regex was the way to go.

    Here is an example of my postflight script.

    #!/bin/bash
    # postflight script
    # Installer.app Environmental Positional Variables.
    # $0 Script path
    # $1 Package path
    # $2 Default location
    # $3 Target volume
    # Declare the Enviromental Positional Variables so the can be used in function calls.
    ScriptPath=$0
    PackagePath=$1
    DefaultLocation=$2
    TargetVolume=$3
    PackageName=${PackagePath”MagicRegEx”}

    RemovePackageReceipt () {
    rm -rf “${TargetVolume}/Library/Receipts/${PackageName}”
    echo removed “${TargetVolume}/Library/Receipts/${PackageName}”
    }

    RemovePackageReceipt

    #377365
    larkost
    Participant

    Assuming that you are not going to have escaped ‘/’ characters in your path:
    [code]PackageName=$( /usr/bin/basename “$PackagePath” )[/code] (not tested… just written)

    #377373
    benfeea1
    Participant

    larkost,

    You are a very wise Marklar. That worked perfectly.

    #!/bin/bash
    # postflight script
    # Installer.app Environmental Positional Variables.
    # $0 Script path
    # $1 Package path
    # $2 Default location
    # $3 Target volume
    # Declare the Enviromental Positional Variables so the can be used in function calls.
    ScriptPath=$0
    PackagePath=$1
    DefaultLocation=$2
    TargetVolume=$3
    PackageName=$( /usr/bin/basename “$PackagePath” )

    RemovePackageReceipt () {
    rm -rf “${TargetVolume}/Library/Receipts/${PackageName}”
    echo removed “${TargetVolume}/Library/Receipts/${PackageName}”
    }

    RemovePackageReceipt

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Comments are closed