Skip to content

Commit 5e55dc9

Browse files
committed
chore: sync with microG unofficial installer
Signed-off-by: ale5000 <15793015+ale5000-git@users.noreply.github.com>
1 parent 63d9723 commit 5e55dc9

File tree

5 files changed

+121
-9
lines changed

5 files changed

+121
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ user.gradle
6464
/docs/devel/
6565

6666
# Custom project folders
67+
/build-hooks/*.hook.sh
6768
/cache/
6869
/output/
6970
/recovery-simulator/output/

addition.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

build-hooks/README.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#####################
2+
Hook system for build
3+
#####################
4+
5+
..
6+
SPDX-FileCopyrightText: 2026 ale5000
7+
SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Archive-packaging-exception
8+
SPDX-FileType: DOCUMENTATION
9+
10+
This directory contains optional hooks to customize the build process. Each hook
11+
must be a shell script named following the pattern: ``<hook_name>.hook.sh``.
12+
13+
14+
How it works
15+
============
16+
17+
If a hook script exists in this folder, the build script will source (include)
18+
it at specific stages. Hooks run in the same shell environment as the main
19+
script, so they have access to all variables (like ``${TEMP_DIR:?}``,
20+
``${MODULE_VER:?}``, etc.).
21+
22+
23+
Available hooks
24+
===============
25+
26+
#. **pre_init** Triggered after core libraries are loaded and command-line
27+
parameters are parsed, but before loading configuration files. *Use case:*
28+
Override logic based on the selected ``${BUILD_TYPE:?}`` or modify early
29+
script flags before configurations are applied.
30+
31+
#. **post_init** Triggered after metadata extraction (ID, Version, Author) but
32+
before dependency checks. *Use case:* Dynamically modify the module version
33+
or add system requirements.
34+
35+
#. **pre_temp_create** Triggered before the temporary working directory is
36+
created.
37+
38+
#. **post_temp_create** Triggered once the temp directory is ready and cleared.
39+
40+
#. **pre_download** Triggered before starting any external file downloads (e.g.,
41+
via wget). *Use case:* Setup proxies, auth tokens, or custom download
42+
mirrors.
43+
44+
#. **pre_package** The last stage before compression. All files are ready in
45+
``${TEMP_DIR:?}/zip-content``. *Use case:* Patching files, minifying assets,
46+
or injecting dynamic data.
47+
48+
#. **post_package** Triggered after the unsigned ZIP is created, but before the
49+
signing process. *Use case:* Run custom integrity checks on the raw archive.
50+
51+
#. **post_sign** Triggered after the ZIP has been signed and zipaligned. *Use
52+
case:* Generate extra checksums.
53+
54+
#. **on_finish** Triggered after cleanup and hash calculation, just before the
55+
script exits. *Use case:* Send notifications (Telegram/Discord) or upload to
56+
a remote server.
57+
58+
59+
Guidelines
60+
==========
61+
62+
- **Extensions:** Files must end in ``.hook.sh``.
63+
- **Exit codes:** If a hook returns a non-zero exit code, the build process
64+
will be aborted immediately.
65+
- **Portability:** Write hooks in POSIX-compliant shell for maximum
66+
compatibility.
67+
68+
69+
Example (pre_package.hook.sh)
70+
=============================
71+
72+
.. code:: sh
73+
74+
#!/usr/bin/env sh
75+
echo 'Adding custom timestamp to info.prop...'
76+
date '+%s' 1>> "${TEMP_DIR:?}/zip-content/info.prop"

build.sh

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ esac
102102
save_last_title
103103
set_title 'Building the flashable zip...'
104104

105+
# [HOOK] pre_init: Early setup
106+
run_hook 'pre_init'
107+
105108
# shellcheck source=SCRIPTDIR/conf/conf-common.inc.sh
106109
. "${MAIN_DIR:?}/conf/conf-common.inc.sh"
107110
# shellcheck source=SCRIPTDIR/conf/conf-full.inc.sh
@@ -159,6 +162,9 @@ if test "${OPENSOURCE_ONLY:?}" != 'false'; then
159162
if test ! -f "${MAIN_DIR:?}/zip-content/settings-oss.conf"; then ui_error 'The settings file is missing' "${LINENO-}" "${FUNCNAME-}"; fi
160163
fi
161164

165+
# [HOOK] post_init: After metadata extraction but before dependency check
166+
run_hook 'post_init'
167+
162168
# Check dependencies
163169
command 1> /dev/null 2>&1 -v 'printf' || ui_error 'Missing: printf'
164170
command 1> /dev/null 2>&1 -v 'zip' || ui_error 'Missing: zip'
@@ -178,13 +184,19 @@ test "${JAVA_VER:-0}" -ge 17 || ui_error 'Java 17 or later is required' "${LINEN
178184
# Create the output dir
179185
mkdir -p "${OUT_DIR:?}" || ui_error 'Failed to create the output dir'
180186

187+
# [HOOK] pre_temp_create: Triggered before temp directory initialization
188+
run_hook 'pre_temp_create'
189+
181190
# Create the temp dir
182191
TEMP_DIR="$(mktemp -d -t ZIPBUILDER-XXXXXX)" || ui_error 'Failed to create our temp dir'
183192
if test -z "${TEMP_DIR}"; then ui_error 'Failed to create our temp dir'; fi
184193

185194
# Empty our temp dir (should be already empty, but we must be sure)
186195
rm -rf "${TEMP_DIR:?}"/* || ui_error 'Failed to empty our temp dir'
187196

197+
# [HOOK] post_temp_create: Ideal for injecting custom files into the temp directory
198+
run_hook 'post_temp_create'
199+
188200
# Set filename
189201
sanitize_filename_part()
190202
{
@@ -219,8 +231,8 @@ fi
219231
FILENAME="${FILENAME_START:?}${FILENAME_MIDDLE:?}${FILENAME_END:?}"
220232
FILENAME_EXT='.zip'
221233

222-
# shellcheck source=SCRIPTDIR/addition.sh
223-
. "${MAIN_DIR}/addition.sh"
234+
# [HOOK] pre_download: Triggered before starting any external file download
235+
run_hook 'pre_download'
224236

225237
# Download and verify external application files to ensure package integrity; bundled files will be verified at a later stage
226238
{
@@ -332,19 +344,28 @@ rm -f "${OUT_DIR:?}/${FILENAME_START:?}"*"${FILENAME_END:?}"*"${FILENAME_EXT:?}"
332344
rm -f "${OUT_DIR:?}/${FILENAME_START:?}"*"${FILENAME_END:?}"*"${FILENAME_EXT:?}".md5 || ui_error 'Failed to remove the previously built files' "${LINENO-}" "${FUNCNAME-}"
333345
rm -f "${OUT_DIR:?}/${FILENAME_START:?}"*"${FILENAME_END:?}"*"${FILENAME_EXT:?}".sha256 || ui_error 'Failed to remove the previously built files' "${LINENO-}" "${FUNCNAME-}"
334346

347+
# [HOOK] pre_package: Last chance to modify content before zipping
348+
run_hook 'pre_package'
349+
335350
# Compress (it ensure that the list of files to compress is in the same order under all OSes)
336351
# Note: Unicode filenames in the zip are disabled since we don't need them and also zipsigner.jar chokes on them
337352
cd "${TEMP_DIR}/zip-content" || ui_error 'Failed to change the folder' "${LINENO-}" "${FUNCNAME-}"
338353
echo 'Zipping...'
339354
find . -type f | LC_ALL=C sort | zip -D -9 -X -UN=n -nw "${TEMP_DIR}/flashable${FILENAME_EXT:?}" -@ || ui_error 'Failed compressing' "${LINENO-}" "${FUNCNAME-}"
340355
FILENAME="${FILENAME:?}-signed"
341356

357+
# [HOOK] post_package: Triggered after compression, but before signing
358+
run_hook 'post_package'
359+
342360
# Sign and zipalign
343361
echo ''
344362
echo 'Signing and zipaligning...'
345363
mkdir -p "${TEMP_DIR:?}/zipsign"
346364
java -Duser.timezone=UTC -Dzip.encoding=Cp437 -Djava.io.tmpdir="${TEMP_DIR:?}/zipsign" -jar "${MAIN_DIR:?}/tools/zipsigner.jar" "${TEMP_DIR:?}/flashable${FILENAME_EXT:?}" "${TEMP_DIR:?}/${FILENAME:?}${FILENAME_EXT:?}" || ui_error 'Failed signing and zipaligning' "${LINENO-}" "${FUNCNAME-}"
347365

366+
# [HOOK] post_sign: Triggered after the signing process is complete
367+
run_hook 'post_sign'
368+
348369
if test "${FAST_BUILD:-false}" = 'false'; then
349370
echo ''
350371
zip -T "${TEMP_DIR:?}/${FILENAME:?}${FILENAME_EXT:?}" || ui_error 'The zip file is corrupted' "${LINENO-}" "${FUNCNAME-}"
@@ -397,14 +418,16 @@ if test "${GITHUB_JOB:-false}" != 'false'; then
397418
} >> "${GITHUB_OUTPUT?}"
398419
fi
399420

421+
set +e
400422
cd "${_init_dir:?}" || ui_error 'Failed to change back the folder' "${LINENO-}" "${FUNCNAME-}"
401423

424+
# [HOOK] on_finish: Final hook for notifications or moving files to a server
425+
run_hook 'on_finish'
426+
402427
echo ''
403428
echo 'Done.'
404429
set_title 'Done'
405430

406-
set +e
407-
408431
# Ring bell
409432
beep
410433

lib/main.lib.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: GPL-3.0-or-later WITH LicenseRef-Archive-packaging-exception
44

55
# shellcheck enable=all
6+
# shellcheck disable=SC2240 # Ignore: The dot command does not support arguments in sh/dash
67
# shellcheck disable=SC3028 # Ignore: In POSIX sh, FUNCNAME is undefined
78
# shellcheck disable=SC3043 # Ignore: In POSIX sh, 'local' is undefined
89

@@ -118,6 +119,17 @@ ui_nl()
118119
printf 1>&2 '\n'
119120
}
120121

122+
run_hook()
123+
{
124+
local hook_file="${MAIN_DIR:?}/build-hooks/${1:?}.hook.sh"
125+
126+
if test -f "${hook_file:?}"; then
127+
ui_debug "Running hook: ${1?}..."
128+
# shellcheck source=/dev/null
129+
. "${hook_file:?}" "${hook_file:?}" "${@}" || ui_error "Hook '${1?}' failed with exit code ${?}" "${LINENO-}" "${FUNCNAME-}"
130+
fi
131+
}
132+
121133
export DL_DEBUG="${DL_DEBUG:-false}"
122134
export http_proxy="${http_proxy-}"
123135
export ftp_proxy="${ftp_proxy-}"
@@ -1594,6 +1606,11 @@ init_cmdline()
15941606
HOME="${USER_HOME:-${HOME:?}}" command -- bundle "${@}"
15951607
}
15961608

1609+
bundler()
1610+
{
1611+
HOME="${USER_HOME:-${HOME:?}}" command -- bundler "${@}"
1612+
}
1613+
15971614
if test "${CI:-false}" = 'false'; then
15981615
PS1="${__DEFAULT_PS1:?}"
15991616
PROMPT_COMMAND='__update_title_and_ps1 "${@}" || true'

0 commit comments

Comments
 (0)