forked from northsea4/mdcx-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-src.sh
executable file
·105 lines (86 loc) · 2.32 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
#!/bin/sh
# 脚本说明:下载应用源码并解压到指定的目录(通过`context`指定)下的`.mdcx_src`目录
# 一般只用于构建镜像流程,普通用户可以忽略。
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 "ℹ️ 将从发布仓库下载源码进行构建"
_content=$(curl -s "https://api.github.com/repos/anyabc/something/releases/latest")
archiveUrl=$(echo $_content | grep -oi 'https://[a-zA-Z0-9./?=_%:-]*MDCx-py-[a-z0-9]\+.[a-z]\+')
# TODO github workflow里竟然会有比较大的概率获取失败
if [[ -z "$archiveUrl" ]]; then
echo "❌ 获取下载链接失败!"
exit 1
fi
archiveFullName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+.[a-z]\+')
archiveExt=$(echo $archiveFullName | grep -oi '[a-z]\+$')
archiveVersion=$(echo $archiveFullName | sed 's/MDCx-py-//g' | sed 's/\.[^.]*$//')
archivePureName=$(echo $archiveUrl | grep -oi 'MDCx-py-[a-z0-9]\+')
if [[ -n "$verbose" ]]; then
echo "🔗 下载链接: $archiveUrl"
echo "ℹ️ 压缩包全名: $archiveFullName"
echo "ℹ️ 压缩包文件名: $archivePureName"
echo "ℹ️ 压缩包后缀名: $archiveExt"
fi
echo "ℹ️ 已发布版本: $archiveVersion"
if [[ -z "$archiveUrl" ]]; then
echo "❌ 从请求结果获取下载链接失败!"
exit 1
fi
echo "⏳ 下载文件..."
archivePath="$archivePureName.rar"
srcDir=".mdcx_src"
if [[ -n "$verbose" ]]; then
curl -o $archivePath $archiveUrl -L
else
curl -so $archivePath $archiveUrl -L
fi
echo "✅ 下载成功"
echo "⏳ 开始解压..."
UNRAR_PATH=$(which unrar)
if [[ -z "$UNRAR_PATH" ]]; then
echo "❌ 没有unrar命令!"
exit 1
else
rm -rf $srcDir
# 解压
unrar x -o+ $archivePath
mkdir -p $srcDir
cp -rfp $archivePureName/* $srcDir
# 删除压缩包
rm -f $archivePath
# 删除解压出来的目录
rm -rf $archivePureName
echo "✅ 源码已解压到 $srcDir"
fi
if [ -n "$GITHUB_ACTIONS" ]; then
echo "APP_VERSION=$archiveVersion" >> $GITHUB_OUTPUT
fi