#!/bin/bash

Get_Dist_Name()
{
    if grep -Eqii "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
        DISTRO='CentOS'
        PM='yum'
    elif grep -Eqi "Red Hat Enterprise Linux Server" /etc/issue || grep -Eq "Red Hat Enterprise Linux Server" /etc/*-release; then
        DISTRO='RHEL'
        PM='yum'
    elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun" /etc/*-release; then
        DISTRO='Aliyun'
        PM='yum'
    elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
        DISTRO='Fedora'
        PM='yum'
    elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
        DISTRO='Debian'
        PM='apt'
    elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
        DISTRO='Raspbian'
        PM='apt'
    elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
        DISTRO='Ubuntu'
        PM='apt'
    elif grep -Eqi "UnionTech" /etc/issue || grep -Eq "UnionTech" /etc/*-release; then
        DISTRO='UnionTech'
        PM='apt'
    elif grep -Eqi "Kylin" /etc/issue || grep -Eq "Kylin" /etc/*-release; then
        DISTRO='Kylin'
        PM='apt'
    elif grep -Eq "RED OS" /etc/*-release; then
        DISTRO='RED OS'
        PM='dnf'
    elif grep -Eq "ALT" /etc/*-release; then
        DISTRO='ALT'
        PM='apt-get'
    else
        DISTRO='unknow'
    fi
}

Get_Dist_Name

echo "detected OS: $DISTRO"

if grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
    #echo "create links"
    cp -f /opt/apps/com.antutu.benchmark/entries/icons/hicolor/512x512/apps/com.antutu.benchmark.png /usr/share/pixmaps

    # for all users
    ln -sf /opt/apps/com.antutu.benchmark/entries/applications/com.antutu.benchmark.desktop /usr/share/applications/com.antutu.benchmark.desktop
fi


if grep -Eqi "Kylin" /etc/issue || grep -Eq "Kylin" /etc/*-release; then
    #echo "create links"
    cp -f /opt/apps/com.antutu.benchmark/entries/icons/hicolor/512x512/apps/com.antutu.benchmark.png /usr/share/pixmaps

    # for all users
    ln -sf /opt/apps/com.antutu.benchmark/entries/applications/com.antutu.benchmark.desktop /usr/share/applications/com.antutu.benchmark.desktop
fi

if grep -Eq "RED OS" /etc/*-release; then
    #echo "create links"
    cp -f /opt/apps/com.antutu.benchmark/entries/icons/hicolor/512x512/apps/com.antutu.benchmark.png /usr/share/pixmaps
    # for all users
    ln -sf /opt/apps/com.antutu.benchmark/entries/applications/com.antutu.benchmark.desktop /usr/share/applications/com.antutu.benchmark.desktop
    sudo $PM install google-noto-sans-cjk-fonts
fi

if grep -Eq "ALT" /etc/*-release; then
    #echo "create links"
    cp -f /opt/apps/com.antutu.benchmark/entries/icons/hicolor/512x512/apps/com.antutu.benchmark.png /usr/share/pixmaps
    # for all users
    ln -sf /opt/apps/com.antutu.benchmark/entries/applications/com.antutu.benchmark.desktop /usr/share/applications/com.antutu.benchmark.desktop
fi
