#! /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
