同步操作将从 飞致云/SQLBot 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/bin/bashINSTALL_TYPE='install'title_count=1CURRENT_DIR=$(cd "$(dirname "0ドル")"pwd)function log() {echo -e "${1}" 2>&1 | tee -a ${CURRENT_DIR}/install.log}function log_title () {log "${title_count}. ${1}"let title_count++}function log_content () {log "\t${1}"}function check_and_prepare_env_params() {log "当前时间 : $(date)"log_title "检查安装环境并初始化环境变量"cd ${CURRENT_DIR}if [ -f /usr/bin/sctl ]; thenecho "当前版本: $(sctl version | head -n 1)"# 获取已安装的 SQLBOT 的运行目录SQLBOT_BASE=$(grep "^SQLBOT_BASE=" /usr/bin/sctl | cut -d'=' -f2)SQLBOT_BASE_OLD=${SQLBOT_BASE}sed -i -e "s#SQLBOT_BASE=.*#SQLBOT_BASE=${SQLBOT_BASE}#g" sctl\cp sctl /usr/local/bin && chmod +x /usr/local/bin/sctllog_content "停止 SQLBot 服务"sctl stopINSTALL_TYPE='upgrade'fiset -asource ${CURRENT_DIR}/install.confif [[ ${SQLBOT_BASE_OLD} ]];thenSQLBOT_BASE=${SQLBOT_BASE_OLD}export SQLBOT_BASE=${SQLBOT_BASE_OLD}fiif [[ -d ${SQLBOT_BASE} ]] && [[ -f ${SQLBOT_BASE}/sqlbot/.env ]]; thensource $SQLBOT_BASE/sqlbot/.envINSTALL_TYPE='upgrade'log_content "升级安装"elseINSTALL_TYPE='install'mkdir -p ${SQLBOT_BASE}log_content "全新安装"fiset +a}function set_run_base_path() {log_title "设置运行目录"SQLBOT_RUN_BASE=$SQLBOT_BASE/sqlbotCONF_FOLDER=${SQLBOT_RUN_BASE}/confTEMPLATES_FOLDER=${SQLBOT_RUN_BASE}/templateslog_content "运行目录 $SQLBOT_RUN_BASE"log_content "配置文件目录 $CONF_FOLDER"}function prepare_sqlbot_run_base() {log_title "初始化运行目录"cd ${CURRENT_DIR}mkdir -p ${SQLBOT_RUN_BASE}log_content "复制安装文件到运行目录"cp -r ./sqlbot/* ${SQLBOT_RUN_BASE}/cd ${SQLBOT_RUN_BASE}env | grep SQLBOT_ >.envmkdir -p ${SQLBOT_RUN_BASE}/confmkdir -p ${SQLBOT_RUN_BASE}/data/sqlbot/{excel,images,logs}if [ "${SQLBOT_EXTERNAL_DB}" = "false" ]; thenmkdir -p ${SQLBOT_RUN_BASE}/data/postgresqlexport SQLBOT_DB_PORT=5432elsesed -i -e "/^ depends_on/,+2d" docker-compose.ymlfilog_content "调整配置文件参数"cd ${SQLBOT_RUN_BASE}cp -r ${TEMPLATES_FOLDER}/* ${CONF_FOLDER}cd ${TEMPLATES_FOLDER}templates_files=( sqlbot.conf )for i in ${templates_files[@]}; doif [ -f $i ]; thenenvsubst < $i > ${CONF_FOLDER}/$ifidone}function update_sctl() {log_title "安装 sctl 命令行工具"log_content "安装至 /usr/local/bin/sctl & /usr/bin/sctl"cd ${CURRENT_DIR}sed -i -e "s#SQLBOT_BASE=.*#SQLBOT_BASE=${SQLBOT_BASE}#g" sctl\cp sctl /usr/local/bin && chmod +x /usr/local/bin/sctlif [ ! -f /usr/bin/sctl ]; thenln -s /usr/local/bin/sctl /usr/bin/sctl 2>/dev/nullfi}function prepare_system_settings() {log_title "修改操作系统相关设置"if which getenforce >/dev/null 2>&1 && [ $(getenforce) == "Enforcing" ];thenlog_content "关闭 SELINUX"setenforce 0sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/configfiif which firewall-cmd >/dev/null 2>&1; thenif systemctl is-active firewalld &>/dev/null ;thenlog_content "开启防火墙端口 ${SQLBOT_WEB_PORT}"firewall-cmd --zone=public --add-port=${SQLBOT_WEB_PORT}/tcp --permanentlog_content "开启防火墙端口 ${SQLBOT_MCP_PORT}"firewall-cmd --zone=public --add-port=${SQLBOT_MCP_PORT}/tcp --permanentfirewall-cmd --reloadelselog_content "防火墙未开启,忽略端口开放"fifi}function install_docker() {log_title "安装 docker"#Install docker##Install Latest Stable Docker Releasecd ${CURRENT_DIR}if which docker >/dev/null 2>&1; thenlog_content "检测到 Docker 已安装,跳过安装步骤"log_content "启动 Docker "service docker start >/dev/null 2>&1 | tee -a ${CURRENT_DIR}/install.logelseif [[ -d docker ]]; thenlog_content "离线安装 docker"cp docker/bin/* /usr/bin/cp docker/service/docker.service /etc/systemd/system/chmod +x /usr/bin/docker*chmod 644 /etc/systemd/system/docker.serviceelselog_content "在线安装 docker"curl -fsSL https://resource.fit2cloud.com/get-docker-linux.sh -o get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.logif [[ ! -f get-docker.sh ]];thenlog_content "docker 在线安装脚本下载失败,请稍候重试"exit 1fisudo sh get-docker.sh 2>&1 | tee -a ${CURRENT_DIR}/install.logfidocker_config_folder="/etc/docker"if [ ! -d "$docker_config_folder" ];thenmkdir -p "$docker_config_folder"cat <<EOF> $docker_config_folder/daemon.json{"log-driver": "json-file","log-opts": {"max-file": "3","max-size": "10m"}}EOFfilog_content "启动 docker"systemctl enable docker >/dev/null 2>&1; systemctl daemon-reload; systemctl start docker 2>&1 | tee -a ${CURRENT_DIR}/install.logdocker version >/dev/null 2>&1if [ $? -ne 0 ]; thenlog_content "docker 安装失败"exit 1elselog_content "docker 安装成功"fifi}function install_docker_compose() {log_title "安装 docker-compose"#Install docker-composecd ${CURRENT_DIR}##Install Latest Stable Docker Compose Releasedocker-compose version >/dev/null 2>&1if [ $? -ne 0 ]; thendocker compose version >/dev/null 2>&1if [ $? -eq 0 ]; thenecho 'docker compose "$@"' > /usr/bin/docker-composechmod +x /usr/bin/docker-composeelseif [[ -d docker ]]; thenlog_content "离线安装 docker-compose"cp docker/bin/docker-compose /usr/bin/chmod +x /usr/bin/docker-composeelselog_content "在线安装 docker-compose"curl -L https://resource.fit2cloud.com/docker/compose/releases/download/v2.16.0/docker-compose-$(uname -s | tr A-Z a-z)-$(uname -m) -o /usr/local/bin/docker-compose 2>&1 | tee -a ${CURRENT_DIR}/install.logif [[ ! -f /usr/local/bin/docker-compose ]];thenlog_content "docker-compose 下载失败,请稍候重试"exit 1fichmod +x /usr/local/bin/docker-composeln -s /usr/local/bin/docker-compose /usr/bin/docker-composefifidocker-compose version >/dev/nullif [ $? -ne 0 ]; thenlog_content "docker-compose 安装失败"exit 1elselog_content "docker-compose 安装成功"fielselog_content "检测到 Docker Compose 已安装,跳过安装步骤"fiexport COMPOSE_HTTP_TIMEOUT=180}function load_images() {log_title "加载 SQLBOT 镜像"cd ${CURRENT_DIR}for i in $(docker images --format '{{.Repository}}:{{.Tag}}' | grep dataease); docurrent_images[${#current_images[@]}]=${i##*/}done# 加载镜像if [[ -d images ]]; thenfor i in $(ls images); doif [[ "${current_images[@]}" =~ "${i%.tar.gz}" ]]; thenlog_content "已存在镜像 ${i%.tar.gz}"elselog_content "加载镜像 ${i%.tar.gz}"docker load -i images/$i >/dev/null 2>&1 | tee -a ${CURRENT_DIR}/install.logfidoneelseSQLBOTVERSION=$(cat ${CURRENT_DIR}/sqlbot/templates/version)curl -sfL https://resource.fit2cloud.com/installation-log.sh | sh -s sqlbot ${INSTALL_TYPE} ${SQLBOTVERSION}fi}function start_sqlbot() {log_title "启动 SQLBOT 服务"sctl reload 2>&1 | tee -a ${CURRENT_DIR}/install.logif [[ $? -ne 0 ]]; thenlog_content "SQLBOT 服务启动失败,请检查日志"exit 1fiechoif [[ $INSTALL_TYPE != "upgrade" ]];thenecho -e "======================= 安装完成 =======================\n" 2>&1 | tee -a ${CURRENT_DIR}/install.logecho -e "系统登录信息如下:\n\t访问地址: http://服务器IP:$SQLBOT_WEB_PORT\n\t用户名: admin\n\t初始密码: SQLBot@123456" 2>&1 | tee -a ${CURRENT_DIR}/install.logelseecho -e "======================= 升级完成 =======================\n" 2>&1 | tee -a ${CURRENT_DIR}/install.logfi}function main() {check_and_prepare_env_paramsset_run_base_pathprepare_sqlbot_run_baseupdate_sctlprepare_system_settingsinstall_dockerinstall_docker_composeload_imagesstart_sqlbot}main
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。