Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions start-automaker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,35 @@ set -e
# ============================================================================
# CONFIGURATION & CONSTANTS
# ============================================================================
# Resolve script directory, following symlinks
SOURCE="${BASH_SOURCE[0]}"
while [ -L "$SOURCE" ]; do
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
done

# Verify the resolved script exists (detect broken symlinks)
if [ ! -f "$SOURCE" ]; then
echo "Error: Script file not found after resolving symlinks: $SOURCE" >&2
exit 1
fi

SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the script more robust against dangling symlinks, it's good practice to verify that the resolved script path actually exists and is a file before proceeding. This prevents the script from silently running in the wrong directory if a symlink is broken, which can lead to confusing downstream errors.

Suggested change
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
if [ ! -f "$SOURCE" ]; then
echo "Error: Script file not found after resolving symlinks: $SOURCE" >&2
exit 1
fi
SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"


# Change to project directory so all relative paths work
cd "$SCRIPT_DIR" || {
echo "Error: Could not change to project directory: $SCRIPT_DIR" >&2
exit 1
}

# Load .env file if it exists (must be after cd to project directory)
if [ -f .env ]; then
set -a
. ./.env
set +a
fi
APP_NAME="Automaker"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

HISTORY_FILE="${HOME}/.automaker_launcher_history"
MIN_TERM_WIDTH=70
MIN_TERM_HEIGHT=20
Expand Down Expand Up @@ -1158,9 +1180,6 @@ fi
# Execute the appropriate command
case $MODE in
web)
if [ -f .env ]; then
export $(grep -v '^#' .env | xargs)
fi
export TEST_PORT="$WEB_PORT"
export VITE_SERVER_URL="http://${APP_HOST}:$SERVER_PORT"
export PORT="$SERVER_PORT"
Expand Down
Loading