if boolean_is_true "$LOCAL_APPS"; then
    # Clean up cups config
    [ -r "/etc/cups/client.conf" ] && rm -f /etc/cups/client.conf

    # Clean up localapps menu
    if boolean_is_true "$LOCAL_APPS_MENU" && [ -n "${TMP_XDG_MENU}" ]; then
        if [ -S ${LDM_SOCKET} ]; then
            ssh -S ${LDM_SOCKET} ${LDM_SERVER} rm -rf "${TMP_XDG_MENU}"
        fi
    fi

    # Unmount sshfs and remove the mount dir
    if [ -n "$SSHFS_HOME" ]; then
        if  [ -n "$LDM_USERNAME" ]; then
            # The user processes need to be terminated before $LDM_HOME gets
            # unmounted, otherwise they end up writing their data in the local
            # tmpfs filesystem.
            # Give them up to 3 seconds to terminate, then kill them.
            pkill -u "$LDM_USERNAME"
            i=0
            while pgrep -u "$LDM_USERNAME" >/dev/null; do
                if [ "$i" -ge 3 ]; then
                    pkill -KILL -u "$LDM_USERNAME"
                    break
                fi
                sleep 1
                i=$(($i+1))
            done
        fi
        fusermount -uqz ${LDM_HOME}
        rmdir ${LDM_HOME}
    fi

    # Unmount other mounts
    if [ -n "${LOCAL_APPS_EXTRAMOUNTS}" ]; then
        oldifs="${IFS-not set}"
        IFS=','
        for extradir in ${LOCAL_APPS_EXTRAMOUNTS}; do
            fusermount -uqz "${extradir}"
            rmdir "${extradir}"
        done
        test "$oldifs" = "not set" && unset IFS || IFS="$oldifs"
    fi
fi

# Copy back passwd, group, shadow and gshadow, except for multiseat systems
if [ "$(pgrep -cf "/usr/share/ldm/ldm-script xsession")" -eq 0 ]; then
    for i in passwd group shadow gshadow; do
        test -e "/run/ltsp/$i" && cp "/run/ltsp/$i" "/etc/$i"
    done
fi

# Clean up remote apps tmpdir
if boolean_is_true "${REMOTE_APPS}" && [ -n "${REMOTE_APPS_TMPDIR}" ] ; then
    fusermount -uqz "${REMOTE_APPS_TMPDIR}"
    rmdir "${REMOTE_APPS_TMPDIR}"
    if [ -w "/usr/lib/mime/packages/ltsp" ]; then
        rm -f /usr/lib/mime/packages/ltsp
        update-mime
    fi
fi
