-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdocker_unblockmusic.sh
213 lines (194 loc) · 5.88 KB
/
docker_unblockmusic.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
OFFLINE_FILE=""
ARCH=$(uname -m)
DOWNLOAD_URL="https://download.docker.com/linux/static/stable/$ARCH"
LATEST_VERSION_CHECK="https://api.github.com/repos/docker/docker-ce/releases/latest"
COMPLETION_FILE="https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker"
# cancel centos alias
[[ -f /etc/redhat-release ]] && unalias -a
#######color code########
RED="31m"
GREEN="32m"
YELLOW="33m"
BLUE="36m"
FUCHSIA="35m"
colorEcho(){
COLOR=$1
echo -e "\033[${COLOR}${@:2}\033[0m"
}
getFullPath() {
local PWD=`pwd`
if [ -d $1 ]; then
cd $1
elif [ -f $1 ]; then
cd `dirname $1`
else
cd
fi
echo $(cd ..; cd -)
cd ${PWD} >/dev/null
}
checkFile(){
local FILE=$1
if [[ ! -e $FILE ]];then
colorEcho $RED "$FILE file not exist!\n"
exit 1
elif [[ ! -f $FILE ]];then
colorEcho $RED "$FILE not a file!\n"
exit 1
fi
FILE_NAME=$(echo ${FILE##*/})
FILE_PATH=$(getFullPath $FILE)
if [[ ! $FILE_NAME =~ ".tgz" && ! $FILE_NAME =~ ".tar.gz" ]];then
colorEcho $RED "$FILE not a tgz file!\n"
echo -e "please download docker binary file: $(colorEcho $FUCHSIA $DOWNLOAD_URL)\n"
exit 1
fi
}
#######get params#########
while [[ $# > 0 ]];do
KEY="$1"
case $KEY in
-f|--file=)
OFFLINE_FILE="$2"
checkFile $OFFLINE_FILE
shift
;;
-h|--help)
echo "$0 [-h] [-f file]"
echo " -f, --file=[file_path] offline tgz file path"
echo " -h, --help find help"
echo ""
echo "Docker binary download link: $(colorEcho $FUCHSIA $DOWNLOAD_URL)"
exit 0
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
#############################
checkSys() {
if [[ -z `command -v systemctl` ]];then
colorEcho ${RED} "system must be have systemd!"
exit 1
fi
if [[ -z `uname -m|grep 64` ]];then
colorEcho ${RED} "docker only support 64-bit system!"
exit 1
fi
# check os
if [[ `command -v apt-get` ]];then
PACKAGE_MANAGER='apt-get'
elif [[ `command -v dnf` ]];then
PACKAGE_MANAGER='dnf'
elif [[ `command -v yum` ]];then
PACKAGE_MANAGER='yum'
else
colorEcho $RED "Not support OS!"
exit 1
fi
}
writeService(){
mkdir -p /usr/lib/systemd/system/
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
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
EOF
}
dependentInstall(){
if [[ ${PACKAGE_MANAGER} == 'yum' || ${PACKAGE_MANAGER} == 'dnf' ]];then
${PACKAGE_MANAGER} install bash-completion wget -y
else
${PACKAGE_MANAGER} update
${PACKAGE_MANAGER} install bash-completion wget -y
fi
}
onlineInstall(){
dependentInstall
LASTEST_VERSION=$(curl -H 'Cache-Control: no-cache' -s "$LATEST_VERSION_CHECK" | grep 'tag_name' | cut -d\" -f4 | sed 's/v//g')
wget $DOWNLOAD_URL/docker-$LASTEST_VERSION.tgz
if [[ $? != 0 ]];then
colorEcho ${RED} "Fail download docker-$LASTEST_VERSION.tgz!"
exit 1
fi
tar xzvf docker-$LASTEST_VERSION.tgz
cp -rf docker/* /usr/bin/
rm -rf docker docker-$LASTEST_VERSION.tgz
curl -L $COMPLETION_FILE -o /usr/share/bash-completion/completions/docker
chmod +x /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/completions/docker
}
offlineInstall(){
local ORIGIN_PATH=$(pwd)
cd $FILE_PATH
tar xzvf $FILE_NAME
cp -rf docker/* /usr/bin/
rm -rf docker
cd ${ORIGIN_PATH} >/dev/null
if [[ -e docker.bash || -e $FILE_PATH/docker.bash ]];then
[[ -e docker.bash ]] && COMPLETION_FILE_PATH=`getFullPath docker.bash` || COMPLETION_FILE_PATH=$FILE_PATH
cp -f $COMPLETION_FILE_PATH/docker.bash /usr/share/bash-completion/completions/docker
chmod +x /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/completions/docker
fi
}
docker_install()
{
echo "检查Docker......"
docker -v
if [ $? -eq 0 ]; then
echo "检查到Docker已安装!"
else
echo "安装docker环境..."
main
echo "安装docker环境...安装完成!"
fi
# 创建公用网络==bridge模式
#docker network create share_network
}
main(){
checkSys
[[ $OFFLINE_FILE ]] && offlineInstall || onlineInstall
writeService
systemctl daemon-reload
systemctl enable docker.service
systemctl restart docker
echo -e "docker $(colorEcho $BLUE $(docker info|grep 'Server Version'|awk '{print $3}')) install success!"
}
start(){
docker run -d --name unblockneteasemusic -p 8080:8080 nondanee/unblockneteasemusic:latest -s -e https://music.163.com -p 8080:8081
}
docker_install
start
echo "运行完成端口8080"