#!/bin/bash

function check_fail(){
if test $1 -ne 0; then
  echo "  Installation failed. LSB package may not be installed.
  Install LSB package and reinstall CryptoPro CSP. If it does not help, please 
  read installation documentation or contact the manufacturer: support@cryptopro.ru."
  exit $1
fi	
}


cd `dirname $0`
/bin/sh ./uninstall.sh || exit $?

case `uname -m` in
x86_64|amd64)
  ARG=64
  arch=x86_64
  ;;
*)
  arch=i486
  ;;
esac

[ -r /etc/debian_version ] && debian=1
[ -r /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release && debian=1

echo "Installing lsb-cprocsp-base-3.9.0-4.noarch.rpm..."
if test x$debian = x1; then
  alien -kci lsb-cprocsp-base-3.9.0-4.noarch.rpm || check_fail $?
else
  rpm -i lsb-cprocsp-base-3.9.0-4.noarch.rpm || check_fail $?
fi

list="lsb-cprocsp-rdr lsb-cprocsp-capilite lsb-cprocsp-kc1"
for i in $list; do
  if test x$ARG = x64 && [ -e lsb-cprocsp-rdr-64-3.9.0-4.$arch.rpm ]; then
    i="${i}-64"
  fi
  echo "Installing $i..."
  if test x$debian = x1; then
    alien -kci $i-3.9.0-4.$arch.rpm || check_fail $?
  else
    rpm -i $i-3.9.0-4.$arch.rpm || check_fail $?
  fi
done