Search/run.sh

72 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2024-06-15 18:12:01 +02:00
#!/bin/sh
2024-04-10 22:40:12 +02:00
# Initialize variables
SKIP_CONFIG=""
PORT=""
DOMAIN=""
2024-12-05 00:24:47 +01:00
BUILD_MODE=false
BUILD_OUTPUT="qgato"
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
--port)
PORT=$2
shift 2
;;
--domain)
DOMAIN=$2
shift 2
;;
--skip-config-check)
SKIP_CONFIG="--skip-config-check"
shift
;;
2024-12-05 00:24:47 +01:00
--build)
BUILD_MODE=true
shift
;;
*)
echo "Unknown argument: $1"
exit 1
;;
esac
done
2024-12-05 00:24:47 +01:00
# Get the directory of the script
SCRIPT_DIR=$(dirname "$0")
# List all Go files in the script directory (excluding test files)
GO_FILES=$(find "$SCRIPT_DIR" -name '*.go' ! -name '*_test.go' -print)
2024-06-29 21:27:48 +02:00
2024-12-05 00:24:47 +01:00
if $BUILD_MODE; then
# Build mode
echo "Building application..."
go build -o "$SCRIPT_DIR/$BUILD_OUTPUT" $GO_FILES
if [ $? -eq 0 ]; then
echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT"
else
echo "Build failed!"
exit 1
fi
else
# Run mode
CMD="./$BUILD_OUTPUT $SKIP_CONFIG"
2024-12-05 00:24:47 +01:00
[ -n "$PORT" ] && CMD="$CMD --port $PORT"
[ -n "$DOMAIN" ] && CMD="$CMD --domain $DOMAIN"
if [ ! -f "$SCRIPT_DIR/$BUILD_OUTPUT" ]; then
echo "Executable not found. Building it first..."
go build -o "$SCRIPT_DIR/$BUILD_OUTPUT" $GO_FILES
if [ $? -ne 0 ]; then
echo "Build failed! Unable to run the application."
exit 1
fi
fi
2024-12-05 00:24:47 +01:00
echo "Starting application with command: $CMD"
# Run the executable
2024-12-05 00:24:47 +01:00
eval $CMD
fi