From a340c65a22ef4f92877cfba0ec2111091cb28207 Mon Sep 17 00:00:00 2001 From: chenc <1458513@qq.com> Date: Tue, 28 Nov 2023 09:43:27 +0800 Subject: [PATCH] Update start.sh --- start.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/start.sh b/start.sh index 6f5474e..8ecf811 100644 --- a/start.sh +++ b/start.sh @@ -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!" \ No newline at end of file