#!/bin/bash

# Usage:
#    Command: sh install.sh step1
#             sh install.sh step2

STEP=${1}

# Install
if [ "${STEP}" = "step1" ]; then
    # Add config
    echo "[INFO] Add config."
    grep "blacklist hns_roce_hw_v2" /etc/modprobe.d/blacklist.conf
    if [ $? -ne 0 ]; then
        echo "" >> /etc/modprobe.d/blacklist.conf
        echo "# iDriver" >> /etc/modprobe.d/blacklist.conf
        echo "blacklist hns_roce_hw_v2" >> /etc/modprobe.d/blacklist.conf
        echo "blacklist hns_roce" >> /etc/modprobe.d/blacklist.conf
    fi
    cat /etc/modprobe.d/blacklist.conf|egrep 'blacklist hns_roce_hw_v2|blacklist hns_roce'
    
    # Regenerate initramfs file
    echo "[INFO] Regenerate initramfs file, then please reboot."
    update-initramfs -u
    #reboot
elif [ "${STEP}" = "step2" ]; then
    # Download
    echo "[INFO] Download package."
    cd /tmp
    rm -f NIC-hisi_eth-Ubuntu18.04.1-hns3-1.0.2-aarch64.deb
    wget https://tools.mindspore.cn/productrepo/iso/ubuntu/ubuntu18.04/iDriver/TaiShanServer/onboard_driver_Ubuntu18.04.1/NIC-hisi_eth-Ubuntu18.04.1-hns3-1.0.2-aarch64.deb
    
    # Install
    echo "[INFO] Install."
    cd /tmp
    dpkg -i NIC-hisi_eth-Ubuntu18.04.1-hns3-1.0.2-aarch64.deb
    modinfo hns3
    
    # Clear
    rm -f /tmp/NIC-hisi_eth-Ubuntu18.04.1-hns3-1.0.2-aarch64.deb
fi
