Update start.sh

This commit is contained in:
chenc 2023-11-28 09:43:27 +08:00
parent b786909b4f
commit a340c65a22

View File

@ -1,18 +1,18 @@
#!/bin/sh
#!/bin/bash
docker_path="/data/aix-docker"
pushd /data
function print_error() {
cd /data
print_error() {
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}[ERROR] $1${NC}" >&2
}
function print_success() {
print_success() {
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}[SUCCESS] $1${NC}" >&2
}
if [ "$EUID" -ne 0 ]; then
query_euid=$(id -u)
if [ $query_euid -ne 0 ]; then
print_error "Please running as root"
fi
if [ -e "/root/.aix_docker.lock" ]; then
@ -27,6 +27,7 @@ if ! command -v jq >/dev/null 2>&1 ; then
else
print_error "Unsupported Linux distribution"
exit 1
fi
fi
if ! command -v docker >/dev/null 2>&1 ; then
wget --no-check-certificate https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/static/stable/x86_64/docker-20.10.9.tgz
@ -82,13 +83,14 @@ if [ ! -d "$docker_path" ]; then
exit 1
fi
fi
pushd /data/aix-docker
cd /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
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"
@ -101,7 +103,7 @@ 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
source /root/.bashrc
fi
touch /root/.aix_docker.lock
print_success "script init success!"