-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
128 lines (98 loc) · 3.69 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
#!/usr/bin/env sh
# Installation Archives Builder
# Copyright (c) 2018-2020, VR25 (xda-developers)
# 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)
version=$(grep '\*\*.*\(.*\)\*\*' README.md \
| head -n 1 | sed 's/\*\*//; s/ .*//')
versionCode=$(grep '\*\*.*\(.*\)\*\*' README.md \
| head -n 1 | sed 's/\*\*//g; s/.* //' | tr -d ')' | tr -d '(')
tmpDir=.tmp/META-INF/com/google/android
# update module.prop
grep -q "$versionCode" module.prop || {
set_prop version $version
set_prop versionCode $versionCode
}
# set ID
for file in ./install*.sh ./$id/*.sh ./bundle.sh; do
if [ -f "$file" ] && grep -Eq '(^|\()id=' $file; then
grep -Eq "(^|\()id=$id" $file || set_prop id $id $file
fi
done
# update README
if [ README.md -ot $id/default-config.txt ] \
|| [ README.md -ot $id/strings.sh ]
then
# default config
set -e
{ sed -n '1,/#DC#/p' README.md; echo; cat $id/default-config.txt; \
echo; sed -n '/^#\/DC#/,$p' README.md; } > README.md.tmp
# terminal commands
{ sed -n '1,/#TC#/p' README.md.tmp; \
echo; sed -n '/^Usage/,/^ Run a/p' $id/strings.sh; \
echo; sed -n '/^#\/TC#/,$p' README.md.tmp; } > README.md
rm README.md.tmp
set +e
fi
# update busybox config (from acc/setup-busybox.sh) in $id/uninstall.sh and install scripts
set -e
for file in ./$id/uninstall.sh ./install*.sh; do
[ $file -ot $id/setup-busybox.sh ] && {
{ sed -n '1,/#BB#/p' $file; \
sed -n '/^if /,/^fi/p' $id/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 install-current.sh ### legacy
cp -u install.sh META-INF/com/google/android/update-binary; } 2>/dev/null
if [ bin/${id}-uninstaller.zip -ot $id/uninstall.sh ] || [ ! -f bin/${id}-uninstaller.zip ]; then
# generate $id uninstaller flashable zip
echo "=> bin/${id}-uninstaller.zip"
rm -rf bin/${id}-uninstaller.zip $tmpDir 2>/dev/null
mkdir -p bin $tmpDir
cp $id/uninstall.sh $tmpDir/update-binary
echo "#MAGISK" > $tmpDir/updater-script
(cd .tmp
zip -r9 ../bin/${id}-uninstaller.zip * \
| sed 's|.*adding: ||' | grep -iv 'zip warning:')
rm -rf .tmp
echo
fi
[ -z "$1" ] && {
# cleanup
rm -rf _builds/${id}_${version}_\(${versionCode}\)/ 2>/dev/null
mkdir -p _builds/${id}_${version}_\(${versionCode}\)/${id}_${version}_\(${versionCode}\)
# generate $id flashable zip
echo "=> _builds/${id}_${version}_(${versionCode})/${id}_${version}_(${versionCode}).zip"
zip -r9 _builds/${id}_${version}_\(${versionCode}\)/${id}_${version}_\(${versionCode}\).zip \
* .gitattributes .gitignore \
-x _\*/\* | sed 's|.*adding: ||' | grep -iv 'zip warning:'
echo
# prepare files to be included in $id installable tarball
cp install-tarball.sh _builds/${id}_${version}_\(${versionCode}\)/
cp -R ${id}/ install.sh *.md module.prop bin/ \
_builds/${id}_${version}_\(${versionCode}\)/${id}_${version}_\(${versionCode}\)/ 2>&1 \
| grep -iv "can't preserve"
# generate $id installable tarball
cd _builds/${id}_${version}_\(${versionCode}\)
echo "=> _builds/${id}_${version}_(${versionCode})/${id}_${version}_(${versionCode}).tar.gz"
tar -cvf - ${id}_${version}_\(${versionCode}\) | gzip -9 > ${id}_${version}_\(${versionCode}\).tar.gz
rm -rf ${id}_${version}_\(${versionCode}\)/
echo
})
exit 0