WORKSPACE := /home/rocker
USER_NAME := rocker
PASSWORD = asd123

build:
	cargo build --release

# 创建WORKSPACE 对应的文件夹
install:
	@# 创建一个普通用户
	-@echo "Creating user $(USER_NAME)"
	-@sudo useradd -m -s /bin/bash $(USER_NAME)
	@# 设置密码
	-@echo "Setting password for $(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
	chmod -R 777 $(WORKSPACE)
	cp images/* $(WORKSPACE)/images/
	chown -R rocker:rocker $(WORKSPACE)

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

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

