-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentrypoint.sh
179 lines (170 loc) · 8.17 KB
/
entrypoint.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
#!/bin/sh
function pythonInit() {
apk add --update python3-dev py3-pip
if [ $PIP_REPO ]; then
pip3 config set global.index-url $PIP_REPO
fi
rm /usr/lib/python*/EXTERNALLY-MANAGED && \
python3 -m ensurepip && \
pip3 install --upgrade pip
}
function nodeInit() {
apk add --update nodejs npm
if [ $NPM_REPO ]; then
npm config set registry $NPM_REPO
fi
}
function golangInit() {
apk add --no-cache go
if [ $GO_PROXY ]; then
go env -w GO111MODULE=on
go env -w GOPROXY=$GO_PROXY,direct
fi
}
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "@@ @@"
echo "@@ 开始时间 $(date +'%Y-%m-%d %H:%M:%S') @@"
echo "@@ @@"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
if [ "$1" ]; then
up_cmd=$1
if [ "$APK_REPO" ]; then
sed -i "s/dl-cdn.alpinelinux.org/$APK_REPO/g" /etc/apk/repositories | sed -e "s/^/[容器首次启动初始化] /"
fi
if [ "$APK_ADD_PKG" ]; then
apk add $(echo $APK_ADD_PKG | tr "&" " ") | sed -e "s/^/[容器首次启动初始化] /"
fi
if [ "$INIT_ENVS" ]; then
for env in $(echo "$INIT_ENVS" | tr "&" " "); do
"${env}Init" | sed -e "s/^/[容器首次启动初始化] /"
if [ $? -ne 0 ]; then
echo "[容器首次启动初始化] [$env]环境初始化出错❌,重启后继续尝试初始化"
exit 1
else
echo "[容器首次启动初始化] [$env]环境初始化完成✅"
fi
done
fi
fi
# 是否指定了仓库信息配置文件的路径,未指定,自动寻找MNT_DIR根木repos.json
if [ -z "$REPOS_CONFIG" ]; then
export REPOS_CONFIG=$MNT_DIR/repos.json
fi
echo "========================================读取[$REPOS_CONFIG]仓库相关配置,并进行执行配置========================================"
# 同步仓库
echo "-e"
cd "$REPOS_DIR"
repo_sync | sed -e "s/^/[仓库更新\/同步] /"
echo -e "\n>>>>>>>>>>>>>>>>>>>>执行仓库入口脚本\n"
for repoInx in $(cat $REPOS_CONFIG | jq .repos | jq 'keys|join(" ")' | sed "s/\"//g"); do
cd "$REPOS_DIR"
repoName=$(cat $REPOS_CONFIG | jq -r ".repos | .[$repoInx] | .repo_name")
repoBranch=$(cat $REPOS_CONFIG | jq -r ".repos | .[$repoInx] | .repo_branch")
repoEntrypoint=$(cat $REPOS_CONFIG | jq -r ".repos | .[$repoInx] | .repo_entrypoint")
if [ -d "$REPOS_DIR/$repoName" ]; then
cd "$REPOS_DIR/$repoName"
if [ -z $(echo $repoBranch | sed "s/null//g") ]; then
echo "[$repoName] 仓库未指定分支,使用当前默认分支"
else
echo "[$repoName] 仓库切换到指定的[$repoBranch]分支..."
git checkout $repoBranch | sed -e "s/^/[$repoName] /"
fi
if [ $(echo $repoEntrypoint | sed "s/null//g") ]; then
echo "[$repoName] 仓库已配置指定的入口shell脚本文件"
if expr "$repoEntrypoint" : 'http.*' &>/dev/null; then
echo "[$repoName] 仓库配置指定的入口shell脚本为远程脚本,开始下载远程脚本 $repoEntrypoint"
wget -O iou-entry.sh "$repoEntrypoint" | sed -e "s/^/[$repoName]/"
echo "[$repoName] 仓库配置指定的入口shell脚本下载完成,开始执行..."
sh iou-entry.sh | sed -e "s/^/[$repoName\/iou-entry.sh] /"
echo "[$repoName] 仓库配置指定的入口shell脚本,执行结束..."
else
if [ ! -f "$repoEntrypoint" ]; then
echo "[$repoName] 仓库配置指定的入口shell脚本为挂载脚本文件,但是挂载文件$repoEntrypoint不存在,跳过..."
else
echo "[$repoName] 仓库配置指定的入口shell脚本为挂载脚本文件,开始执行..."
cp -rf "$repoEntrypoint" ./iou-entry.sh
sh iou-entry.sh | sed -e "s/^/[$repoName\/iou-entry.sh] /"
echo "[$repoName] 仓库配置指定的入口shell脚本为挂载脚本文件,开始结束..."
fi
fi
else
if [ -f "$REPOS_DIR/$repoName/iou-entry.sh" ]; then
echo "[$repoName] 仓库为默认入口shell脚本,开始执行..."
sh iou-entry.sh | sed -e "s/^/[$repoName\/iou-entry.sh] /"
echo "[$repoName] 仓库为默认入口shell脚本,执行结束..."
else
echo "[$repoName] 仓库为默认入口shell脚本iou-entry.sh不存在,跳过..."
fi
fi
echo "-e"
else
echo "[$repoName] 仓库目录不存在,可能clone失败,跳过..."
fi
done
echo -e "\n>>>>>>>>>>>>>>>>>>>>执行挂载本地目录入口脚本\n"
for repoInx in $(cat $REPOS_CONFIG | jq .local_dir | jq 'keys|join(" ")' | sed "s/\"//g"); do
cd "$LOCAL_DIR"
dirName=$(cat $REPOS_CONFIG | jq -r ".local_dir | .[$repoInx] | .dir_name")
dirEntrypoint=$(cat $REPOS_CONFIG | jq -r ".local_dir | .[$repoInx] | .dir_entrypoint")
if [ -d "$LOCAL_DIR/$dirName" ]; then
cd "$LOCAL_DIR/$dirName"
if [ $(echo $dirEntrypoint | sed "s/null//g") ]; then
echo "[$dirName] 挂载目录已配置指定的入口shell脚本文件"
if expr "$dirEntrypoint" : 'http.*' &>/dev/null; then
echo "[$dirName] 挂载目录配置指定的入口shell脚本为远程脚本,开始下载远程脚本 $dirEntrypoint"
wget -O iou-entry.sh "$dirEntrypoint" | sed -e "s/^/[$dirName]/"
echo "[$dirName] 挂载目录配置指定的入口shell脚本下载完成,开始执行..."
sh iou-entry.sh | sed -e "s/^/[$dirName\/iou-entry.sh] /"
echo "[$dirName] 挂载目录配置指定的入口shell脚本,执行结束..."
else
if [ ! -f "$dirEntrypoint" ]; then
echo "[$dirName] 挂载目录配置指定的入口shell脚本为挂载脚本文件,但是挂载文件$dirEntrypoint不存在,跳过..."
else
echo "[$dirName] 挂载目录配置指定的入口shell脚本为挂载脚本文件,开始执行..."
cp -rf "$dirEntrypoint" ./iou-entry.sh
sh iou-entry.sh | sed -e "s/^/[$dirName\/iou-entry.sh] /"
echo "[$dirName] 挂载目录配置指定的入口shell脚本为挂载脚本文件,开始结束..."
fi
fi
else
if [ -f "$LOCAL_DIR/$dirName/iou-entry.sh" ]; then
echo "[$dirName] 挂载目录为默认入口shell脚本,开始执行..."
sh iou-entry.sh | sed -e "s/^/[$dirName\/iou-entry.sh] /"
echo "[$dirName] 挂载目录为默认入口shell脚本,执行结束..."
else
echo "[$dirName] 挂载目录为默认入口shell脚本iou-entry.sh不存在,跳过..."
fi
fi
echo "-e"
else
echo "[$dirName] 挂载目录不存在,请检查挂载路径,跳过..."
fi
done
echo "========================================================$REPOS_CONFIG]配置结束================================================="
firstFile="y"
echo "05 * * * * entrypoint.sh >> $MNT_DIR/entrypoint.log 2>&1 " >"$CRON_FILE_DIR/entrypoint_cron.sh"
for cronFile in $(ls "$CRON_FILE_DIR" | grep ".sh" | grep -v "merge_all_cron.sh" | tr "\n" " "); do
cd $CRON_FILE_DIR
if [ $firstFile == "y" ]; then
echo "#[$cronFile]文件任务列表" >"$CRON_FILE_DIR/merge_all_cron.sh"
firstFile="n"
else
echo "#[$cronFile]文件任务列表" >>"$CRON_FILE_DIR/merge_all_cron.sh"
fi
cat $cronFile >>"$CRON_FILE_DIR/merge_all_cron.sh"
echo "-e" >>"$CRON_FILE_DIR/merge_all_cron.sh"
done
echo "-e"
echo "[定时任务列表] 更新定时任务列表"
crontab "$CRON_FILE_DIR/merge_all_cron.sh"
crontab -l | sed -e "s/^/[定时任务列表] /"
echo "-e"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "@@ @@"
echo "@@ 完成时间 $(date +'%Y-%m-%d %H:%M:%S') @@"
echo "@@ @@"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
if [ "$up_cmd" ]; then
echo "keep running..."
crond -f
fi