183 lines
6.4 KiB
Plaintext
183 lines
6.4 KiB
Plaintext
|
|
|
|
#
|
|
# Original by Konstantinos Sykas <ksykas@gmail.com> (26-Mar-2011)
|
|
#
|
|
# Type: shell script
|
|
# Description: The Oolite uninstall script. During installation the "setup" script
|
|
# adds a header defining the environment variables used below.
|
|
#
|
|
# 2011-04-03: Updated to facilitate rsync repository setup for oolite-update script
|
|
# 2014-06-20: Enhanced error code generation to facilitate error recognition
|
|
# Updated to remove ManagedAddOns folder tree
|
|
# 2014-07-13: Ambiguous warning message is displayed when Oolite/ManagedAddOns
|
|
# folder does not exist. Added check before trying to remove it.
|
|
# Updated error handling to report the folders which were not empty and
|
|
# could not be removed.
|
|
# 2014-07-14: Replaced '~' by $HOME environment variable.
|
|
# Fixed a warning visualization issue.
|
|
# 2014-07-15: Added checks to remove Oolite and Managed Add-ons parent folders only
|
|
# if all subfolders are removed.
|
|
#
|
|
|
|
|
|
FOLDER_MASK_DOC=0x01
|
|
FOLDER_MASK_ADDONS=0x02
|
|
FOLDER_MASK_APP=0x04
|
|
FOLDER_MASK_OOLITE=0x08
|
|
FOLDER_MASK_MNGADDONS=0x10
|
|
FOLDER_MASK_MNGOOLITE=0x20
|
|
|
|
rm_rc=0 # Initialize (r)e(m)ove (r)eturn (c)ode counter
|
|
SELF_PATH=$(cd $(dirname $0); pwd -P)
|
|
SELF_FILENAME=$(basename $0)
|
|
echo -n "Removing Oolite${TRUNK} from \"${SELF_PATH}\"... "
|
|
|
|
# Refuse automated uninstall of a relocated installation
|
|
if [ "${SELF_PATH}" != "$HOME/${INSTALL_ROOT_USERHOME}/${OOLITE_ROOT_NAME}" ] && [ "${SELF_PATH}" != "${INSTALL_ROOT_SYSTEMWIDE}/${OOLITE_ROOT_NAME}" ]
|
|
then
|
|
echo
|
|
echo "Error: Oolite${TRUNK} installation has been relocated from its original path."
|
|
exit ${ERROR_CODE_UNINSTALL_FAILED}
|
|
fi
|
|
|
|
# Get user root-status and setup env accordingly
|
|
if [ `id -u` -eq 0 ]
|
|
then
|
|
USER_IS_ROOT=1
|
|
|
|
# Setup env for root uninstall
|
|
OOLITE_ROOT="${INSTALL_ROOT_SYSTEMWIDE}/${OOLITE_ROOT_NAME}"
|
|
STARTUP_SCRIPTS_PATH="${STARTUP_SCRIPTS_PATH_SYSTEMWIDE}"
|
|
DESKTOP_MODE="system"
|
|
|
|
# Check if we have the right privileges to proceed with removal
|
|
if [ "${SELF_PATH}" != "${OOLITE_ROOT}" ]
|
|
then
|
|
echo
|
|
echo "Error: You are root and try to uninstall a home-directory Oolite${TRUNK} installation."
|
|
echo " If you're using sudo, you don't need it this time."
|
|
exit ${ERROR_CODE_UNINSTALL_FAILED}
|
|
fi
|
|
else
|
|
# Setup env for user home directory uninstall
|
|
OOLITE_ROOT="$HOME/${INSTALL_ROOT_USERHOME}/${OOLITE_ROOT_NAME}"
|
|
STARTUP_SCRIPTS_PATH="$HOME/${STARTUP_SCRIPTS_PATH_USERHOME}"
|
|
DESKTOP_MODE="user"
|
|
|
|
# Check if we have the right privileges to proceed with removal
|
|
if [ "${SELF_PATH}" != "${OOLITE_ROOT}" ]
|
|
then
|
|
echo
|
|
echo "Error: Oolite${TRUNK} was installed by root, so you must be root to uninstall it."
|
|
exit ${ERROR_CODE_UNINSTALL_FAILED}
|
|
fi
|
|
fi
|
|
|
|
|
|
# Remove Oolite
|
|
|
|
echo
|
|
cd ${OOLITE_ROOT}
|
|
|
|
# Remove Oolite menu
|
|
xdg-desktop-menu uninstall --novendor --mode ${DESKTOP_MODE} oolite${TRUNK}.org.desktop 1> /dev/null 2> /dev/null
|
|
xdg-icon-resource uninstall --novendor --mode ${DESKTOP_MODE} --size ${ICON_SIZE} oolite${TRUNK}.org-icon.png 1> /dev/null 2> /dev/null
|
|
|
|
# Only remove known files from oolite root and oolite startup scripts path
|
|
rm -f release.txt 1> /dev/null 2> /dev/null
|
|
rm -f ${STARTUP_SCRIPTS_PATH}/oolite${TRUNK} 1> /dev/null 2> /dev/null
|
|
rm -f ${STARTUP_SCRIPTS_PATH}/oolite${TRUNK}-update 1> /dev/null 2> /dev/null
|
|
|
|
# Unconditionally remove FreeDesktop/ in case setup left it there
|
|
rm -rf FreeDesktop/ 1> /dev/null 2> /dev/null
|
|
|
|
# Unconditionally remove oolite-deps/
|
|
rm -rf oolite-deps/ 1> /dev/null 2> /dev/null
|
|
|
|
# Only remove known files from doc/ and
|
|
# delete doc/ if it is empty
|
|
rm -f doc/AdviceForNewCommanders.pdf 1> /dev/null 2> /dev/null
|
|
rm -f doc/CHANGELOG.TXT 1> /dev/null 2> /dev/null
|
|
rm -f doc/OoliteReadMe.pdf 1> /dev/null 2> /dev/null
|
|
rm -f doc/OoliteRS.pdf 1> /dev/null 2> /dev/null
|
|
rm -f doc/README-PREAMBLE.TXT 1> /dev/null 2> /dev/null
|
|
rm -f doc/README.TXT 1> /dev/null 2> /dev/null
|
|
rmdir doc/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_DOC))
|
|
echo "Warning: Unable to remove ${OOLITE_ROOT}/doc/. The folder is not empty."
|
|
fi
|
|
|
|
# Only remove add-on placed by setup and
|
|
# delete AddOns/ if it is empty
|
|
rm -rf AddOns/Basic-debug.oxp/ 1> /dev/null 2> /dev/null
|
|
rmdir AddOns/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_ADDONS))
|
|
echo "Warning: Unable to remove ${OOLITE_ROOT}/AddOns/. The folder is not empty."
|
|
fi
|
|
|
|
# Only remove known files from oolite.app/ and
|
|
# unconditionally remove oolite.app/Resources/ and
|
|
# delete oolite.app/ if it is empty
|
|
rm -f oolite.app/oolite 1> /dev/null 2> /dev/null
|
|
rm -f oolite.app/oolite-update 1> /dev/null 2> /dev/null
|
|
rm -f oolite.app/oolite-wrapper 1> /dev/null 2> /dev/null
|
|
rm -rf oolite.app/Resources/ 1> /dev/null 2> /dev/null
|
|
rmdir oolite.app/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_APP))
|
|
echo "Warning: Unable to remove ${OOLITE_ROOT}/oolite.app/. The folder is not empty."
|
|
fi
|
|
|
|
# Remove uninstall script
|
|
rm -f ${SELF_FILENAME}
|
|
|
|
# Remove Oolite/ root folder if it is empty
|
|
if [ $rm_rc -eq 0 ]; then # Proceed to parent folder removal only if subfolders are removed
|
|
rmdir ${OOLITE_ROOT}/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_OOLITE))
|
|
echo "Warning: Unable to remove ${OOLITE_ROOT}/. The folder is not empty."
|
|
fi
|
|
fi
|
|
|
|
# Remove Oolite/ManagedAddOns folder if it is empty
|
|
if [ -d "$HOME/GNUstep/Library/ApplicationSupport/Oolite" ]; then
|
|
if [ -d "$HOME/GNUstep/Library/ApplicationSupport/Oolite/ManagedAddOns" ]; then
|
|
rmdir $HOME/GNUstep/Library/ApplicationSupport/Oolite/ManagedAddOns/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_MNGADDONS))
|
|
echo "Warning: Unable to remove $HOME/GNUstep/Library/ApplicationSupport/Oolite/ManagedAddOns/. The folder is not empty."
|
|
fi
|
|
fi
|
|
|
|
subfolders_deleted=$(($rm_rc & $FOLDER_MASK_MNGADDONS))
|
|
if [ $subfolders_deleted -eq 0 ]; then # Proceed to parent folder removal only if subfolder is removed
|
|
rmdir $HOME/GNUstep/Library/ApplicationSupport/Oolite/ 1> /dev/null 2> /dev/null
|
|
if [ $? -ne 0 ]
|
|
then
|
|
rm_rc=$(($rm_rc+$FOLDER_MASK_MNGOOLITE))
|
|
echo "Warning: Unable to remove $HOME/GNUstep/Library/ApplicationSupport/Oolite/. The folder is not empty."
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
|
|
# Finished uninstall!
|
|
if [ $rm_rc -ne 0 ]
|
|
then
|
|
echo "Finished with warnings."
|
|
else
|
|
echo "Done."
|
|
fi
|
|
|
|
# Exit with grace
|
|
exit $rm_rc
|