aix-docker/start.sh

61 lines
1.7 KiB
Bash
Raw Normal View History

2023-11-28 09:43:27 +08:00
#!/bin/bash
2024-05-16 11:07:12 +08:00
docker_compose_ver="2.26.0"
2023-11-27 17:17:47 +08:00
docker_path="/data/aix-docker"
2023-11-28 09:43:27 +08:00
cd /data
print_error() {
2023-11-27 17:17:47 +08:00
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}[ERROR] $1${NC}" >&2
}
2023-11-28 09:43:27 +08:00
print_success() {
2023-11-27 17:17:47 +08:00
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}[SUCCESS] $1${NC}" >&2
}
2023-11-28 09:43:27 +08:00
query_euid=$(id -u)
if [ $query_euid -ne 0 ]; then
2023-11-27 17:17:47 +08:00
print_error "Please running as root"
fi
2023-08-16 16:48:05 +08:00
if ! command -v docker-compose >/dev/null 2>&1 ; then
2024-08-06 05:37:16 +00:00
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
2023-08-16 16:48:05 +08:00
chmod +x /usr/local/bin/docker-compose
fi
if ! command -v git > /dev/null 2>&1 ; then
2023-11-27 17:17:47 +08:00
print_error '请安装Git'
2023-08-16 16:48:05 +08:00
return 1;
2023-09-07 10:38:27 +08:00
fi
2023-11-27 17:17:47 +08:00
if [ ! -d "$docker_path" ]; then
git clone -depth=1 https://opencode.jsaix.cn/chenc/aix-docker.git /data/aix-docker
2023-11-27 17:17:47 +08:00
if [ $? -ne 0 ]; then
print_error "git clone aix-docker failed"
exit 1
fi
fi
2023-11-28 09:43:27 +08:00
cd /data/aix-docker
2023-11-27 17:17:47 +08:00
2023-11-28 16:01:23 +08:00
yaml_file=$(find "$(pwd)" -type f -name "docker-compose-*.yaml" | head -n 1)
2023-11-27 17:17:47 +08:00
if [ -n "$yaml_file" ]; then
if [ -z "$AIX_DOCKER_COMPOSER_FILE" ]; then
2023-11-28 09:43:27 +08:00
echo -e "export AIX_DOCKER_COMPOSER_FILE=${yaml_file}" >> ~/.bashrc
export AIX_DOCKER_COMPOSER_FILE=$yaml_file
source /root/.bashrc
2023-11-27 17:17:47 +08:00
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
2023-11-28 09:43:27 +08:00
source /root/.bashrc
2023-11-27 17:17:47 +08:00
fi
touch /root/.aix_docker.lock
print_success "script init success!"