diff --git a/macports/postinstall_with_uninstall b/macports/postinstall_with_uninstall index 3ef77a6d..9d7e15d7 100755 --- a/macports/postinstall_with_uninstall +++ b/macports/postinstall_with_uninstall @@ -1,82 +1,87 @@ #!/usr/bin/env bash INSTDIR=$(echo "$2/opt/rkward" | sed 's#//#/#g') INSTALLER_USER=$(stat -f '%Su' "${HOME}") AGENT="org.macports.kf5-rkward" RKWARDSHARE="${INSTDIR}/share/rkward" SCRIPTDIR="${RKWARDSHARE}/macOS" PLISTSOURCE="${SCRIPTDIR}/${AGENT}.plist" AGENTSDIR="${HOME}/Library/LaunchAgents" PLISTTARGET="${AGENTSDIR}/${AGENT}.plist" UNINSTALLER="${SCRIPTDIR}/uninstall.scpt" "${INSTDIR}/bin/update-mime-database" -V "${INSTDIR}/share/mime" if [ -d "${RKWARDSHARE}" ] ; then mkdir -p "${SCRIPTDIR}" # generate uninstall script cat < "${UNINSTALLER}" set RKWardDir to "${INSTDIR}" +set appInTrash to POSIX path of (path to trash) & "rkward.app/Contents/Info.plist" set haveRKWard to false +set haveTrash to false tell application "System Events" + if exists file appInTrash then + set haveTrash to true + end if if exists folder RKWardDir then set haveRKWard to true end if end tell -if haveRKWard then +if haveTrash and haveRKWard then try - display dialog "Most of RKWard's installation resides in " & RKWardDir & ". To uninstall RKWard completely that directory should be deleted as well.\n\nDo you want to remove it now?\n\nIf you choose this option, all files below " & RKWardDir & " will not be moved to Trash but removed permanently!" buttons {"No, keep for now", "Yes, completely remove"} default button "Yes, completely remove" cancel button "No, keep for now" with title "Remove RKWard completely?" with icon caution + display dialog "Most of RKWard's installation resides in " & RKWardDir & ". To completely uninstall RKWard, that directory should be deleted as well.\n\nIf you choose this option, all files below " & RKWardDir & " will not be moved to Trash but removed permanently!\n\nDo you want to remove " & RKWardDir & " now?" buttons {"No, keep for now", "Yes, completely remove"} default button "Yes, completely remove" cancel button "No, keep for now" with title "Remove RKWard completely?" with icon caution set {buttonReturned} to {button returned of result} if buttonReturned is "Yes, completely remove" then try do shell script "rm -rf \"" & RKWardDir & "\"" with administrator privileges set removeRKWardOK to true on error set removeRKWardOK to false display alert "Failed removing " & RKWardDir & "!" end try if removeRKWardOK then try - do shell script "launchctl unload \"${PLISTTARGET}\"" do shell script "rm \"${PLISTTARGET}\"" + do shell script "launchctl remove \"${AGENT}\"" end try end if end if end try end if EOF # generate watch job cat < "${PLISTSOURCE}" Label ${AGENT} WatchPaths ~/.Trash/rkward.app ProgramArguments osascript ${UNINSTALLER} KeepAlive EOF # link watch job if [ -f "${PLISTSOURCE}" ] ; then if ! [ -d "${AGENTSDIR}" ] ; then sudo -u "${INSTALLER_USER}" mkdir -p "${AGENTSDIR}" fi if ! [ -f "${PLISTTARGET}" ] ; then sudo -u "${INSTALLER_USER}" ln -s "${PLISTSOURCE}" "${PLISTTARGET}" fi if ! [ $(launchctl list | grep ${AGENT}) ] ; then sudo -u "${INSTALLER_USER}" launchctl load -w "${PLISTTARGET}" fi fi fi exit 0