fix(#2): validate binary before exec in start.sh

Resolves #2: start.sh fails with "Is a directory" error

Added pre-exec validation to check the binary exists, is a regular file,
and is executable. Improved build failure handling so the script stops
with a clear message instead of trying to exec a missing/invalid binary.

Files modified:
- start.sh

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
tr4m0ryp 2026-04-12 20:06:49 +02:00
parent 58f04f2be0
commit 904ac4523c

View file

@ -213,16 +213,31 @@ install_deps() {
# ------------------------------------------------------------------ # # ------------------------------------------------------------------ #
build_project() { build_project() {
if [ -x "$BINARY" ]; then if [ -f "$BINARY" ] && [ -x "$BINARY" ]; then
msg_ok "Binary already built: $BINARY" msg_ok "Binary already built: $BINARY"
return 0 return 0
fi fi
# If a directory exists where the binary should be, the build cannot proceed
if [ -d "$BINARY" ]; then
msg_err "Expected binary at $BINARY but found a directory."
msg_info "Remove it and rebuild: rm -rf '$BINARY' && make clean && make"
exit 1
fi
msg_info "Building tr4mpass..." msg_info "Building tr4mpass..."
(cd "$SCRIPT_DIR" && make clean && make) if ! (cd "$SCRIPT_DIR" && make clean && make); then
msg_err "Build failed. Check compiler output above."
exit 1
fi
if [ ! -f "$BINARY" ]; then
msg_err "Build completed but binary not found at $BINARY."
exit 1
fi
if [ ! -x "$BINARY" ]; then if [ ! -x "$BINARY" ]; then
msg_err "Build failed. Check compiler output above." msg_err "Binary exists but is not executable. Run: chmod +x $BINARY"
exit 1 exit 1
fi fi
@ -512,6 +527,22 @@ main() {
msg_info "Starting tr4mpass..." msg_info "Starting tr4mpass..."
echo "" echo ""
# Final validation before exec
if [ ! -e "$BINARY" ]; then
msg_err "Binary not found at $BINARY. Build may have failed."
msg_info "Run 'make' manually to see errors."
exit 1
fi
if [ -d "$BINARY" ]; then
msg_err "Expected binary at $BINARY but found a directory."
msg_info "Remove it and rebuild: rm -rf '$BINARY' && make clean && make"
exit 1
fi
if [ ! -x "$BINARY" ]; then
msg_err "Binary exists but is not executable. Run: chmod +x $BINARY"
exit 1
fi
exec "$BINARY" "$@" exec "$BINARY" "$@"
} }