#!/bin/sh

set -e

SYSTEMD_FILE="/etc/systemd/system/yandex-sol-rtc@.service"

UPSTART_STARTER="/etc/init/yandex-sol-rtc-starter.conf"
UPSTART_WORKER="/etc/init/yandex-sol-rtc-worker.conf"

postrm_for_systemd(){
    if [ -e ${SYSTEMD_FILE} ]; then
        rm ${SYSTEMD_FILE}
    fi
}

postrm_for_upstart(){
    for i in $UPSTART_STARTER $UPSTART_WORKER; do
        if [ -e ${i} ]; then
            rm ${i}
        fi
    done
}

case "$1" in
    remove|purge)
        if [ -e /bin/systemctl -a -d /usr/lib/systemd ]; then
            postrm_for_systemd
        else
            postrm_for_upstart
        fi

    ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
