58 lines
1.4 KiB
Bash
Executable File
58 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Set error handling
|
|
set -e
|
|
|
|
# Function to cleanup resources on exit
|
|
cleanup() {
|
|
echo "Cleaning up resources..."
|
|
|
|
# Kill Xvfb if it's running
|
|
if [ -n "$XVFB_PID" ] && ps -p $XVFB_PID > /dev/null; then
|
|
echo "Stopping Xvfb (PID: $XVFB_PID)"
|
|
kill $XVFB_PID || true
|
|
fi
|
|
|
|
# Remove X lock files if they exist
|
|
if [ -e "/tmp/.X99-lock" ]; then
|
|
echo "Removing X lock file"
|
|
rm -f /tmp/.X99-lock
|
|
fi
|
|
|
|
echo "Cleanup complete"
|
|
}
|
|
|
|
# Register the cleanup function to run on script exit
|
|
trap cleanup EXIT
|
|
|
|
# Check if X lock file exists and remove it (in case of previous unclean shutdown)
|
|
if [ -e "/tmp/.X99-lock" ]; then
|
|
echo "Removing existing X lock file"
|
|
rm -f /tmp/.X99-lock
|
|
fi
|
|
|
|
# Start Xvfb with display :99
|
|
echo "Starting Xvfb on display :99"
|
|
Xvfb :99 -screen 0 1280x1024x24 -ac &
|
|
XVFB_PID=$!
|
|
|
|
# Wait a moment for Xvfb to initialize
|
|
sleep 2
|
|
|
|
# Check if Xvfb started successfully
|
|
if ! ps -p $XVFB_PID > /dev/null; then
|
|
echo "Failed to start Xvfb"
|
|
exit 1
|
|
fi
|
|
|
|
# Export the DISPLAY variable for the browser
|
|
export DISPLAY=:99
|
|
|
|
echo "Xvfb started successfully with PID: $XVFB_PID"
|
|
echo "DISPLAY set to: $DISPLAY"
|
|
|
|
# Start the Camoufox server with all arguments passed to this script
|
|
echo "Starting Camoufox server with arguments:"
|
|
printf " Arg: '%s'\n" "$@" # Print each argument quoted on a new line
|
|
echo "Executing: python3 camoufox_server.py $@"
|
|
python3 camoufox_server.py "$@" |