iTunes 12.7 Postinstall Action Script Issue

iTunes 12.7 Postinstall Action Script Issue


Overview


Inside the standard iTunes 12.7 installer is a postinstall action script called startFpsdDaemons.sh  that has some bugs that cause issues with tools like AutoDMG.

Incorrect Permissions
First, the script has incorrect permissions -rw-r–r– . So, the group and other users, do not have execute permissions.

Syntax Error
And has a syntax error on line 123:

logger -p install.info “sudo killall adid”

Note, the last quote is a smart quote in unicode. Smart Quotes are a special kind of quotation mark where the opening-quote and the closing-quote are visually different. Sometimes they are also known as “curly quotes”. In many typographic settings, this is preferred to the more mundane “straight quote”. Many times this will cause issues in scripts and code, you will get an error and the code won’t run.

The script is unable to run due to these issues and will get a syntax error once it has been ran.

/path/to/startFpsdDaemons.sh 
/System/Library/LaunchDaemons/com.apple.fpsd.plist: service already loaded
/path/to/startFpsdDaemons.sh: line 123: unexpected EOF while looking for matching `"'
/path/to/startFpsdDaemons.sh: line 129: syntax error: unexpected end of file

If the script doesn’t run properly, it will not create the _fpsd  user, unload the com.apple.fpsd.plist  LaunchDaemon and properly kill the adid  and fpsd  processes.

This causes iTunes to hang and become unresponsive. Manually installing the package doesn’t cause iTunes to hang, but using open-source tools like AutoDMG to create an image will cause iTunes to hang. Fixing the permissions and the syntax error will make iTunes work properly using tools like AutoDMG, etc.

OS Code Names
Note, of interest is the following comments in the postinstall action script:

# for Syrah or higher unload and load fpsd if it exists

“Syrah” is the code name for Mac OSX Yosemite 10.10.

And, other code name, “Lobo” for macOS High Sierra 10.13:

# remove adid daemon if < Lobo

# For Lobo or higher unload and load adid if it exists

Workaround & Fix
We fixed the script, removed the smart quote…

logger -p install.info “sudo killall adid”

And changed permissions to -rwxr-xr-x , giving group and other users execute permisions.

So, now we get the following output with the script properly running:

/path/to/startFpsdDaemons.sh
/System/Library/LaunchDaemons/com.apple.fpsd.plist: service already loaded
No matching processes were found
No matching processes were found

And created a package installer of the fixed script which fixes the issue in AutoDMG.

Credit
We want to give credit to our own Topher Nadauld, for the great detective work tracking this issue down. Great job!!!

Bug Report
This issue has be filed in Apple’s Bug Reporter system, radar number: 34719508 .
And this has been added to the community open radar here.

For reference, here is the entire startFpsdDaemons.sh  iTunes 12.7 postinstall action script:

#!/bin/bash                                                                      
DESTPATH=$2
TARGETVOL=$3

adidPlist="/System/Library/LaunchDaemons/com.apple.adid.plist"
fpsdPlist="/System/Library/LaunchDaemons/com.apple.fpsd.plist"

################## Functions  ####################

function isOSEqualHigher() {

input=$1

version=$(sw_vers -productVersion)

firstDigit=$(echo $version | cut -d . -f 1)

secondDigit=$(echo $version | cut -d . -f 2)

# if Lobo or higher return 1                                                                                                                          
if [[ "$firstDigit" -ge  "11"  ]] ; then

    echo  1


elif [[ "$secondDigit" -ge  "$input"  &&  "$firstDigit" -eq  "10"  ]] ; then

    echo 1

# must be less than Lobo return 1                                                                                                                               
else

    echo 0

fi

}


# check if _fpsd users exists.  Create _fpsd if it doesn't

/usr/bin/dscl . -list /Users UniqueID | grep '_fpsd' &> /dev/null


if [ $? != 0 ]; then
  

   
    /usr/bin/dscl . -create /Groups/_fpsd  || logger -p install.info “/usr/bin/dscl . -create /Groups/_fpsd failed:  ”

   
    /usr/bin/dscl . -create /Groups/_fpsd PrimaryGroupID 265 || logger -p install.info “/Groups/_fpsd PrimaryGroupID 265 failed:  ” logger -p install.info “/Groups/_fpsd PrimaryGroupID 265 failed:  ”
    
   
    /usr/bin/dscl . -create /Users/_fpsd UniqueID 265 ||  logger -p install.info “ /usr/bin/dscl . -create /Users/_fpsd UniqueID 265 failed:  ”
    
   
    /usr/bin/dscl . -create /Users/_fpsd PrimaryGroupID 265 ||  logger -p install.info “/usr/bin/dscl . -create /Users/_fpsd PrimaryGroupID 265  failed:  ”

    /usr/bin/dscl . -create /Users/_fpsd NFSHomeDirectory  /var/db/fpsd  ||  logger -p install.info “/usr/bin/dscl . -create /Users/_fpsd NFSHomeDirectory  /var/db/fpsd failed:  ”
   
    /usr/bin/dscl . -create /Users/_fpsd UserShell /usr/bin/false ||  logger -p install.info “/usr/bin/dscl . -create /Users/_fpsd UserShell  failed:  ”


fi


# remove adid daemon if < Lobo  


if [[ $(isOSEqualHigher 13) == 0  && -f "$adidPlist" ]] ; then
       
       logger -p install.info "sudo rm -rf  $adidPlist"
       sudo rm -rf $adidPlist

fi



# For Lobo or higher unload and load adid if it exists
if  [ `isOSEqualHigher 13` -eq 1 ]; then

    if [[ -f $adidPlist ]]; then
        logger -p install.info "sudo launchctl bootstrap system $adidPlist"
	launchctl bootstrap system $adidPlist
    fi
fi

# for Syrah or higher unload and load fpsd if it exists 
if  [ `isOSEqualHigher 10` -eq 1 ]; then

    if [[ -f $fpsdPlist ]]; then
    logger -p install.info "sudo launchctl bootstrap system $fpsdPlist"
    launchctl bootstrap system $fpsdPlist
   
    fi

elif [[ -f "$fpsdPlist" ]] ; then

     logger -p install.info "sudo launchctl unload $fpsdPlist"
     sudo launchctl unload $fpsdPlist
     logger -p install.info "sudo launchctl load $fpsdPlist"
     sudo launchctl load $fpsdPlist
else

    logger -p install.info "$fpsdPlist doesn't exist, so didn't load them"	

fi

logger -p  install.info "killall fpsd"

killall fpsd

logger -p  install.info "sudo killall adid”

sudo killall adid

exit 0

 

No Comments

Leave a Reply