cd /root
mkdir fengyixing
cd fengyixing
LOG_HEAD "Install base tools."
yum install -y vim \
wget \
xz \
net-tools \
git \
curl \
subversion \
ntpdate \
unzip \
tzdata \
tcl \
sudo \
bzip2 \
passwd \
tar \
java-1.8.0 \
tree \
nfs-utils
# openssh-clients \ 存在版本降级问题，导致exit之后无法重新ssh登录

LOG_HEAD "Install compile tools."
yum install -y gcc \
gcc-c++ \
gcc-gfortran \
make \
gmp-devel \
patch \
autoconf \
libtool \
automake \
numactl \
numactl-devel

LOG_HEAD "Install dependency lib of python."
yum install -y libffi-devel \
zlib-devel \
bzip2-devel \
openssl-devel \
ncurses-devel \
sqlite-devel \
readline-devel \
gdbm-devel \
xz-devel \
mesa-libGL

LOG_HEAD "Install dependency lib of opencv-python(pip)."
yum install -y libSM

LOG_HEAD "Install dependency lib of pillow(pip)."
yum install -y libjpeg-turbo-devel

LOG_HEAD "Install dependency lib of matplotlib(pip)."
yum install -y freetype-devel

LOG_HEAD "Install dependency lib of scipy(pip)."
yum install -y blas \
lapack \
atlas
yum install -y openblas \
atlas-devel

LOG_HEAD "Install dependency lib(hdf5) of tables(pip)."
cd /root/fengyixing
wget http://tools.mindspore.cn/tools/ci/hdf5/hdf5-1.12.0/hdf5-1.12.0.tar.gz
tar -zxf hdf5-1.12.0.tar.gz
cd /tmp/hdf5-1.12.0
./configure --prefix=/usr/local
make -j16
make install -j16

LOG_HEAD "Install gcc."
cd /root/fengyixing
mkdir gcc
cd gcc
wget http://tools.mindspore.cn/tools/build/gcc/gcc-7.3.0/source/gcc-7.3.0.tar.gz
wget http://tools.mindspore.cn/tools/build/gcc/gcc-7.3.0/source/isl-0.16.1.tar.bz2
wget http://tools.mindspore.cn/tools/build/gcc/gcc-7.3.0/source/gmp-6.1.0.tar.bz2
wget http://tools.mindspore.cn/tools/build/gcc/gcc-7.3.0/source/mpfr-3.1.4.tar.gz
wget http://tools.mindspore.cn/tools/build/gcc/gcc-7.3.0/source/mpc-1.0.3.tar.gz
tar -zxf gcc-7.3.0.tar.gz
tar -zxf mpc-1.0.3.tar.gz
tar -zxf mpfr-3.1.4.tar.gz
tar -jxf gmp-6.1.0.tar.bz2
tar -jxf isl-0.16.1.tar.bz2
mv gmp-6.1.0 gcc-7.3.0/gmp
mv isl-0.16.1 gcc-7.3.0/isl
mv mpc-1.0.3 gcc-7.3.0/mpc
mv mpfr-3.1.4 gcc-7.3.0/mpfr
mkdir -p /usr/local/gcc/gcc730
cd gcc-7.3.0
mkdir build
cd build
../configure --prefix=/usr/local/gcc/gcc730 -enable-checking=release -enable-languages=c,c++ -disable-multilib
make -j32
make install-strip
chmod 755 -R /usr/local/gcc
cd /usr/local/gcc/gcc730/bin
ln -s gcc cc
grep "export PATH=/usr/local/gcc/gcc730/bin" ~/.bashrc
if [ $? -ne 0 ]; then
    echo "" >> ~/.bashrc
    echo "# GCC env" >> ~/.bashrc
    echo "export PATH=/usr/local/gcc/gcc730/bin:\$PATH" >> ~/.bashrc
    echo "export LD_LIBRARY_PATH=/usr/local/gcc/gcc730/lib64:\$LD_LIBRARY_PATH" >> ~/.bashrc
	export LD_LIBRARY_PATH=/usr/local/gcc/gcc730/lib64:$LD_LIBRARY_PATH
	export PATH=/usr/local/gcc/gcc730/bin:$PATH
