######################################################################
#### function: install dependencies
####author:danial_chen
####create date:2019-11-07
####modify date:2019-11-07
######################################################################
#/bin/bash
#useage: sh installdependencies.sh

## ENV ##
pd=$PWD

set -e

os=${1}
test -z ${os} && echo "操作系统为空" && exit 1

## install dependencies ##
if [ -f dependencies.tar.gz ]; then
  tar -zxvf dependencies.tar.gz
fi
# 判断系统
if [[ ${os} == "ubuntu" ]]; then
  apt install -y libssl-dev sshpass make zlib1g zlib1g-dev gcc g++ libtool libpcre3 libpcre3-dev net-tools libreadline-dev libncurses5-dev locales unzip cron gawk sysstat iputils-ping gdb
  if [ $? -eq 1 ]; then
    exit 1
  fi
else
  yum --disablerepo='*' --enablerepo=singularity-base-repo install -y openssl openssl-devel sshpass make zlib zlib-devel gcc gcc-c++ libtool pcre pcre-devel net-tools readline-devel ncurses-devel libatomic unzip gdb || true
  if [ $? -eq 1 ]; then
    exit 1
  fi
  if [[ ${os} == "centos" ]]; then
    yum --disablerepo='*' --enablerepo=singularity-base-repo install -y sysstat ip-utils
  else
    yum --disablerepo='*' --enablerepo=singularity-base-repo install -y sysstat iputils
  fi
  if [ $? -eq 1 ]; then
    exit 1
  fi
fi

## echo install resault ##
echo "dependencies install success!"
