Skip to content

Instantly share code, notes, and snippets.

@gniemetz
Created August 2, 2017 14:24
Show Gist options
  • Save gniemetz/57904dd85415a9218500cf316c82a069 to your computer and use it in GitHub Desktop.
Save gniemetz/57904dd85415a9218500cf316c82a069 to your computer and use it in GitHub Desktop.
Pre-/Postinstall script for installing Acrobat XI/DC/2015/2017 via munki
#!/usr/bin/env bash
PS4='+(${BASH_SOURCE}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
### customize parameters here
# show debug messages
Debug=${1:-false}
# the languages for the user templates
declare -a UserTemplateLanguageArray
UserTemplateLanguageArray[${#UserTemplateLanguageArray[@]}]="English.lproj"
UserTemplateLanguageArray[${#UserTemplateLanguageArray[@]}]="German.lproj"
UserTemplateLanguageArray[${#UserTemplateLanguageArray[@]}]="Non_localized"
# the keys and values to write to a plist file
# PreferencesDataArray structure = "plist file|key|datatype|value|write user template|write user preferences[|forced]"
# index no.: 0 |1 |2 |3 |4 |5 |6
# plist file: string (preferences file, eg com.microsoft.autoupdate2)
# key: string (key name, eg. HowToCheck)
# datatype: string, data, int[eger], float, bool[ean], date, array, array-add, dict, dict-add
# value: corresponding value
# write user template: true|false (write into ${UserTemplateFQFN}, typically /System/Library/User Template/${UserTemplateLanguageArray}/Library/Preferences)
# write user preferences: true|false (write into ${UserPreferencesFQFN}, typically /Users/${User}/Library/Preferences)
# forced (opt.): true (forced write of key and value into ${UserPreferencesFQFN}, even if the key previously didn't exist)
declare -a PreferencesDataArrayArray
PreferencesDataArray[${#PreferencesDataArray[@]}]="com.adobe.Reader.plist|DC|dict-add|EULAAccepted -bool true|true|true|true"
PreferencesDataArray[${#PreferencesDataArray[@]}]="com.adobe.Reader.plist|2015|dict-add|EULAAccepted -bool true|true|true|true"
PreferencesDataArray[${#PreferencesDataArray[@]}]="com.adobe.Reader.plist|2017|dict-add|EULAAccepted -bool true|true|true|true"
# leave untouched, unless you know what you're doing
UserTemplateLanguage=""
PreferencesData=""
# read with IFS='|' read -ra PreferencesDataSubArray <<<"${PreferencesDataArray[<Index number>]}"
PreferencesDataSubArray=""
UserTemplateBasePath="/System/Library/User Template"
UserTemplateFQFN=""
UsersFQPN="/Users"
UserArray=( $( (set +o noglob && cd "${UsersFQPN}" && { find * -type d -maxdepth 0 \( -iname guest* -o -iname shared \) -prune -o -type d -print || : ; } && set -o noglob) ) ardadmin )
User=""
PreferencesDir="Library/Preferences"
UserPreferencesFQPN=""
UserPreferencesFQFN=""
# variables dscl* set through eval $(dscl | awk)
dsclNFSHomeDirectory=""
declare -i dsclPrimaryGroupID
dsclRealName=""
dsclInitials=""
declare -i dsclUniqueID
Delimiter="|"
Cmd=""
RClog=""
declare -i RC=0
declare -i EC=0
# set preferences for existing users
for User in "${UserArray[@]}"; do
Cmd="dscl . read /Users/${User} NFSHomeDirectory PrimaryGroupID RealName UniqueID"
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
if [[ ${RC} -eq 0 ]]; then
eval $(echo "${RClog}" |\
awk '
BEGIN {
PrefixOutput="dscl"
NFSHomeDirectory=""
PrimaryGroupID=""
RealNameFound=0
RealName=""
UniqueID=""
}
function getRealNameFromPos(Position) {
for(FieldNr=Position; FieldNr <= NF; FieldNr++) {
RealName = (RealName == "" ? "" : RealName " ") $FieldNr
}
}
RealNameFound == 1 {
getRealNameFromPos(1)
RealNameFound=0
}
$1 == "RealName:" {
if(NF > 1) {
getRealNameFromPos(2)
}
else {
RealNameFound=1
}
}
$1 == "NFSHomeDirectory:" {
NFSHomeDirectory=$2
}
$1 == "PrimaryGroupID:" {
PrimaryGroupID=$2
}
$1 == "UniqueID:" {
UniqueID=$2
}
END {
if (PrimaryGroupID != "" && UniqueID != "") {
split(RealName, Initials, " ")
printf("declare -i %sPrimaryGroupID=%s; %sNFSHomeDirectory=%c%s%c; %sRealName=%c%s%c; %sInitials=%c%c%c%c; declare -i %sUniqueID=%s", PrefixOutput, PrimaryGroupID, PrefixOutput, 34, NFSHomeDirectory, 34, PrefixOutput, 34, (RealName == "" ? "Ein Microsoft Office User" : RealName), 34, PrefixOutput, 34, (Initials[1] == "" ? "O" : Initials[1]), (Initials[2] == "" ? "U" : Initials[2]), 34, PrefixOutput, UniqueID)
exit 0
}
else {
exit 1
}
}
')
UserPreferencesFQPN="${dsclNFSHomeDirectory:+${dsclNFSHomeDirectory}/}${PreferencesDir}"
if [[ -d "${UserPreferencesFQPN}" && -n "${dsclUniqueID}" && -n "${dsclPrimaryGroupID}" ]]; then
for PreferencesData in "${PreferencesDataArray[@]}"; do
IFS="${Delimiter}" read -ra PreferencesDataSubArray<<<"${PreferencesData}"
UserPreferencesFQFN="${UserPreferencesFQPN}/${PreferencesDataSubArray[0]}"
if [[ "${PreferencesDataSubArray[5]}" == true ]]; then
# save value of ${Key} when Value of PreferencesDataArray is a variable
if [[ "${PreferencesDataSubArray[3]}" =~ "$" ]]; then
Cmd="defaults read \"${UserPreferencesFQFN}\" \"${PreferencesDataSubArray[1]}\""
else
Cmd="defaults delete \"${UserPreferencesFQFN}\" \"${PreferencesDataSubArray[1]}\""
fi
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
if [[ ${RC} -eq 0 || "${PreferencesDataSubArray[6]}" == true ]]; then
if [[ "${PreferencesDataSubArray[3]}" =~ "$" ]]; then
if [[ -z "${RClog}" ]]; then
PreferencesDataSubArray[3]="$(eval echo "${PreferencesDataSubArray[3]}")"
else
PreferencesDataSubArray[3]="${RClog}"
fi
fi
Cmd="defaults write \"${UserPreferencesFQFN}\" \"${PreferencesDataSubArray[1]}\" -\"${PreferencesDataSubArray[2]}\" ${PreferencesDataSubArray[3]}"
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
if [[ ${RC} -eq 0 ]]; then
Cmd="chown ${dsclUniqueID}:${dsclPrimaryGroupID} \"${UserPreferencesFQFN}\""
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
if [[ ${RC} -eq 0 ]]; then
Cmd="chmod 600 \"${UserPreferencesFQFN}\""
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
if [[ ${RC} -ne 0 ]]; then
echo -e "ERROR: ${Cmd} failed|RC=${RC}|RClog=${RClog}"
EC=$((${EC}||${RC}))
fi
else
echo -e "ERROR: ${Cmd} failed|RC=${RC}|RClog=${RClog}"
EC=$((${EC}||${RC}))
fi
else
echo -e "ERROR: ${Cmd} failed|RC=${RC}|RClog=${RClog}"
EC=$((${EC}||${RC}))
fi
fi
fi
done
else
echo -e "WARNING: ${UserPreferencesFQPN} does not exist, maybe not a real user?"
fi
else
if [[ ${RC} -eq 56 ]]; then
echo -e "WARNING: ${${User}} via dscl not found|RC=${RC}|RClog=${RClog}"
else
echo -e "ERROR: ${Cmd} failed|RC=${RC}|RClog=${RClog}"
EC=$((${EC}||${RC}))
fi
fi
done
# set user template for future users
for UserTemplateLanguage in "${UserTemplateLanguageArray[@]}"; do
for PreferencesData in "${PreferencesDataArray[@]}"; do
IFS="${Delimiter}" read -ra PreferencesDataSubArray<<<"${PreferencesData}"
if [[ "${PreferencesDataSubArray[4]}" == true ]]; then
UserTemplateFQFN="${UserTemplateBasePath}/${UserTemplateLanguage}/${PreferencesDir}/${PreferencesDataSubArray[0]}"
Cmd="defaults delete \"${UserTemplateFQFN}\" \"${PreferencesDataSubArray[1]}\""
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
Cmd="defaults write \"${UserTemplateFQFN}\" \"${PreferencesDataSubArray[1]}\" -\"${PreferencesDataSubArray[2]}\" ${PreferencesDataSubArray[3]}"
RClog="$(eval ${Cmd} 2>&1)"
RC=${?}
[[ "Debug_${Debug}" == Debug_true ]] && echo "DEBUG: Cmd=${Cmd}|RC=${RC}|RClog=${RClog}"
fi
done
done
exit ${EC}
#!/usr/bin/env bash
AcrobatProPreferences="/Library/Preferences/com.adobe.Acrobat.Pro.plist"
AcrobatReaderPreferences="/Library/Preferences/com.adobe.Reader.plist"
IFS= read -d '' CommonAdobePreferences <<EOPREF
<key>EULAAccepted</key>
<true/>
<key>AVAlert</key>
<dict>
<key>Checkbox</key>
<array>
<integer>8</integer>
<dict>
<key>OptionToOwn</key>
<array>
<integer>1</integer>
<integer>1</integer>
</array>
</dict>
</array>
</dict>
<key>AVGeneral</key>
<dict>
<key>isFirstLaunch</key>
<array>
<integer>0</integer>
<false/>
</array>
</dict>
<key>ShowSplashScreen</key>
<false/>
<key>FeatureLockdown</key> <!-- https://www.adobe.com/devnet-docs/acrobatetk/tools/PrefRef/Macintosh/index.html -->
<dict>
<key>bUpdater</key>
<false/>
<key>cGeneral</key>
<dict>
<key>bToggleCustomOpenSaveExperience</key>
<false/>
</dict>
<key>cCloud</key>
<dict>
<key>bDisableADCFileStore</key>
<true/>
</dict>
<key>cServices</key>
<dict>
<key>bToggleAdobeDocumentServices</key>
<false/>
<key>bToggleAdobeSign</key>
<false/>
<key>bToggleDocumentCloud</key>
<false/>
<key>bToggleDocumentConversionServices</key>
<false/>
<key>bToggleFillSign</key>
<false/>
<key>bToggleMobileLink</key>
<false/>
<key>bToggleSendAndTrack</key>
<false/>
<key>bToggleWebConnectors</key>
<true/>
<key>bDisableSharePointFeatures</key>
<true/>
<key>bUpdater</key>
<false/>
<key>bUsageMeasurement</key>
<false/>
</dict>
<key>cSharePoint</key>
<dict>
<key>bDisableSharePointFeatures</key>
<true/>
</dict>
<key>cWebmailProfiles</key>
<dict>
<key>bDisableWebmail</key>
<true/>
</dict>
</dict>
<key>FeatureLockDown</key> <!-- https://www.adobe.com/devnet-docs/acrobatetk/tools/PrefRef/Macintosh/index.html -->
<dict>
<key>bUpdater</key>
<false/>
<key>cGeneral</key>
<dict>
<key>bToggleCustomOpenSaveExperience</key>
<false/>
</dict>
<key>cCloud</key>
<dict>
<key>bDisableADCFileStore</key>
<true/>
</dict>
<key>cServices</key>
<dict>
<key>bToggleAdobeDocumentServices</key>
<false/>
<key>bToggleAdobeSign</key>
<false/>
<key>bToggleDocumentCloud</key>
<false/>
<key>bToggleDocumentConversionServices</key>
<false/>
<key>bToggleFillSign</key>
<false/>
<key>bToggleMobileLink</key>
<false/>
<key>bToggleSendAndTrack</key>
<false/>
<key>bToggleWebConnectors</key>
<true/>
<key>bDisableSharePointFeatures</key>
<true/>
<key>bUpdater</key>
<false/>
<key>bUsageMeasurement</key>
<false/>
</dict>
<key>cSharePoint</key>
<dict>
<key>bDisableSharePointFeatures</key>
<true/>
</dict>
<key>cWebmailProfiles</key>
<dict>
<key>bDisableWebmail</key>
<true/>
</dict>
</dict>
EOPREF
if ! RV="$(cat >"${AcrobatReaderPreferences}" <<EOPLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>11</key> <!-- https://www.adobe.com/devnet-docs/acrobatetk/tools/AdminGuide/whatsnewdc.html#whatsnewdc -->
<dict>
${CommonAdobePreferences} </dict>
<key>DC</key>
<dict>
${CommonAdobePreferences} </dict>
<key>2015</key>
<dict>
${CommonAdobePreferences} </dict>
<key>2017</key>
<dict>
${CommonAdobePreferences} </dict>
</dict>
</plist>
EOPLIST
)"; then
echo "ERROR|cat >'${AcrobatReaderPreferences}' failed (RC=${?}, RV=${RV})"
exit 1
fi
if ! RV="$(plutil -lint "${AcrobatReaderPreferences}" 2>&1)"; then
echo "ERROR|plutil -lint '${AcrobatReaderPreferences}' failed (RC=${?}, RV=${RV})"
exit 1
fi
if ! RV="$(chown root:wheel "${AcrobatReaderPreferences}" 2>&1)"; then
echo "ERROR|chown root:wheel '${AcrobatReaderPreferences}' failed (RC=${?}, RV=${RV})"
exit 1
fi
if ! RV="$(chmod 644 "${AcrobatReaderPreferences}" 2>&1)"; then
echo "ERROR|chmod 644 '${AcrobatReaderPreferences}' failed (RC=${?}, RV=${RV})"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment