-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-register-docker.sh
executable file
·92 lines (73 loc) · 4.99 KB
/
start-register-docker.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# get host name
os_name=$(uname -s)
white="\033[0;37m"
green="\033[1;32m"
end_style="\033[0m"
# test if sudo command exists
if command -v sudo &> /dev/null
then
SUDO="sudo"
else
SUDO=""
fi
# 检查 Docker 是否正在运行
if ! docker info > /dev/null 2>&1; then
echo -e "\033[1;31mDocker is not running. Please start Docker and try again.\033[0m"
exit 1
fi
# get local ip address according to the operating system
if [ "$os_name" = "Linux" ]; then
ip_address=$(hostname -I | awk '{print $1}')
elif [ "$os_name" = "Darwin" ]; then
ip_address=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | head -n 1)
else
echo "Unsupported OS"
ip_address=localhost
fi
# get public ip address
public_ip_address=$(curl -s https://api.ipify.org)
echo -e "\033[2J\033[0;0H"
echo -e "${white}---------------------------------------------------------------------------------------${end_style}"
echo -e "${white}| UPC System Start Script |${end_style}"
echo -e "${white}|-------------------------------------------------------------------------------------|${end_style}"
echo -e "${white}| ██╗ ██╗██████╗ ██████╗ |${end_style}"
echo -e "${white}| ██║ ██║██╔══██╗██╔════╝ |${end_style}"
echo -e "${white}| ██║ ██║██████╔╝██║ |${end_style}"
echo -e "${white}| ██║ ██║██╔═══╝ ██║ |${end_style}"
echo -e "${white}| ╚██████╔╝██║ ╚██████╗ |${end_style}"
echo -e "${white}| ╚═════╝ ╚═╝ ╚═════╝ |${end_style}"
echo -e "${white}|-------------------------------------------------------------------------------------|${end_style}"
echo -e "${white}| Register Server |${end_style}"
echo -e "${white}---------------------------------------------------------------------------------------${end_style}"
echo ""
echo -e "\033[37mYour Host type: \033[1;33m$os_name${end_style}"
echo -e "\033[37mYour Local IP Address: \033[1;33m$ip_address${end_style}"
echo -e "\033[37mYour Public IP Address: \033[1;33m$public_ip_address${end_style}"
echo ""
echo -e "\033[1;37m1. Please enter your Register \033[1;31mPORT${end_style} ${white}(press Enter for default:${end_style} \033[32m8000${end_style}${white}):${end_style}"
read regi_PORT
REGI_PORT=${regi_PORT:-8000}
echo -e "\033[97mRegister Server URL: ${green}\033[4mhttp://$ip_address:$REGI_PORT${end_style}"
sleep 1
echo -e "\033[2J\033[0;0H"
echo -e "${green}---------------------------------------------------------------------------------------${end_style}"
echo -e "${green}| UPC System Start Script |${end_style}"
echo -e "${green}|-------------------------------------------------------------------------------------|${end_style}"
echo -e "${green}| ██╗ ██╗██████╗ ██████╗ |${end_style}"
echo -e "${green}| ██║ ██║██╔══██╗██╔════╝ |${end_style}"
echo -e "${green}| ██║ ██║██████╔╝██║ |${end_style}"
echo -e "${green}| ██║ ██║██╔═══╝ ██║ |${end_style}"
echo -e "${green}| ╚██████╔╝██║ ╚██████╗ |${end_style}"
echo -e "${green}| ╚═════╝ ╚═╝ ╚═════╝ |${end_style}"
echo -e "${green}|-------------------------------------------------------------------------------------|${end_style}"
echo -e "${green}| Register Server |${end_style}"
echo -e "${green}---------------------------------------------------------------------------------------${end_style}"
# check if there are dangling images
dangling_images=$($SUDO docker images -f "dangling=true" -q)
if [ -n "$dangling_images" ]; then
# if there are dangling images, remove them
$SUDO docker rmi $dangling_images
fi
# Run the docker container
$SUDO docker pull afterlifexx/upc-register:latest && $SUDO docker run -e REGI_PORT=$REGI_PORT -it --rm -p $REGI_PORT:$REGI_PORT afterlifexx/upc-register:latest