#!/bin/bash clear CONTAINER_NAME="sycgram" GITHUB_IMAGE_NAME="iwumingz/${CONTAINER_NAME}" GITHUB_IMAGE_PATH="ghcr.io/${GITHUB_IMAGE_NAME}" PROJECT_PATH="/opt/${CONTAINER_NAME}" PROJECT_VERSION="v1.0.4" red='\033[0;31m' green='\033[0;32m' yellow='\033[0;33m' plain='\033[0m' pre_check() { [[ $EUID -ne 0 ]] && echo -e "${red}错误: ${plain} 需要root权限\n" && exit 1 command -v git >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "正在安装Git..." apt install git -y >/dev/null 2>&1 echo -e "${green}Git${plain} 安装成功" fi command -v curl >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "正在安装curl..." apt install curl -y >/dev/null 2>&1 echo -e "${green}curl${plain} 安装成功" fi command -v docker >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "正在安装Docker..." bash <(curl -fsL https://get.docker.com) >/dev/null 2>&1 echo -e "${green}Docker${plain} 安装成功" fi command -v tar >/dev/null 2>&1 if [[ $? != 0 ]]; then echo -e "正在安装tar..." apt install tar -y >/dev/null 2>&1 echo -e "${green}tar${plain} 安装成功" fi } delete_old_image_and_container(){ # 获取最新指令说明 # 远程file remote_file="https://raw.githubusercontent.com/iwumingz/sycgram/main/data/command.yml" # 本地file local_cmd_file="${PROJECT_PATH}/data/command.yml" if [[ -f ${local_cmd_file} ]]; then t=$(date "+%H_%M_%M") mkdir -p "${PROJECT_PATH}/data/command" >/dev/null 2>&1 echo -e "${yello}正在备份${plain} >>> ${local_cmd_file}" cp ${local_cmd_file} "${PROJECT_PATH}/data/command/command.yml.${t}" fi curl -fsL ${remote_file} > ${local_cmd_file} echo -e "${yellow}正在删除旧版本容器...${plain}" docker rm -f $(docker ps -a | grep ${CONTAINER_NAME} | awk '{print $1}') echo -e "${yellow}正在删除旧版本镜像...${plain}" docker image rm -f $(docker images | grep ${CONTAINER_NAME} | awk '{print $3}') } check_and_create_config(){ if [ ! -f ${PROJECT_PATH}/data/config.ini ]; then mkdir -p "${PROJECT_PATH}/data" >/dev/null 2>&1 read -p "Please input your api_id:" api_id read -p "Please input your api_hash:" api_hash cat > ${PROJECT_PATH}/data/config.ini <