WORKSPACE := /home/rocker
USER_NAME := rocker
GROUP_NAME := $(USER_NAME)
UID = 7788
GID = 7788
PASSWORD = quant_u2Oh0Go9J76aQb3h7Ybg2apw@yanguangshaonian

build:
	cargo build --release

# 创建WORKSPACE 对应的文件夹
install:
	@# 创建一个普通用户
	-@sudo useradd -m -s /bin/bash $(USER_NAME) -u $(UID)
	@# 将用户添加到用户组
	-@sudo usermod -g $(GID) -aG $(GROUP_NAME) $(USER_NAME)
	@# 设置密码
	-@echo "$(USER_NAME):$(PASSWORD)" | sudo chpasswd
#	@# 授权sudo
#	-@echo "Authorizing $(USER_NAME) to use sudo"
#	-@sudo sh -c "echo '$(USER_NAME) ALL=(ALL) ALL' >> /etc/sudoers"

	mkdir -p $(WORKSPACE)/images
	mkdir -p $(WORKSPACE)/volumes
	mkdir -p $(WORKSPACE)/containers
	touch $(WORKSPACE)/network
	chmod -R 777 $(WORKSPACE)
	cp images/* $(WORKSPACE)/images/
	chown -R rocker:rocker $(WORKSPACE)

	@# 设置cgroup.subtree_control的 
	mkdir /sys/fs/cgroup/rocker
	echo "+cpuset +cpu +io +memory +hugetlb +pids +rdma +misc" > /sys/fs/cgroup/rocker/cgroup.subtree_control


clean:
	-./target/debug/rocker --rm all
	-rocker --rm all
	-rm -rf $(WORKSPACE)/*
	-rm -rf /usr/bin/rocker

	-rmdir /sys/fs/cgroup/rocker/*
	-rmdir /sys/fs/cgroup/rocker

	-@echo "Cleaning up"
	-@sudo userdel -r $(USER_NAME)
	-@sudo groupdel $(GROUP_NAME)
	-@sudo sed -i "/^$(USER_NAME)/d" /etc/sudoers

