#! /bin/bash

echo "Removing AppImageLauncher as interpreter for AppImages"

UPDATE_BINFMTS=update-binfmts

if ! (type "$UPDATE_BINFMTS" &>/dev/null) && ! (which "$UPDATE_BINFMTS" &>/dev/null); then
    UPDATE_BINFMTS=/usr/lib/appimagelauncher/update-binfmts

    if [ ! -f "$UPDATE_BINFMTS" ]; then
        UPDATE_BINFMTS=
    fi
fi

if [ "$UPDATE_BINFMTS" != "" ]; then
    (set -x; "$UPDATE_BINFMTS" --package appimage --remove appimage-type1 /usr/bin/AppImageLauncher)
    (set -x; "$UPDATE_BINFMTS" --package appimage --remove appimage-type2 /usr/bin/AppImageLauncher)
else
    (set -x; systemctl restart systemd-binfmt)
fi

update_notifier="/usr/share/update-notifier/notify-reboot-required"
if [ -x "$update_notifier" ]; then
    "$update_notifier"
fi

cat <<EOF
#####################################################
#                                                   #
#  NOTE: you need to reboot your computer in order  #
#  to complete the uninstallation                   #
#                                                   #
#  (If you see this message during an upgrade:      #
#  don't worry, you do not have to take any         #
#  action, no reboot required!)                     #
#                                                   #
#####################################################
EOF
