#!/bin/bash

set -e

# 获取操作系统的 ID
distro_id=$(grep -w ID /etc/os-release | cut -d= -f2 | tr -d '"')

ARCH=`uname -m`

case "${ARCH}" in
    x86_64)
        ;;
    aarch64)
        ;;
    *)
        echo "unknown cpu"
        exit -1
        ;;
esac


vlcVersion=3.0.16.2-1
libVlcName=libidste-vlc-player
libVlcRpmName=${libVlcName}-${vlcVersion}.${ARCH}.rpm

if [[ `rpm -qa ${libVlcName} | wc -l` == 0 ]]
then
    echo "install ${libVlcName} ${libVlcRpmName} now"
    
    wget http://mirrors.idste.org/rpm/common/${ARCH}/${libVlcRpmName}
    rpm -ivh ${libVlcRpmName} --nodeps
else
    curName=`rpm -qa ${libVlcName}`
    echo "cur vlc name ${curName}"
    curVersion=`rpm -qi libidste-vlc-player | grep Version | awk -F ":" '{print $2}' | awk -F " " '{print $1}'`
    if [[ ${curVersion} != `echo ${vlcVersion} | awk -F "-" '{print $1}'` ]]
    then
        echo "upgrade ${libVlcName} to ${libVlcRpmName}  now"
        wget http://dev.idste.org:3284/rpm/common/${ARCH}/${libVlcRpmName}
	rpm -Uvh ${libVlcRpmName} --nodeps --force
    fi
fi

echo "check and install ${libVlcName} success"

