configurations/testbed/scripts/deploy1.sh
2023-04-29 19:27:43 +08:00

91 lines
3.0 KiB
Bash

#!/bin/bash
set -ex
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
if [[ "$EUID" != "0" ]]; then
echo "Please run as root."
exit 1
fi
# resolv
systemctl disable --now systemd-resolved
rm /etc/resolv.conf
cat << EOF > /etc/resolv.conf
nameserver 192.168.16.118
nameserver 166.111.8.28
nameserver 166.111.8.29
nameserver 114.114.114.114
EOF
# preparation
apt update
apt install -y make cmake python3 python3-pip gcc-10 g++-10 dkms net-tools ethtool
ethtool -s eno1 wol g
cd /tmp
wget http://192.168.16.118/MLNX_OFED_LINUX-5.8-2.0.3.0-ubuntu22.04-x86_64.tgz
wget http://192.168.16.118/NVIDIA-Linux-x86_64-460.106.00.run
wget http://192.168.16.118/cuda_11.2.0_460.27.04_linux.run
# mlnx ofed
apt install -y pkg-config swig bison dpatch m4 libnl-3-dev autoconf automake libnl-route-3-dev chrpath quilt libgfortran5 libltdl-dev libfuse2 debhelper flex gfortran autotools-dev tk graphviz libnl-route-3-200
x MLNX_OFED_LINUX-5.8-2.0.3.0-ubuntu22.04-x86_64.tgz
cd MLNX_OFED_LINUX-5.8-2.0.3.0-ubuntu22.04-x86_64
./mlnxofedinstall --skip-unsupported-devices-check
/etc/init.d/openibd restart
# nvidia gpu
cd /tmp
#update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
#update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
# see: https://louwrentius.com/unattended-automatic-installation-of-linux-nvidia-binary-driver.html
sh /tmp/NVIDIA-Linux-x86_64-460.106.00.run -q -a -n -X -s
sh /tmp/cuda_11.2.0_460.27.04_linux.run
# container
cd /tmp
curl -fsSL https://get.docker.com -o get-docker.sh && sudo sh get-docker.sh --mirror Aliyun
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
&& curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt update
apt install nvidia-container-runtime nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl restart docker
mkdir /etc/systemd/system/docker.service.d
cat << EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://192.168.16.118:8118"
Environment="HTTPS_PROXY=http://192.168.16.118:8118"
EOF
systemctl daemon-reload
systemctl restart docker
# conf from git
insert_if_not_exist()
{
filename=$1
line=$2
if [ ! -f "$filename" ]; then
touch $filename
fi
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
}
cd /opt
git clone https://git.nasp.ob.ac.cn/NASP/configurations
insert_if_not_exist "/etc/crontab" "59 23 * * * root \"$THIS_DIR\"/schedule-poweroff.sh"
cd /opt
git clone https://git.nasp.ob.ac.cn/NASP/registry
cd registry/scripts
./testbed_deploy.sh
# scripts
cp "$THIS_DIR"/dnew /usr/local/bin/
echo "will reboot in 10 seconds... press ctrl-c to cancel."
sleep 10
reboot