#!/bin/bash
current_dir=$(pwd)
resources=${current_dir}/resources3
status_folder=${current_dir}/status3


run_command() {
    echo "执行命令: $@"
    if ! sudo "$@"; then
        echo "错误：命令执行失败 - $@"
        exit 1
    fi
}

REQ="${resources}/r.txt"

#############################################
if [ ! -e ${status_folder} ]; then
	echo "mkdir ..............."
	mkdir -p ${status_folder}
fi


if [ ! -e ${resources} ]; then
	echo "${resources} folder is empty, stop "
	exit 1
fi

if [ ! -e ${status_folder}/success-1 ]; then
	if [ -e "$REQ" ]; then
		run_command pip install -r ${REQ} -i https://mirrors.aliyun.com/pypi/simple/
		touch ${status_folder}/success-1
	else
		echo "$REQ Not Found"
		exit 1
	fi
fi

if [ -e ${status_folder}/success-1 ]; then
	touch ${status_folder}/success_ok
	echo "所有命令执行成功。"
fi