#!/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.2.0" 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 echo -e "${red}警告!警告!警告!${plain}" echo -e "${red}警告:通过脚本更新sycgram可能会导致您的command.yml被远程配置覆盖${plain}" echo -e "${yellow}提示:如果您的command.yml相对不重要,您可以直接更新${plain}" echo -e "${yellow}建议:通过sycgram指令更新${plain}" read -p "是否继续,是则请输入yes:" opt if [[ ${opt} != "yes" ]]; then exit 0 fi 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 "+%Y_%m_%d_%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 <