fi

LOG_HEAD "Install python."
PYTHON_PATH=/usr/local/python/python375
cd /root/fengyixing
wget http://tools.mindspore.cn/tools/build/python/python-3.7.5/Python-3.7.5.tar.xz
tar -xf Python-3.7.5.tar.xz
cd Python-3.7.5
./configure --prefix=${PYTHON_PATH} --enable-shared
umask 022 && make -j16 && make install -j16
chmod 755 /usr/local/python
cd ${PYTHON_PATH}/bin
rm -f python
rm -f pip
ln -s python3.7 python
ln -s pip3.7 pip
grep "export PATH=${PYTHON_PATH}/bin" ~/.bashrc
if [ $? -ne 0 ]; then
    echo "" >> ~/.bashrc
    echo "# Python env" >> ~/.bashrc
    echo "export PATH=${PYTHON_PATH}/bin:\$PATH" >> ~/.bashrc
fi

# Set pip source
LOG_HEAD "Set pip source."
mkdir /root/.pip
echo "[global]" > /root/.pip/pip.conf
echo "index-url=https://mirrors.aliyun.com/pypi/simple" >> /root/.pip/pip.conf
echo "trusted-host=mirrors.aliyun.com" >> /root/.pip/pip.conf
echo "timeout=120" >> /root/.pip/pip.conf
cat /root/.pip/pip.conf

LOG_HEAD "Install pip package for sault."
export PATH=/usr/local/python/python375/bin:$PATH
umask 022 && pip3 install --upgrade pip
umask 022 && pip3 install paramiko
umask 022 && pip3 install pyyaml
umask 022 && pip3 install scp
umask 022 && pip3 install flask
umask 022 && pip3 install requests
umask 022 && pip3 install flask_restful
umask 022 && pip3 install argparse
umask 022 && pip3 install pytest
umask 022 && pip3 install virtualenv
umask 022 && pip3 install nose
pip3 list

LOG_HEAD "Install pip package of mindspore."
export PATH=/usr/local/python/python375/bin:$PATH
umask 022 && pip3 install 'wheel==0.34.2'
umask 022 && pip3 install 'pybind11==2.5.0'
umask 022 && pip3 install 'pytest==5.4.3'
umask 022 && pip3 install 'pytest-xdist==1.32.0'
umask 022 && pip3 install 'numpy>=1.17.0'
umask 022 && pip3 install 'pillow>=6.2.0'
umask 022 && pip3 install 'protobuf>=3.8.0'
umask 022 && pip3 install 'asttokens>=1.1.13'
umask 022 && pip3 install 'scipy==1.5.3'
umask 022 && pip3 install 'easydict>=1.9'
umask 022 && pip3 install 'sympy>=1.4'
umask 022 && pip3 install 'cffi>=1.13.2'
umask 022 && pip3 install 'decorator>=4.4.0'
umask 022 && pip3 install 'astunparse>=1.6.3'
umask 022 && pip3 install 'packaging>=20.0'
umask 022 && pip3 install 'bs4'
umask 022 && pip3 install 'matplotlib>=3.1.3'
umask 022 && pip3 install 'sklearn>=0.0'
umask 022 && pip3 install 'pandas>=1.0.4'
umask 022 && pip3 install 'pycocotools>=2.0.0'
umask 022 && pip3 install 'tables>=3.6.1'
umask 022 && pip3 install 'attrdict>=2.0.1'
umask 022 && pip3 install 'Click>=7.0'
umask 022 && pip3 install 'Flask>=1.1.1'
umask 022 && pip3 install 'Flask-Cors>=3.0.8'
umask 022 && pip3 install 'google-pasta>=0.1.8'
umask 022 && pip3 install 'gunicorn>=19.9.0'
umask 022 && pip3 install 'itsdangerous>=1.1.0'
umask 022 && pip3 install 'Jinja2>=2.10.1'
umask 022 && pip3 install 'MarkupSafe>=1.1.1'
umask 022 && pip3 install 'marshmallow>=2.19.2'
umask 022 && pip3 install 'psutil>=5.6.1'
umask 022 && pip3 install 'six>=1.12.0'
umask 022 && pip3 install 'Werkzeug>=1.0.0'
umask 022 && pip3 install 'tabulate>=0.8.6'
umask 022 && pip3 install 'grpcio>=1.27.3'
umask 022 && pip3 install 'treelib>=1.6.1'
umask 022 && pip3 install 'scikit-learn>=0.21.2'
umask 022 && pip3 install 'pyyaml>=5.3.1'
umask 022 && pip3 install 'yapf>=0.30.0'
pip3 list

