#!/bin/bash
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.

. $CCI_SRC/container/defconfig.sh
. $CCI_SRC/lib/log.sh

lsmod | grep -q "^nfs\s" || {
	log_error "kernel module nfs is missing (try: sudo modprobe nfs)"
	exit 1
}
lsmod | grep -q "^nfsd\s" || {
	log_error "kernel module nfsd is missing (try: sudo modprobe nfsd)"
	exit 1
}

# Several nfs servers running will cause conflict, so rm an old before running a new nfs server docker.
docker_rm os-nfs

cmd=(
	docker run
	--restart=always
#	-it
	--name os-nfs # avoid multiple containers
	-e NFS_DISABLE_VERSION_3=1
	--mount type=tmpfs,destination=/exports
	-v /srv/os:/exports/os:ro
	-v /etc/localtime:/etc/localtime:ro
	-v /srv/os:/exports/os-rw	 # for install/setup
	-v /srv/result:/exports/result
	-v /srv/data:/exports/data
	-v /srv/initrd:/exports/initrd
	-v /srv/initrd:/exports/osimage  # for lkp compatibility
	--cap-add SYS_ADMIN
#	--privileged
	--net=host # w/o it, docker-proxy only listens on tcp6..
#	-p 2049:2049
	-d # comment out to see debug output
	os-nfs
)

"${cmd[@]}"
