#!/bin/bash

imageName=$1

if [ $(echo $imageName|grep "ubuntu") ];then
    imageOs="ubuntu"
    davinci_num=2
elif [ $(echo $imageName|grep "openeuler") ];then
    imageOs="openeuler"
    davinci_num=3
fi

imageOsName=$(echo $imageName|awk -F '-' '{print $5}')

if [ -n "$2" ];then
    docker run -dit --security-opt seccomp=unconfined \
	--cap-add=SYS_PTRACE -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
	--name modelbox_runner_${imageOsName}_$(date +"%Y%m%d%H%M%S") \
	--device=/dev/davinci${davinci_num} \
    --device=/dev/davinci_manager \
	--device=/dev/hisi_hdc \
	--device=/dev/devmm_svm \
	-v /opt/${imageOs}:/opt/${imageOs} \
	-v /opt/thirdparty:/opt/thirdparty \
	-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
	-v /var/run/docker.sock:/var/run/docker.sock \
	-v /usr/bin/docker:/usr/bin/docker \
	-v /root/.docker/cli-plugins:/root/.docker/cli-plugins \
    $imageName
else
    docker run -dit --security-opt seccomp=unconfined \
	--cap-add=SYS_PTRACE -v /sys/fs/cgroup:/sys/fs/cgroup:ro \
	--name zxk_runner_${imageOsName}_$(date +"%Y%m%d%H%M%S") \
	--device=/dev/davinci${davinci_num} \
    --device=/dev/davinci_manager \
	--device=/dev/hisi_hdc \
	--device=/dev/devmm_svm \
	-v /opt/${imageOs}:/opt/${imageOs} \
	-v /opt/thirdparty:/opt/thirdparty \
	-v /usr/local/sbin/npu-smi:/usr/local/sbin/npu-smi \
	-v /var/run/docker.sock:/var/run/docker.sock \
	-v /usr/bin/docker:/usr/bin/docker \
	-v /root/.docker/cli-plugins:/root/.docker/cli-plugins \
    $imageName
fi

