forked from northsea4/mdcx-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-src.sh
executable file
·109 lines (88 loc) · 2.29 KB
/
prepare-src.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
#!/bin/sh
# 脚本说明:下载应用源码并解压到指定的目录(通过`context`指定)下的`.mdcx_src`目录
# 一般只用于构建镜像流程,普通用户可以忽略。
# UPDATE 2023-12-24 17:08:03 使用新的源码仓库:https://github.com/sqzw-x/mdcx
# 检查是否有jq命令
if ! command -v jq &> /dev/null
then
echo "❌ 请先安装jq命令!参考:https://command-not-found.com/jq"
exit 1
fi
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--context)
context="$2"
shift
shift
;;
--verbose)
verbose=1
shift
;;
-h|--help)
help=1
shift
;;
*)
shift
;;
esac
done
if [[ -z "$context" ]]; then
echo "❌ context is required!"
exit 1
fi
if [[ ! -d "$context" ]]; then
echo "❌ Dir $context is not exist!"
exit 1
fi
cd $context
echo "ℹ️ 将从发布仓库下载源码进行构建"
_url="https://api.github.com/repos/sqzw-x/mdcx/releases/latest"
_content=$(curl -s "$_url")
# TODO github workflow里竟然会有比较大的概率获取失败
if [[ -z "$_content" ]]; then
echo "❌ 请求 $_url 失败!"
exit 1
fi
# tag名称,作为版本号
tagName=$(printf '%s' $_content | jq -r ".tag_name")
archiveVersion=$(echo $tagName | sed 's/v//g')
# 源码压缩包(tar格式)链接
archiveUrl=$(printf '%s' $_content | jq -r ".tarball_url")
if [[ -z "$archiveUrl" ]]; then
echo "❌ 从请求结果获取源码压缩包文件下载链接失败!"
echo "🔘 请求链接:$_url"
echo "🔘 请求结果:$_content"
exit 1
fi
if [[ -n "$verbose" ]]; then
echo "ℹ️ TAG名称: $tagName"
echo "🔗 下载链接: $archiveUrl"
fi
echo "ℹ️ 已发布版本: $archiveVersion"
if [[ -z "$archiveUrl" ]]; then
echo "❌ 从请求结果获取下载链接失败!"
exit 1
fi
echo "⏳ 下载文件..."
archivePath="$archiveVersion.tar.gz"
srcDir=".mdcx_src"
if [[ -n "$verbose" ]]; then
curl -o $archivePath $archiveUrl -L
else
curl -so $archivePath $archiveUrl -L
fi
echo "✅ 下载成功"
echo "⏳ 开始解压..."
# 使用tar命令解压
rm -rf $srcDir
mkdir -p $srcDir
tar -zxvf $archivePath -C $srcDir --strip-components 1
rm -f $archivePath
echo "✅ 源码已解压到 $srcDir"
if [ -n "$GITHUB_ACTIONS" ]; then
echo "APP_VERSION=$archiveVersion" >> $GITHUB_OUTPUT
fi