Posted on 10-06-2015 12:15 PM
Hi Everyone! Does anyone have a script that will "uninstall" all versions of Shockwave 12 completely from my Macs?
Solved! Go to Solution.
Posted on 10-06-2015 12:24 PM
Try this. No guarantees, though.
It also is more complicated than it needs to be, but i just copy and paste a skeleton script for those purposes.
#!/bin/bash
#
# Uninstalls all files and processes
#
# Define your removal options here
launchdaemons_to_remove=(
)
launchdaemons_to_remove_at_end=(
)
launchagents_to_remove=(
)
directory_trees_to_remove=(
"/Library/Application Support/Adobe/Shockwave 11"
"/Library/Application Support/Adobe/Shockwave 12/DirectorShockwave.bundle"
"/Library/Application Support/Adobe/Shockwave 12/Xtras"
"/Library/Internet Plug-Ins/DirectorShockwave.plugin"
)
empty_directories_to_remove=(
"/Library/Application Support/Adobe/Shockwave 12"
"/Library/Application Support/Adobe"
)
pkg_receipts_to_remove=(
"com.adobe.shockwave"
"adobe.adobeShockwavePlayer.shockwave11.pkg"
"adobe.adobeShockwavePlayer.shockwave12.pkg"
)
casper_receipts_pattern='^Shockwave_Installer_Full_.*.[m]?pkg$'
function RemovePrefFiles () {
# custom pref removal function
return 0
}
#
# NOTHING TO CHANGE BELOW HERE
#
#################
# get script parameters
targetDrive="${1}"
computerName="${2}"
userName="${3}"
bRemovePrefs="${4}"
# Variables
CASPER_RECEIPT_PATH="${targetDrive}/Library/Application Support/JAMF/Receipts"
#################
# check script parameters
if [[ "${targetDrive}" == "" ]]; then
echo "No Target Drive set."
exit 1
fi
# check if we also should clear the preferences
if [[ "${bRemovePrefs}" != "yes" ]]; then
bRemovePrefs=""
fi
#################
# get the first non-root loginwindow user
# TODO: get all users and and unload agents for all of them
current_user=$( ps aux|grep "loginwindow [c]onsole"|grep -v "^root"|head -n 1|awk '{print $1}' )
if [[ "${current_user}" == "" ]]; then
current_user_loginpid=""
echo "Could not determine current Aqua user - not loading any LaunchAgents"
else
current_user_loginpid=$( ps ax -U "${current_user}"|grep "loginwindow [c]onsole"|head -n 1|awk '{print $1}' )
echo "Current Aqua user is ${current_user}, loginwindow pid is ${current_user_loginpid}"
fi
#################
# remove LaunchDaemons
for item in "${launchdaemons_to_remove[@]}"; do
fs_item="${targetDrive}/Library/LaunchDaemons/${item}.plist"
if [[ "${targetDrive}" == "/" ]]; then
launchdRunning=$( launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl remove "${item}"
&& echo "Removed active LaunchDaemon ${item}"
|| echo "Error removing active LaunchDaemon ${item}"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove LaunchAgents
for item in "${launchagents_to_remove[@]}"; do
fs_item="${targetDrive}/Library/LaunchAgents/${item}.plist"
if [[ "${targetDrive}" == "/" && ${current_user_loginpid} -gt 0 ]]; then
launchdRunning=$(
launchctl bsexec "${current_user_loginpid}" chroot -u "${current_user}" /
launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl bsexec "${current_user_loginpid}" chroot -u "${current_user}" / launchctl remove "${item}"
&& echo "Removed active LaunchAgent ${item} for user $current_user"
|| echo "Error removing active LaunchAgent ${item} for user $current_user"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove directories
for item in "${directory_trees_to_remove[@]}"; do
fs_item="${targetDrive}/${item}"
if [[ -d "${fs_item}" ]]; then
rm -r "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove empty directories
for item in "${empty_directories_to_remove[@]}"; do
fs_item="${targetDrive}/${item}"
if [[ -d "${fs_item}" ]]; then
rmdir "${fs_item}" 2>/dev/null
&& echo "Removed empty directory ${fs_item}"
fi
done
#################
# remove receipts
for item in "${pkg_receipts_to_remove[@]}"; do
/usr/sbin/pkgutil --volume "${targetDrive}" --forget "${item}" 2>/dev/null
done
#################
# remove casper receipts (empty files in CASPER_RECEIPT_PATH)
IFS=$'
'
if [[ "${casper_receipts_pattern}" != "" ]]; then
casper_receipts=(
$( /bin/ls "${CASPER_RECEIPT_PATH}" 2>/dev/null |
/usr/bin/grep "${casper_receipts_pattern}" )
)
for item in "${casper_receipts[@]}"; do
if [[ -f "${CASPER_RECEIPT_PATH}/${item}" ]]; then
/bin/rm "${CASPER_RECEIPT_PATH}/${item}"
&& echo "Removed ${CASPER_RECEIPT_PATH}/${item}"
|| echo "Error removing ${CASPER_RECEIPT_PATH}/${item}"
fi
done
IFS=$OLDIFS
fi
#################
# remove preferences
if [[ "${bRemovePrefs}" == "yes" ]]; then
echo "Removing preferences"
RemovePrefFiles
fi
#################
# remove final LaunchDaemons
for item in "${launchdaemons_to_remove_at_end[@]}"; do
fs_item="${targetDrive}/Library/LaunchDaemons/${item}.plist"
if [[ "${targetDrive}" == "/" ]]; then
launchdRunning=$( launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl remove "${item}"
&& echo "Removed active final LaunchDaemon ${item}"
|| echo "Error removing active final LaunchDaemon ${item}"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
exit 0
Posted on 10-06-2015 12:24 PM
Try this. No guarantees, though.
It also is more complicated than it needs to be, but i just copy and paste a skeleton script for those purposes.
#!/bin/bash
#
# Uninstalls all files and processes
#
# Define your removal options here
launchdaemons_to_remove=(
)
launchdaemons_to_remove_at_end=(
)
launchagents_to_remove=(
)
directory_trees_to_remove=(
"/Library/Application Support/Adobe/Shockwave 11"
"/Library/Application Support/Adobe/Shockwave 12/DirectorShockwave.bundle"
"/Library/Application Support/Adobe/Shockwave 12/Xtras"
"/Library/Internet Plug-Ins/DirectorShockwave.plugin"
)
empty_directories_to_remove=(
"/Library/Application Support/Adobe/Shockwave 12"
"/Library/Application Support/Adobe"
)
pkg_receipts_to_remove=(
"com.adobe.shockwave"
"adobe.adobeShockwavePlayer.shockwave11.pkg"
"adobe.adobeShockwavePlayer.shockwave12.pkg"
)
casper_receipts_pattern='^Shockwave_Installer_Full_.*.[m]?pkg$'
function RemovePrefFiles () {
# custom pref removal function
return 0
}
#
# NOTHING TO CHANGE BELOW HERE
#
#################
# get script parameters
targetDrive="${1}"
computerName="${2}"
userName="${3}"
bRemovePrefs="${4}"
# Variables
CASPER_RECEIPT_PATH="${targetDrive}/Library/Application Support/JAMF/Receipts"
#################
# check script parameters
if [[ "${targetDrive}" == "" ]]; then
echo "No Target Drive set."
exit 1
fi
# check if we also should clear the preferences
if [[ "${bRemovePrefs}" != "yes" ]]; then
bRemovePrefs=""
fi
#################
# get the first non-root loginwindow user
# TODO: get all users and and unload agents for all of them
current_user=$( ps aux|grep "loginwindow [c]onsole"|grep -v "^root"|head -n 1|awk '{print $1}' )
if [[ "${current_user}" == "" ]]; then
current_user_loginpid=""
echo "Could not determine current Aqua user - not loading any LaunchAgents"
else
current_user_loginpid=$( ps ax -U "${current_user}"|grep "loginwindow [c]onsole"|head -n 1|awk '{print $1}' )
echo "Current Aqua user is ${current_user}, loginwindow pid is ${current_user_loginpid}"
fi
#################
# remove LaunchDaemons
for item in "${launchdaemons_to_remove[@]}"; do
fs_item="${targetDrive}/Library/LaunchDaemons/${item}.plist"
if [[ "${targetDrive}" == "/" ]]; then
launchdRunning=$( launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl remove "${item}"
&& echo "Removed active LaunchDaemon ${item}"
|| echo "Error removing active LaunchDaemon ${item}"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove LaunchAgents
for item in "${launchagents_to_remove[@]}"; do
fs_item="${targetDrive}/Library/LaunchAgents/${item}.plist"
if [[ "${targetDrive}" == "/" && ${current_user_loginpid} -gt 0 ]]; then
launchdRunning=$(
launchctl bsexec "${current_user_loginpid}" chroot -u "${current_user}" /
launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl bsexec "${current_user_loginpid}" chroot -u "${current_user}" / launchctl remove "${item}"
&& echo "Removed active LaunchAgent ${item} for user $current_user"
|| echo "Error removing active LaunchAgent ${item} for user $current_user"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove directories
for item in "${directory_trees_to_remove[@]}"; do
fs_item="${targetDrive}/${item}"
if [[ -d "${fs_item}" ]]; then
rm -r "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
#################
# remove empty directories
for item in "${empty_directories_to_remove[@]}"; do
fs_item="${targetDrive}/${item}"
if [[ -d "${fs_item}" ]]; then
rmdir "${fs_item}" 2>/dev/null
&& echo "Removed empty directory ${fs_item}"
fi
done
#################
# remove receipts
for item in "${pkg_receipts_to_remove[@]}"; do
/usr/sbin/pkgutil --volume "${targetDrive}" --forget "${item}" 2>/dev/null
done
#################
# remove casper receipts (empty files in CASPER_RECEIPT_PATH)
IFS=$'
'
if [[ "${casper_receipts_pattern}" != "" ]]; then
casper_receipts=(
$( /bin/ls "${CASPER_RECEIPT_PATH}" 2>/dev/null |
/usr/bin/grep "${casper_receipts_pattern}" )
)
for item in "${casper_receipts[@]}"; do
if [[ -f "${CASPER_RECEIPT_PATH}/${item}" ]]; then
/bin/rm "${CASPER_RECEIPT_PATH}/${item}"
&& echo "Removed ${CASPER_RECEIPT_PATH}/${item}"
|| echo "Error removing ${CASPER_RECEIPT_PATH}/${item}"
fi
done
IFS=$OLDIFS
fi
#################
# remove preferences
if [[ "${bRemovePrefs}" == "yes" ]]; then
echo "Removing preferences"
RemovePrefFiles
fi
#################
# remove final LaunchDaemons
for item in "${launchdaemons_to_remove_at_end[@]}"; do
fs_item="${targetDrive}/Library/LaunchDaemons/${item}.plist"
if [[ "${targetDrive}" == "/" ]]; then
launchdRunning=$( launchctl list 2>&1 |
/usr/bin/grep -c "^.*[[:space:]]${item}$" 2>/dev/null )
if [[ ${launchdRunning} -gt 0 ]]; then
launchctl remove "${item}"
&& echo "Removed active final LaunchDaemon ${item}"
|| echo "Error removing active final LaunchDaemon ${item}"
fi
fi
if [[ -e "${fs_item}" ]]; then
rm -f "${fs_item}"
&& echo "Removed ${fs_item}"
|| echo "Error removing ${fs_item}"
fi
done
exit 0
Posted on 10-06-2015 03:28 PM
@cvgs First several "Wow's". Wow 1= Super fast accurate response... THANKS Wow 2= Awesome script! I had to bring my Code guru (Jon) over just to help me wrap my head around it. I can see using this as a template in the future. So again thanks! I/we did make just a few changes to get it to perform as we expected.