2023-08-16 16:48:05 +08:00
|
|
|
#/bin/sh
|
2023-11-27 17:17:47 +08:00
|
|
|
docker_path="/data/aix-docker"
|
2023-09-07 10:38:27 +08:00
|
|
|
pushd /data
|
2023-11-27 17:17:47 +08:00
|
|
|
function print_error() {
|
|
|
|
|
RED='\033[0;31m'
|
|
|
|
|
NC='\033[0m'
|
|
|
|
|
|
|
|
|
|
echo -e "${RED}[ERROR] $1${NC}" >&2
|
|
|
|
|
}
|
|
|
|
|
function print_success() {
|
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
|
NC='\033[0m'
|
|
|
|
|
echo -e "${GREEN}[SUCCESS] $1${NC}" >&2
|
|
|
|
|
}
|
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
|
print_error "Please running as root"
|
|
|
|
|
fi
|
|
|
|
|
if [ -e "/root/.aix_docker.lock" ]; then
|
|
|
|
|
print_error "Initialization has been performed!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if ! command -v jq >/dev/null 2>&1 ; then
|
|
|
|
|
if [ -f /etc/redhat-release ]; then
|
|
|
|
|
yum install -y jq
|
|
|
|
|
elif [ -f /etc/debian_version ]; then
|
|
|
|
|
apt-get install -y jq
|
|
|
|
|
else
|
|
|
|
|
print_error "Unsupported Linux distribution"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-08-16 16:48:05 +08:00
|
|
|
if ! command -v docker >/dev/null 2>&1 ; then
|
2023-11-23 07:32:19 +00:00
|
|
|
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/x86_64/docker-20.10.9.tgz
|
|
|
|
|
if [ $? -ne 0 ]; then
|
2023-11-27 17:17:47 +08:00
|
|
|
print_error "Download docker failed"
|
2023-11-23 07:32:19 +00:00
|
|
|
exit 1
|
|
|
|
|
fi
|
2023-08-16 16:48:05 +08:00
|
|
|
tar -zxvf docker-20.10.9.tgz
|
|
|
|
|
mv docker/* /usr/bin/
|
|
|
|
|
groupadd docker
|
|
|
|
|
cat > /usr/lib/systemd/system/docker.service << EOF
|
|
|
|
|
[Unit]
|
|
|
|
|
Description=Docker Application Container Engine
|
|
|
|
|
Documentation=https://docs.docker.com
|
|
|
|
|
After=network-online.target firewalld.service
|
|
|
|
|
Wants=network-online.target
|
|
|
|
|
[Service]
|
|
|
|
|
Type=notify
|
|
|
|
|
ExecStart=/usr/bin/dockerd
|
|
|
|
|
ExecReload=/bin/kill -s HUP $MAINPID
|
|
|
|
|
LimitNOFILE=infinity
|
|
|
|
|
LimitNPROC=infinity
|
|
|
|
|
TimeoutStartSec=0
|
|
|
|
|
Delegate=yes
|
|
|
|
|
KillMode=process
|
|
|
|
|
Restart=on-failure
|
|
|
|
|
StartLimitBurst=3
|
|
|
|
|
StartLimitInterval=60s
|
|
|
|
|
[Install]
|
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
|
EOF
|
|
|
|
|
chmod +x /usr/lib/systemd/system/docker.service
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
systemctl start docker
|
|
|
|
|
systemctl enable docker
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if ! command -v docker-compose >/dev/null 2>&1 ; then
|
2023-11-23 07:41:06 +00:00
|
|
|
curl -L https://mirror.ghproxy.com/https://github.com/docker/compose/releases/download/v2.18.1/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 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
|
|
|
|
|
pushd /data/aix-docker
|
|
|
|
|
|
|
|
|
|
yaml_file=$(find "$(pwd)" -type f -name "*.yaml" -o -name "*.yml" | head -n 1)
|
|
|
|
|
if [ -n "$yaml_file" ]; then
|
|
|
|
|
if [ -z "$AIX_DOCKER_COMPOSER_FILE" ]; then
|
|
|
|
|
echo 'export AIX_DOCKER_COMPOSER_FILE=$yaml_file' >> ~/.bashrc
|
|
|
|
|
source ~/.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 ~/.bashrc
|
|
|
|
|
fi
|
|
|
|
|
touch /root/.aix_docker.lock
|
|
|
|
|
print_success "script init success!"
|