Skip to content

Commit da8d869

Browse files
fix(termux-bootstrap-second-stage.sh): do not exit with the wrong "second stage has already been run before" error if ln process used to create lock file got killed instead of failing to create lock file if it already existed
Related termux/termux-app#4219
1 parent a292391 commit da8d869

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

scripts/bootstrap/termux-bootstrap-second-stage.sh

+43-5
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,29 @@ run_bootstrap_second_stage() {
9292

9393
local return_value
9494

95-
if ! ln -s "termux-bootstrap-second-stage.sh" \
96-
"@TERMUX_BOOTSTRAPS__BOOTSTRAP_CONFIG_DIR@/termux-bootstrap-second-stage.sh.lock" 2>/dev/null; then
97-
log "The termux bootstrap second stage has already been run before and cannot be run again."
98-
log "If you still want to force run it again (not recommended), \
95+
local output
96+
97+
output="$(ln -s "termux-bootstrap-second-stage.sh" \
98+
"@TERMUX_BOOTSTRAPS__BOOTSTRAP_CONFIG_DIR@/termux-bootstrap-second-stage.sh.lock" 2>&1)"
99+
return_value=$?
100+
if [ $return_value -ne 0 ]; then
101+
if [ $return_value -eq 1 ] && [[ "$output" == *"File exists"* ]]; then
102+
log "The termux bootstrap second stage has already been run before and cannot be run again."
103+
log "If you still want to force run it again (not recommended), \
99104
like in case of previous failure and it must be re-run again for testing, \
100105
then delete the '@TERMUX_BOOTSTRAPS__BOOTSTRAP_CONFIG_DIR@/termux-bootstrap-second-stage.sh.lock' \
101106
file manually and run 'termux-bootstrap-second-stage.sh' again."
102-
return 0
107+
return 0
108+
else
109+
log_error "$output"
110+
log_error "Failed to create lock file for termux bootstrap second stage at \
111+
'@TERMUX_BOOTSTRAPS__BOOTSTRAP_CONFIG_DIR@/termux-bootstrap-second-stage.sh.lock'"
112+
warn_if_process_killed "$return_value" "ln"
113+
return $return_value
114+
fi
103115
fi
104116

117+
105118
log "Running termux bootstrap second stage"
106119
run_bootstrap_second_stage_inner
107120
return_value=$?
@@ -112,6 +125,7 @@ file manually and run 'termux-bootstrap-second-stage.sh' again."
112125

113126
log "The termux bootstrap second stage completed successfully"
114127

128+
115129
return 0
116130

117131
}
@@ -360,6 +374,30 @@ run_package_postinst_maintainer_scripts() {
360374

361375
}
362376

377+
378+
379+
380+
381+
warn_if_process_killed() {
382+
383+
local return_value="${1:-}"
384+
local command="${2:-}"
385+
386+
if [[ "$return_value" == "137" ]]; then
387+
log_error "The '$command' command was apparently killed with SIGKILL (signal 9). \
388+
This may have been due to the security policies of the Android OS installed on your device.
389+
Check https://github.com/termux/termux-app/issues/4219 for more info."
390+
return 0
391+
fi
392+
393+
return 1
394+
395+
}
396+
397+
398+
399+
400+
363401
# If running in bash, run script logic, otherwise exit with usage error
364402
if [ -n "${BASH_VERSION:-}" ]; then
365403
# If script is sourced, return with error, otherwise call main function

0 commit comments

Comments
 (0)