pip install mmcv
pip install opencv-python==4.6.0.66
pip install opencv-python-headless==4.6.0.66
umask 022 && pip3 install torch==1.8.1
umask 022 && pip3 install 'torchvision==0.2.2.post3'
pip3 list

LOG_HEAD "Install cmake."
cd /root/fengyixing
wget http://tools.mindspore.cn/tools/build/cmake/cmake-3.18.3/cmake-3.18.3.tar.gz
tar -zxf cmake-3.18.3.tar.gz
cd cmake-3.18.3
./bootstrap --prefix=/usr/local/cmake --parallel=16
make -j16
make install -j16
cd ..
chmod 755 -R /usr/local/cmake
grep "export PATH=/usr/local/cmake/bin" ~/.bashrc
if [ $? -ne 0 ]; then
    echo "" >> ~/.bashrc
    echo "# Cmake env" >> ~/.bashrc
    echo "export PATH=/usr/local/cmake/bin:\$PATH" >> ~/.bashrc
fi
    
LOG_HEAD "Install nodejs."
cd /root/fengyixing
PACKAGE_NAME="node-v12.18.4-linux-arm64"
wget https://mirrors.huaweicloud.com/nodejs/v12.18.4/${PACKAGE_NAME}.tar.gz
tar -zxf ${PACKAGE_NAME}.tar.gz
rm -rf /usr/local/nodejs
mkdir -p /usr/local/nodejs
mv ${PACKAGE_NAME} /usr/local/nodejs/
chmod 755 -R /usr/local/nodejs
ln -sf /usr/local/nodejs/${PACKAGE_NAME}/bin/node /usr/bin/node
ln -sf /usr/local/nodejs/${PACKAGE_NAME}/bin/npm /usr/bin/npm
npm config set registry https://mirrors.huaweicloud.com/repository/npm
npm config get registry
npm info express
npm cache clean -f

LOG_HEAD "Install ccache."
cd /root/fengyixing
wget http://tools.mindspore.cn/tools/build/ccache/ccache-3.7.12/ccache-3.7.12.tar.gz
tar -zxf ccache-3.7.12.tar.gz
cd ccache-3.7.12
./configure --prefix=/usr/local/ccache
make -j16
make install -j16
cd ..
chmod 755 -R /usr/local/ccache
rm -f /usr/local/bin/gcc
rm -f /usr/local/bin/g++
rm -f /usr/local/bin/cc
rm -f /usr/local/bin/c++
ln -s /usr/local/ccache/bin/ccache /usr/local/bin/gcc
ln -s /usr/local/ccache/bin/ccache /usr/local/bin/g++
ln -s /usr/local/ccache/bin/ccache /usr/local/bin/cc
ln -s /usr/local/ccache/bin/ccache /usr/local/bin/c++
/usr/local/ccache/bin/ccache -C
/usr/local/ccache/bin/ccache --max-size=8
/usr/local/ccache/bin/ccache -p

LOG_HEAD "Install sshpass."
cd /root/fengyixing
wget http://tools.mindspore.cn/tools/ci/sshpass/sshpass-1.06/sshpass-1.06.tar.gz
tar -zxf sshpass-1.06.tar.gz
cd sshpass-1.06
./configure
make -j16
make install

if [ -z "$(cat /etc/bashrc|grep /usr/local/gcc/gcc730)" ]; then
    echo ' ' >> /etc/bashrc
    echo '# GCC env' >> /etc/bashrc
    echo 'export LD_LIBRARY_PATH=/usr/local/gcc/gcc730/lib64:$LD_LIBRARY_PATH' >> /etc/bashrc
    echo 'export PATH=/usr/local/gcc/gcc730/bin:$PATH' >> /etc/bashrc
