-
Notifications
You must be signed in to change notification settings - Fork 2
/
iproyal.sh
133 lines (113 loc) · 4.61 KB
/
iproyal.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#FROM https://github.com/spiritLHLS/pawns-one-click-command-installation
utf8_locale=$(locale -a 2>/dev/null | grep -i -m 1 -E "UTF-8|utf8")
if [[ -z "$utf8_locale" ]]; then
echo "No UTF-8 locale found"
else
export LC_ALL="$utf8_locale"
export LANG="$utf8_locale"
export LANGUAGE="$utf8_locale"
echo "Locale set to $utf8_locale"
fi
# 定义容器名
NAME='iproyalnode'
# 自定义字体彩色,read 函数,安装依赖函数
red(){ echo -e "\033[31m\033[01m$1$2\033[0m"; }
green(){ echo -e "\033[32m\033[01m$1$2\033[0m"; }
yellow(){ echo -e "\033[33m\033[01m$1$2\033[0m"; }
reading(){ read -rp "$(green "$1")" "$2"; }
# 必须以root运行脚本
check_root(){
[[ $(id -u) != 0 ]] && red " The script must be run as root, you can enter sudo -i and then download and run again." && exit 1
}
# 判断系统,并选择相应的指令集
check_operating_system(){
CMD=("$(grep -i pretty_name /etc/os-release 2>/dev/null | cut -d \" -f2)"
"$(hostnamectl 2>/dev/null | grep -i system | cut -d : -f2)"
"$(lsb_release -sd 2>/dev/null)" "$(grep -i description /etc/lsb-release 2>/dev/null | cut -d \" -f2)"
"$(grep . /etc/redhat-release 2>/dev/null)"
"$(grep . /etc/issue 2>/dev/null | cut -d \\ -f1 | sed '/^[ ]*$/d')"
)
for i in "${CMD[@]}"; do SYS="$i" && [[ -n $SYS ]] && break; done
REGEX=("debian" "ubuntu" "centos|red hat|kernel|oracle linux|amazon linux|alma|rocky")
RELEASE=("Debian" "Ubuntu" "CentOS")
PACKAGE_UPDATE=("apt -y update" "apt -y update" "yum -y update")
PACKAGE_INSTALL=("apt -y install" "apt -y install" "yum -y install")
PACKAGE_UNINSTALL=("apt -y autoremove" "apt -y autoremove" "yum -y autoremove")
for ((int = 0; int < ${#REGEX[@]}; int++)); do
[[ $(echo "$SYS" | tr '[:upper:]' '[:lower:]') =~ ${REGEX[int]} ]] && SYSTEM="${RELEASE[int]}" && break
done
[[ -z $SYSTEM ]] && red " ERROR: The script supports Debian, Ubuntu, CentOS or Alpine systems only.\n" && exit 1
}
# 判断宿主机的 IPv4 或双栈情况,没有拉取不了 docker
check_ipv4(){
! curl -s4m8 ip.sb | grep -q '\.' && red " ERROR:The host must have IPv4. " && exit 1
}
# 判断 CPU 架构
check_virt(){
ARCHITECTURE=$(uname -m)
case "$ARCHITECTURE" in
aarch64 ) ARCH=arm64v8;;
x64|x86_64|amd64 ) ARCH=latest;;
* ) red " ERROR: Unsupported architecture: $ARCHITECTURE\n" && exit 1;;
esac
}
# 输入 iproyal 的个人 信息
input_token(){
[ -z $EMAIL ] && reading " Enter your Email, if you do not find it, open https://pawns.app?r=usdbonus: " EMAIL
[ -z $PASSWORD ] && reading " Enter your Password: " PASSWORD
}
container_build(){
# 宿主机安装 docker
green "\n Install docker.\n "
if ! systemctl is-active docker >/dev/null 2>&1; then
echo -e " \n Install docker \n "
if [ $SYSTEM = "CentOS" ]; then
${PACKAGE_INSTALL[int]} yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo &&
${PACKAGE_INSTALL[int]} docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
else
${PACKAGE_INSTALL[int]} docker.io
fi
fi
# 删除旧容器(如有)
docker ps -a | awk '{print $NF}' | grep -qw "$NAME" && yellow " Remove the old iproyal container.\n " && docker rm -f "$NAME" >/dev/null 2>&1
# 创建容器
yellow " Create the iproyal container.\n "
ori=$(date | md5sum)
rname=${ori: 2: 9}
docker pull iproyal/pawns-cli:latest
docker run -d --name "$NAME" --restart=always iproyal/pawns-cli:latest -email="$EMAIL" -password="$PASSWORD" -device-name=raspberrypi -device-id="$rname" -accept-tos >/dev/null 2>&1
# docker run -d --name "$NAME" --restart=always iproyal/pawns-cli:latest -email="$EMAIL" -password="$PASSWORD" -device-name=raspberrypi -accept-tos >/dev/null 2>&1
# 创建 Towerwatch
[[ ! $(docker ps -a) =~ watchtower ]] && yellow " Create TowerWatch.\n " && docker run -d --name watchtower --restart always -p 2095:8080 -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower --cleanup >/dev/null 2>&1
}
# 显示结果
result(){
docker ps -a | grep -q "$NAME" && green " Install success.\n" || red " install fail.\n"
}
# 卸载
uninstall(){
docker rm -f $(docker ps -a | grep -w "$NAME" | awk '{print $1}')
docker rmi -f $(docker images | grep iproyal/pawns-cli | awk '{print $3}')
green "\n Uninstall containers and images complete.\n"
exit 0
}
# 传参
while getopts "UuM:m:P:p:" OPTNAME; do
case "$OPTNAME" in
'U'|'u' ) uninstall;;
'M'|'m' ) EMAIL=$OPTARG;;
'P'|'p' ) PASSWORD=$OPTARG;;
esac
done
# 主程序
check_root
check_operating_system
check_ipv4
check_virt
input_token
container_build
result
rm -rf iproyal.sh*