About setXattr and cxattr

I checked the /var/log/installer.log and found this after upgrading the initial installation of macOS High Sierra 10.13:

Begin script: setXattr
installd[610]: postinstall: Detected Seed Program Enrollement: DeveloperSeed in /Volumes/HSDPX/Users/Shared/.SeedEnrollment.plist
installd[610]: postinstall: /private/tmp/PKInstallSandbox.4ddTpG/Scripts/com.apple.pkg.InstallAssistantAuto.XPuvds/postinstall_actions/setXattr: line 22: ./Tools/cxattr: No such file or directory
installd[610]: postinstall: Failed to set xattr on: /Volumes/HSDPX/Applications/Install macOS High Sierra Beta.app
End script: setXattr

But no worries. High Sierra works just fine so that is not the problem. Still. I want to learn/know what is going on and where this error is coming from. I searched the backups that I made and found the script (setAttr) in InstallOSAuto.pkg Here it is:

#!/bin/bash

APP_BUNDLE_PATH="$3/Applications/Install macOS 10.13 Beta.app"
SEED_PROGRAM_KEY="SeedProgram"
SEED_PLIST="$3/Users/Shared/.SeedEnrollment.plist"
if [ $(/usr/bin/sw_vers -productVersion | /usr/bin/cut -d '.' -f 1,2) == "10.9" ]; then
    SEED_PLIST="$3/Library/Application Support/App Store/.SeedEnrollment.plist"
fi

if [ ! -e "${SEED_PLIST}" ]; then
    echo "Seed Program Enrollement plist not found."
    exit 0
fi

SEED_PROGRAM=$(/usr/libexec/PlistBuddy -c "Print ${SEED_PROGRAM_KEY}" "${SEED_PLIST}")
if [ $? -ne "0" ]; then
    SEED_PROGRAM=0
fi

if [ "${SEED_PROGRAM}" != "0" ]; then
    echo "Detected Seed Program Enrollement: ${SEED_PROGRAM} in ${SEED_PLIST}"
    ./Tools/cxattr -w "${SEED_PROGRAM_KEY}" "${SEED_PROGRAM}" "${APP_BUNDLE_PATH}"
    if [ $? -ne "0" ]; then
        echo "Failed to set xattr on: ${APP_BUNDLE_PATH}"
    fi
else
    echo "Seed Program Enrollment not detected in ${SEED_PLIST}"
fi

What this script does, basically, is to set an attribute (SeedProgram) on the High Sierra installer app, and it does this like so for the BetaSeed:

./Tools/cxattr -w SeedProgram BetaSeed /Applications/Install\ macOS\ 10.13\ Beta.app

Here is the one for the DeveloperSeed:

./Tools/cxattr -w SeedProgram DeveloperSeed /Applications/Install\ macOS\ 10.13\ Beta.app

And here is the one for the CustomerSeed:

./Tools/cxattr -w SeedProgram CustomerSeed /Applications/Install\ macOS\ 10.13\ Beta.app

The cxattr tool is a compiled program but /usr/bin/xattr is just a Python script. Here it is:

#!/usr/bin/python

import sys, os
import glob, re

partA = """\
python version %d.%d.%d can't run %s.  Try the alternative(s):

"""
partB = """
Run "man python" for more information about multiple version support in
Mac OS X.
"""

sys.stderr.write(partA % (sys.version_info[:3] + (sys.argv[0],)))

dir, base = os.path.split(sys.argv[0])
specialcase = (base == 'python-config')
if specialcase:
    pat = "python*-config"
else:
    pat = base + '*'
g = glob.glob(os.path.join(dir, pat))
# match a single digit, dot and possibly multiple digits, because we might
# have 2to32.6, where the program is 2to3 and the version is 2.6.
vpat = re.compile("\d\.\d+")
n = 0
for i in g:
    vers = vpat.search(i)
    if vers is None:
	continue
    sys.stderr.write("%s (uses python %s)\n" % (i, i[vers.start():vers.end()]))
    n = 1
if n == 0:
    sys.stderr.write("(Error: no alternatives found)\n")

sys.stderr.write(partB)
sys.exit(1)

The good thing is that we don’t need the cxattr tool. No. We can also use: usr/bin/xattr:

xattr -w SeedProgram BetaSeed /Applications/Install\ macOS\ 10.13\ Beta.app

That is. After the installer is done – there is no Python during the installation phases. Anyway. You can list the attributes that are set with:

xattr -l /Applications/Install\ macOS\ 10.13\ Beta.app

Or you can do that with hexadecimal output:

xattr -lx /Applications/Install\ macOS\ 10.13\ Beta.app

Removing the SeedProgram attribute (or any other attribute that is set) can be done with:

xattr -d SeedProgram /Applications/Install\ macOS\ 10.13\ Beta.app

It seems that only the initial installer came with the cxattr tool. All later updates of High Sierra do not include the cxattr tool.

Ok. It’s not like we really need it, but I thought to share my findings with you here. Just in case you are wondering where that error is coming from 😉

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s