Search/run.sh

86 lines
1.5 KiB
Bash
Raw 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=""
2025-02-21 20:29:43 +01:00
CONFIG_FILE=""
2025-06-01 09:54:09 +02:00
BUILD_ONLY=0
PLATFORM="linux"
2024-12-05 00:24:47 +01:00
BUILD_OUTPUT="qgato"
# Parse arguments
while [ $# -gt 0 ]; do
case $1 in
--port)
PORT=$2
shift 2
;;
--domain)
DOMAIN=$2
shift 2
;;
2025-02-21 20:29:43 +01:00
--config)
CONFIG_FILE=$2
shift 2
;;
2025-06-01 09:54:09 +02:00
--platform)
PLATFORM=$2
shift 2
;;
--build-only)
BUILD_ONLY=1
shift
;;
--skip-config-check)
SKIP_CONFIG="--skip-config-check"
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")
2025-06-01 09:54:09 +02:00
# Set GOOS and output filename
if [ "$PLATFORM" = "windows" ]; then
GOOS=windows
BUILD_OUTPUT="qgato.exe"
else
GOOS=linux
BUILD_OUTPUT="qgato"
fi
2024-06-29 21:27:48 +02:00
2025-06-01 09:54:09 +02:00
# Clean and build
2025-01-08 00:29:21 +01:00
echo "Cleaning previous build..."
rm -f "$SCRIPT_DIR/$BUILD_OUTPUT"
2025-06-01 09:54:09 +02:00
echo "Building application for $PLATFORM..."
GOOS=$GOOS go build -ldflags="-s -w" -o "$SCRIPT_DIR/$BUILD_OUTPUT" .
2025-01-08 00:29:21 +01:00
if [ $? -eq 0 ]; then
echo "Build successful! Output: $SCRIPT_DIR/$BUILD_OUTPUT"
2024-12-05 00:24:47 +01:00
else
2025-01-08 00:29:21 +01:00
echo "Build failed!"
exit 1
fi
2025-06-01 09:54:09 +02:00
# Skip execution if build-only
if [ "$BUILD_ONLY" -eq 1 ]; then
exit 0
fi
2025-01-08 00:29:21 +01:00
# Construct the run command
CMD="$SCRIPT_DIR/$BUILD_OUTPUT $SKIP_CONFIG"
[ -n "$PORT" ] && CMD="$CMD --port $PORT"
[ -n "$DOMAIN" ] && CMD="$CMD --domain $DOMAIN"
2025-02-21 20:29:43 +01:00
[ -n "$CONFIG_FILE" ] && CMD="$CMD --config $CONFIG_FILE"
2025-01-08 00:29:21 +01:00
echo "Starting application with command: $CMD"
# Run the built executable
eval $CMD