-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
build.sh
159 lines (123 loc) · 4.5 KB
/
build.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
#!/usr/bin/env sh
# Installation Archives Builder
# Copyright 2018-2022, VR25
# License: GPLv3+
#
# usage: $0 [any_random_arg]
# e.g.,
# build.sh (builds $id and generates installable archives)
# build.sh any_random_arg (only builds $id)
(cd ${0%/*} 2>/dev/null
. ./check-syntax.sh || exit $?
set_prop() {
sed -i -e "s/^($1=.*/($1=$2/" -e "s/^$1=.*/$1=$2/" \
${3:-module.prop} 2>/dev/null
}
id=$(sed -n "s/^id=//p" module.prop)
domain=$(sed -n "s/^domain=//p" module.prop)
version="$(sed -n 1p changelog.md | sed 's/[*()]//g')"
versionCode=${version#* }
version=${version% *}
basename=${id}_${version}_$versionCode
tmpDir=.tmp/META-INF/com/google/android
# update module info
[ changelog.md -ot module.prop ] || {
set_prop version $version
set_prop versionCode $versionCode
cat << EOF > module.json
{
"busybox": "https://github.com/Magisk-Modules-Repo/busybox-ndk",
"changelog": "https://raw.githubusercontent.com/VR-25/$id/master/changelog.md",
"curl": "https://github.com/Zackptg5/Cross-Compiled-Binaries-Android/tree/master/curl",
"onlineInstaller": "https://github.com/VR-25/$id/releases/download/$version/install-online.sh",
"tgz": "https://github.com/VR-25/$id/releases/download/$version/${basename}.tgz",
"tgzInstaller": "https://github.com/VR-25/$id/releases/download/$version/install-tarball.sh",
"version": "$version",
"versionCode": $versionCode,
"zipUrl": "https://github.com/VR-25/$id/releases/download/$version/${basename}.zip"
}
EOF
}
# set ID
for file in ./install*.sh ./install/*.sh ./bundle.sh; do
if [ -f "$file" ] && grep -Eq '(^|\()id=' $file; then
grep -Eq "(^|\()id=$id" $file || set_prop id $id $file
fi
done
# set domain
for file in ./install*.sh ./install/*.sh ./bundle.sh; do
if [ -f "$file" ] && grep -Eq '(^|\()domain=' $file; then
grep -Eq "(^|\()domain=$domain" $file || set_prop domain $domain $file
fi
done
# update README
if [ README.md -ot install/default-config.txt ] \
|| [ README.md -ot install/strings.sh ] \
|| [ README.md -nt README.html ]
then
# default config
set -e
{ sed -n '1,/#DC#/p' README.md; echo; cat install/default-config.txt; \
echo; sed -n '/^#\/DC#/,$p' README.md; } > README.md.tmp
# terminal commands
{ sed -n '1,/#TC#/p' README.md.tmp; \
echo; . ./install/strings.sh; print_help; \
echo; sed -n '/^#\/TC#/,$p' README.md.tmp; } > README.md
rm README.md.tmp
set +e
markdown README.md > README.html
fi
# update busybox config (from install/setup-busybox.sh) in install/uninstall.sh and install scripts
set -e
for file in ./install/uninstall.sh ./install*.sh; do
[ $file -ot install/setup-busybox.sh ] && {
{ sed -n '1,/#BB#/p' $file; \
grep -Ev '^$|^#' install/setup-busybox.sh; \
sed -n '/^#\/BB#/,$p' $file; } > ${file}.tmp
mv -f ${file}.tmp $file
}
done
set +e
# unify installers for flashable zip (customize.sh and update-binary are copies of install.sh)
{ cp -u install.sh customize.sh
cp -u install.sh META-INF/com/google/android/update-binary; } 2>/dev/null
if [ bin/${id}_flashable_uninstaller.zip -ot install/uninstall.sh ] || [ ! -f bin/${id}_flashable_uninstaller.zip ]; then
# generate $id uninstaller flashable zip
echo "=> bin/${id}_flashable_uninstaller.zip"
rm -rf bin/${id}_flashable_uninstaller.zip $tmpDir 2>/dev/null
mkdir -p bin $tmpDir
sed 's|#!/system/bin/sh|#!/sbin/sh|' install/uninstall.sh > $tmpDir/update-binary
echo "#MAGISK" > $tmpDir/updater-script
(cd .tmp
zip -r9 ../bin/${id}_flashable_uninstaller.zip * \
| sed 's|.*adding: ||' | grep -iv 'zip warning:')
rm -rf .tmp
echo
fi
[ -z "$1" ] && {
# cleanup
rm -rf _builds/${basename}/ 2>/dev/null
mkdir -p _builds/${basename}/${basename}
cp bin/${id}_flashable_uninstaller.zip install-online.sh install-tarball.sh _builds/${basename}/
# generate $id flashable zip
case $version in
*-*) basename_=${basename}_$(date +%H%M);;
*) basename_=$basename;;
esac
echo "=> _builds/${basename}/${basename_}.zip"
zip -r9 _builds/${basename}/${basename_}.zip \
* .gitattributes .gitignore .github \
-x _\*/\* | sed 's|.*adding: ||' | grep -iv 'zip warning:'
echo
# prepare files to be included in $id installable tarball
cp -R install install.sh License.md README.* module.prop bin/ \
_builds/${basename}/${basename}/ 2>&1 \
| grep -iv "can't preserve"
# generate $id installable tarball
cd _builds/${basename}
echo "=> _builds/${basename}/${basename}.tgz"
tar -cvf - ${basename} | gzip -9 > ${basename}.tgz
rm -rf ${basename}/
echo
})
exit 0