fi

# Create user
cd /root/fengyixing
wget --no-check-certificate https://tools.mindspore.cn/scripts/sysconfig/common/create_user.sh
bash create_user.sh -u HwHiAiUser -g HwHiAiUser -p 'mindspore@GeKo@r4Pus'
bash create_user.sh -u jenkins -g HwHiAiUser -p 'uX9#bM0@dN0AbJ9!'

# mount nfs未完成
mkdir /nfs
mount -t nfs -o vers=3,nolock 123.60.230.78:/data/nfs /nfs --verbose

# opencv依赖库
yum install mesa-libGL.aarch64 -y

# Set env(910)
# Install hccl
cd /root/fengyixing
wget --no-check-certificate https://tools.mindspore.cn/scripts/sysconfig/common/set_hccl_ip.sh
sh set_hccl_ip.sh
cat /etc/hccn.conf

# Install mpi
cd /root/fengyixing
wget --no-check-certificate https://tools.mindspore.cn/tools/run/ompi/install_ompi_euleros.sh
cd /root/fengyixing
wget --no-check-certificate https://tools.mindspore.cn/tools/run/ompi/ompi-4.0.3/ompi-4.0.3.tar.gz
tar -zxf ompi-4.0.3.tar.gz
cd ompi-4.0.3
./autogen.pl
./configure
make -j32
make install -j32
cd ..
grep "export LD_LIBRARY_PATH=/usr/local/lib:" ~/.bashrc
if [ $? -ne 0 ]; then
    echo "" >> ~/.bashrc
    echo "# ompi env" >> ~/.bashrc
    echo "export LD_LIBRARY_PATH=/usr/local/lib:\${LD_LIBRARY_PATH}" >> ~/.bashrc
fi

# Copy config(910)未完成
scp -r jenkins@8.92.9.211:/home/jenkins/config  /home/jenkins/
cd /home/jenkins/config/ && sed -i 's#8.92.9.211#61.151.139.123#g' env_config.json && cat env_config.json

# Install anti-virus未完成
cd /root/fengyixing
wget --no-check-certificate https://tools.mindspore.cn/scripts/anti-virus/installer-linuxs%28access.skylarv6.security.huawei.com_8530%29.sh
bash installer-linuxs\(access.skylarv6.security.huawei.com_8530\).sh
ps aux|grep qaxsafed

# set ssh black names
cd /etc/ssh
rm -f ssh_login_failed_host_deny.sh
wget --no-check-certificate https://tools.mindspore.cn/scripts/sysconfig/common/ssh_login_failed_host_deny.sh
ls -l /etc/ssh
bash ssh_login_failed_host_deny.sh
crontab -e
# 每分钟执行一次
* * * * * /etc/ssh/sh_login_failed_host_deny.sh

# Open core down(910)
cp /etc/profile /etc/profile_bak
sed -i '/ulimit -c 0/d' /etc/profile
echo "ulimit -c unlimited" >> /etc/profile
echo '*                     -          core                 unlimited' >> /etc/security/limits.conf
echo 'kernel.core_pattern=/home/workspace/core/core-%e-%p-%h-%t' >> /etc/sysctl.conf
echo 'jenkins hard core unlimited' >>  /etc/security/limits.conf
echo 'jenkins soft core unlimited' >>  /etc/security/limits.conf
mkdir -p /home/workspace/core
chmod 777 /home/workspace/core
sysctl -p

# install requirements
cd /root/fengyixing
# 新建requirements.txt文件，从网页https://gitee.com/mindspore/mindspore/blob/master/requirements.txt拷贝内容
# 手动删除UT的依赖执行下一步
pip install -r requirements.txt

# install pip packages
pip3 install omegaconf
pip3 install einops
pip3 install ftfy
pip3 install regex
pip3 install albumentations
pip3 install pandas
pip3 install imagesize
pip3 install toolz
pip3 install tqdm
pip3 install mpi4py==3.1.4
pip3 install projectq==0.8.0
pip3 install onnx==1.4.1

# 待解决
# 挂载nfs，拷贝数据集，拷贝sault config文件，刷海思包，更新sault，防毒脚本






