#!/bin/bash docker_compose_ver="2.26.0" docker_path="/data/aix-docker" cd /data print_error() { RED='\033[0;31m' NC='\033[0m' echo -e "${RED}[ERROR] $1${NC}" >&2 } print_success() { GREEN='\033[0;32m' NC='\033[0m' echo -e "${GREEN}[SUCCESS] $1${NC}" >&2 } query_euid=$(id -u) if [ $query_euid -ne 0 ]; then print_error "Please running as root" fi if ! command -v docker-compose >/dev/null 2>&1 ; then curl -L https://gh-mirrors.qra.ink/https://github.com/docker/compose/releases/download/v${docker_compose_ver}/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose fi if ! command -v git > /dev/null 2>&1 ; then print_error '请安装Git' return 1; fi if [ ! -d "$docker_path" ]; then git clone -depth=1 https://opencode.jsaix.cn/chenc/aix-docker.git /data/aix-docker if [ $? -ne 0 ]; then print_error "git clone aix-docker failed" exit 1 fi fi cd /data/aix-docker yaml_file=$(find "$(pwd)" -type f -name "docker-compose-*.yaml" | head -n 1) if [ -n "$yaml_file" ]; then if [ -z "$AIX_DOCKER_COMPOSER_FILE" ]; then echo -e "export AIX_DOCKER_COMPOSER_FILE=${yaml_file}" >> ~/.bashrc export AIX_DOCKER_COMPOSER_FILE=$yaml_file source /root/.bashrc print_success "AIX_DOCKER_COMPOSER_FILE environment variable set to '$yaml_file'" else echo "AIX_DOCKER_COMPOSER_FILE is already set to: $AIX_DOCKER_COMPOSER_FILE" fi else print_error "Please config docker composer startup yaml file" exit 1 fi if grep -q "/data/aix-docker/.alias" ~/.bashrc; then print_success ".alias is already sourced in ~/.bashrc" else echo "source /data/aix-docker/.alias" >> ~/.bashrc source /root/.bashrc fi touch /root/.aix_docker.lock print_success "script init success!"