-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathff-src-part-ci.sh
executable file
·148 lines (121 loc) · 4.66 KB
/
ff-src-part-ci.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
#!/bin/bash
git checkout master
git clean -f
git clean -f -d
echo ""
echo ""
# 存储当前目录的路径到GITREPO
GITREPO="$(pwd)"
# 存储“$GITREPO/firefox-src-part”的路径到FF_SRC_GIT
FF_SRC_GIT="$GITREPO/firefox-src-part"
# 获取Firefox的最新版本并存到VER_LATEST
# 注意:这里假设有一个有效的API或方式来获取该最新版本
# VER_LATEST=$(wget -q -O - "https://api.github.com/repos/firefox/releases/latest" | awk -F '[:"]' '/tag_name/{print $4}')
# VER_LATEST="$(curl -s https://product-details.mozilla.org/1.0/firefox_versions.json| jq -r '.LATEST_FIREFOX_VERSION')" || exit 1
VER_LATEST="$(curl -s https://product-details.mozilla.org/1.0/firefox_versions.json| jq -r '.LATEST_FIREFOX_RELEASED_DEVEL_VERSION')" || exit 1
echo "Latest Firefox version: $VER_LATEST"
# 获取存储在$GITREPO/version.txt的版本号
VER_FILE=$(cat "$GITREPO/version.txt")
echo "Saved version: $VER_FILE"
# 使用 'sort -V' 将两个版本号进行比较,如果VER_LATEST版本号较大,则继续
if [[ ! $(printf '%s\n' "$VER_LATEST" "$VER_FILE" | sort -V | tail -n 1) = "$VER_LATEST" ]]
then
echo "No larger version found"
exit 0
fi
cd $HOME || exit 1
# 下载并解压VER_LATEST版本的Firefox源码到临时目录
# wget "https://example.com/path/to/firefox-$VER_LATEST.tar.gz"
SOURCE_TAR="firefox-${VER_LATEST}.source.tar.xz"
SOURCE_TAR_URL="https://ftp.mozilla.org/pub/firefox/releases/${VER_LATEST}/source/${SOURCE_TAR}"
echo "Download new source tarball ..."
wget --no-verbose "$SOURCE_TAR_URL" || exit 1
echo "Extract tarball..."
tar -xf "$SOURCE_TAR" || exit 1
ls # see extracted folder
# EXTRACTED_DIR="firefox-${VER_LATEST/esr/}"
EXTRACTED_DIR="$(find . -name "firefox*" -maxdepth 1 -type d)"
EXTRACTED_DIR=${EXTRACTED_DIR/\.\//}
FF_LATEST_TMP="$PWD/$EXTRACTED_DIR"
# 删除FF_SRC_GIT中除了.git之外的所有文件和目录
cd "$FF_SRC_GIT" || exit 1
pwd
echo "Delete old Firefox source..."
# find "$FF_SRC_GIT" -mindepth 1 ! -regex '^.*\.git.*$' -exec rm -r {} \;
rm -r * || exit 1
# 切换到FF_LATEST_TMP目录并执行$GITREPO/del-uneeded.sh
cd "$FF_LATEST_TMP" || exit 1
pwd
function del_uneeded() {
rm -r intl/icu \
third_party \
gfx \
toolkit/crashreporter \
toolkit/components/translation \
toolkit/components/protobuf \
toolkit/components/telemetry \
js \
dom/media/platforms \
devtools/docs \
security \
media \
modules/freetype2 \
modules/zlib \
mobile/android/fonts \
mobile/android/exoplayer2 \
other-licenses \
config/external/icu \
devtools/client/shared/sourceeditor/codemirror \
devtools/client/shared/vendor \
devtools/client/shared/build \
devtools/client/debugger/dist \
tools \
find . -iname "*test*" -exec rm -r {} \; 2>/dev/null
find . -iname "*benchmark*" -exec rm -r {} \; 2>/dev/null
find . -iname "*example*" -exec rm -r {} \; 2>/dev/null
find . \( -type f -and ! \( \
-name '*.xml' \
-or -name '*.mjs' \
-or -name '*.jsm' \
-or -name '*.html' \
-or -name '*.xhtml' \
-or -name '*.js' \
-or -name '*.jsx' \
-or -name '*.xul' \
-or -name '*.idl' \
-or -name '*nsI*' \
-or -name "*Glue*" \
-or -name "*.css" \
-or -name "*.scss" \
\) \) -delete 2>/dev/null
find . \( ! -name . -prune \) \( ! -name .. -prune \) -name ".*" -exec rm -r {} \; 2>/dev/null
while read -r line
do
rm "$line"
done< <(grep -rIL .)
#
# for file in $(find . -type f)
# do
# # 使用 grep -E 命令检查文件是否只包含空格或者换行
# if ! grep -Eq "\S" "$file"; then
# echo "empty file: $file"
# fi
# done
find . -type d -empty -delete 2>/dev/null
return 0
}
echo "Delete unneded files in new Firefox source ..."
del_uneeded || exit 1
# 将FF_LATEST_TMP中的所有文件和目录复制到FF_SRC_GIT
echo "Copy new codes to git folder..."
cp -r ./* "$FF_SRC_GIT" || exit 1
# 将VER_LATEST添加到$GITREPO/version.txt并进行git commit
echo "$VER_LATEST" > "$GITREPO/version.txt"
cd "$GITREPO" || exit 1
git config user.name bot
git config user.email [email protected]
git add . || exit
git commit -m "$VER_LATEST" || exit
git tag "$VER_LATEST"
git push -u origin || exit 1
git push -u origin --tags