-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_mod.sh
executable file
·167 lines (146 loc) · 5.48 KB
/
create_mod.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
160
161
162
163
164
165
166
167
#!/usr/bin/env sh
set -e
error() { echo "$@" >&2; }
USAGE=$(
cat <<-END
Usage: $0 [OPTION]...
-e early exit if no updates
-n additionally build the netinst version
-h display this help and exit
Home page: <https://github.com/qianbinbin/fdroid-priv-ext>
END
)
_exit() {
error "$USAGE"
exit 2
}
EARLY_EXIT=false
NETINST=false
while getopts "enh" c; do
case $c in
e) EARLY_EXIT=true ;;
n) NETINST=true ;;
h) error "$USAGE" && exit ;;
*) _exit ;;
esac
done
shift $((OPTIND - 1))
[ $# -ne 0 ] && _exit
PROG_DIR=$(dirname "$(realpath "$0")")
cd "$PROG_DIR"
OUT_DIR="$PROG_DIR/build"
[ ! -d "$OUT_DIR" ] && mkdir -p "$OUT_DIR"
TMP_DIR=$(mktemp -d -t fpe.tmp.XXXXXXXX)
trap 'rm -rf "$TMP_DIR"' EXIT
FDROID_NAME=F-Droid
FPE_NAME=F-DroidPrivilegedExtension
FDROID_PKG=org.fdroid.fdroid
FPE_PKG="$FDROID_PKG.privileged"
FPE_OTA_PKG="$FPE_PKG.ota"
FPE_OTA_OLD_VC=$(sed -n 's/^fpeOtaVersionCode=//p' module.prop)
FPE_OTA_NEW_VC=$(curl --compressed -fsSL "https://f-droid.org/api/v1/packages/$FPE_OTA_PKG" | jq '.suggestedVersionCode')
FDROID_OLD_VC=$(sed -n 's/^fdroidVersionCode=//p' module.prop)
FDROID_NEW_VC=$(curl --compressed -fsSL "https://f-droid.org/api/v1/packages/$FDROID_PKG" | jq '.suggestedVersionCode')
MOD_VER=$(sed -n 's/^versionCode=//p' module.prop)
UPGRADE=false
if [ "$FPE_OTA_OLD_VC" -eq "$FPE_OTA_NEW_VC" ]; then
error "$FPE_OTA_PKG is already the newest version ($FPE_OTA_OLD_VC)."
else
error "==> Upgrading:"
error "$FPE_OTA_PKG $FPE_OTA_OLD_VC -> $FPE_OTA_NEW_VC"
UPGRADE=true
fi
if [ "$FDROID_OLD_VC" -eq "$FDROID_NEW_VC" ]; then
error "$FDROID_PKG is already the newest version ($FDROID_OLD_VC)."
else
error "==> Upgrading:"
error "$FDROID_PKG $FDROID_OLD_VC -> $FDROID_NEW_VC"
UPGRADE=true
fi
[ "$EARLY_EXIT" = true ] && [ "$UPGRADE" != true ] && exit
[ "$UPGRADE" = true ] && MOD_VER=$(date +%Y%m%d)
error "==> Fetching info"
INDEX_URL="https://f-droid.org/repo/index-v1.json"
INDEX_JSON="$TMP_DIR/index-v1.json"
curl --compressed -L "$INDEX_URL" >"$INDEX_JSON"
FPE_OTA_INFO=$(jq ".packages.\"$FPE_OTA_PKG\" | .[] | select(.versionCode==$FPE_OTA_NEW_VC)" "$INDEX_JSON")
FPE_OTA_ZIP=$(echo "$FPE_OTA_INFO" | jq -r '.apkName')
if [ "$(echo "$FPE_OTA_INFO" | jq -r '.hashType')" = sha256 ]; then
FPE_OTA_SHA256=$(echo "$FPE_OTA_INFO" | jq -r '.hash')
fi
FPE_OTA_URL="https://f-droid.org/repo/$FPE_OTA_ZIP"
FDROID_INFO=$(jq ".packages.\"$FDROID_PKG\" | .[] | select(.versionCode==$FDROID_NEW_VC)" "$INDEX_JSON")
if [ "$(echo "$FDROID_INFO" | jq -r '.hashType')" = sha256 ]; then
FDROID_SHA256=$(echo "$FDROID_INFO" | jq -r '.hash')
fi
FDROID_URL="https://f-droid.org/repo/$(echo "$FDROID_INFO" | jq -r '.apkName')"
rm -f "$INDEX_JSON"
verify_sha256() {
actual=$(sha256sum "$1" | awk '{ print $1 }')
if [ "$actual" != "$2" ]; then
error "$actual != $2"
return 1
fi
}
error "==> Downloading $FPE_OTA_URL"
curl -L "$FPE_OTA_URL" >"$TMP_DIR/$FPE_OTA_ZIP"
if [ -n "$FPE_OTA_SHA256" ]; then
error "==> Verifying checksum"
verify_sha256 "$TMP_DIR/$FPE_OTA_ZIP" "$FPE_OTA_SHA256"
else
error "==> Skipping checksum verification"
fi
error "==> Extracting files from $FPE_OTA_ZIP"
mkdir -p "$TMP_DIR/system/app/$FDROID_NAME" "$TMP_DIR/system/priv-app/$FPE_NAME" "$TMP_DIR/system/etc/permissions"
unzip "$TMP_DIR/$FPE_OTA_ZIP" "$FPE_NAME.apk" -d "$TMP_DIR/system/priv-app/$FPE_NAME"
unzip "$TMP_DIR/$FPE_OTA_ZIP" permissions_org.fdroid.fdroid.privileged.xml -d "$TMP_DIR/system/etc/permissions"
error "==> Downloading $FDROID_URL"
curl -L "$FDROID_URL" >"$TMP_DIR/system/app/$FDROID_NAME/$FDROID_NAME.apk"
if [ -n "$FDROID_SHA256" ]; then
error "==> Verifying checksum"
verify_sha256 "$TMP_DIR/system/app/$FDROID_NAME/$FDROID_NAME.apk" "$FDROID_SHA256"
else
error "==> Skipping checksum verification"
fi
rm -f "$TMP_DIR/$FPE_OTA_ZIP"
error "==> Collecting files"
DUMB_DIR="$TMP_DIR/META-INF/com/google/android"
mkdir -p "$DUMB_DIR"
curl --compressed -L https://raw.githubusercontent.com/topjohnwu/Magisk/master/scripts/module_installer.sh >"$DUMB_DIR/update-binary"
chmod +x "$DUMB_DIR/update-binary"
echo "#MAGISK" >"$DUMB_DIR/updater-script"
chmod +x "$DUMB_DIR/updater-script"
cp customize.sh "$TMP_DIR"
if [ "$UPGRADE" = true ]; then
sed -e "s/^version=.*$/version=$MOD_VER/g" \
-e "s/^versionCode=.*$/versionCode=$MOD_VER/g" \
-e "s/^fpeOtaVersionCode=.*$/fpeOtaVersionCode=$FPE_OTA_NEW_VC/g" \
-e "s/^fdroidVersionCode=.*$/fdroidVersionCode=$FDROID_NEW_VC/g" module.prop >"$TMP_DIR/module.prop"
cp "$TMP_DIR/module.prop" module.prop
else
cp module.prop "$TMP_DIR"
fi
error "==> Creating zip"
FPE_MOD_ZIP="$FPE_PKG.mod_$MOD_VER.zip"
cd "$TMP_DIR"
zip -r "$OUT_DIR/$FPE_MOD_ZIP" .
error "$OUT_DIR/$FPE_MOD_ZIP"
if [ "$NETINST" = true ]; then
FPE_MOD_NETINST_ZIP="$FPE_PKG.mod.netinst_$MOD_VER-beta.zip"
rm -rf system customize.sh
cp "$PROG_DIR/customize-netinst.sh" customize.sh
sed 's/^\(updateJson=.*\)\.json$/\1-netinst.json/g' "$PROG_DIR/module.prop" >module.prop
zip -r "$OUT_DIR/$FPE_MOD_NETINST_ZIP" .
error "$OUT_DIR/$FPE_MOD_NETINST_ZIP"
fi
cd "$PROG_DIR"
if [ "$UPGRADE" = true ]; then
error "==> Updating CHANGELOG"
{
echo "### $MOD_VER" && echo
[ "$FPE_OTA_OLD_VC" -ne "$FPE_OTA_NEW_VC" ] && echo "- $FPE_OTA_PKG $FPE_OTA_OLD_VC -> $FPE_OTA_NEW_VC" && echo
[ "$FDROID_OLD_VC" -ne "$FDROID_NEW_VC" ] && echo "- $FDROID_PKG $FDROID_OLD_VC -> $FDROID_NEW_VC" && echo
} >"$TMP_DIR/CHANGELOG.md"
[ -f CHANGELOG.md ] && cat CHANGELOG.md >>"$TMP_DIR/CHANGELOG.md"
mv "$TMP_DIR/CHANGELOG.md" CHANGELOG.md
fi