Skip to content

Instantly share code, notes, and snippets.

@XxUnkn0wnxX
Last active October 16, 2023 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XxUnkn0wnxX/c8c42f5784c99a516276736c4e6e87e5 to your computer and use it in GitHub Desktop.
Save XxUnkn0wnxX/c8c42f5784c99a516276736c4e6e87e5 to your computer and use it in GitHub Desktop.
macOS runtime script for trickster-is-weak/Surviving-Maps
#!/usr/bin/env zsh
# Set custom environment variables
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home" # set your java 17 home path
export PATH="/usr/local/opt/gradle@7/bin:$PATH" # set your gradle 7 path
# Get the directory where the script is located
script_dir=$(dirname "$0")
# Change the current working directory to the script's directory
cd "$script_dir"
# Function to read server.port from application.properties
function get_server_port() {
# Define the path to the application.properties file
properties_file="src/main/resources/application.properties"
# Check if the file exists
if [[ ! -f "$properties_file" ]]; then
echo "The application.properties file does not exist."
exit 1
fi
# Parse the file for the port number and print it (instead of assigning it to a variable)
grep "server.port" "$properties_file" | cut -d'=' -f2
}
# Function to handle the SIGINT signal
function handle_sigint() {
echo "Killing gradle process..."
kill $gradle_pid
exit 0
}
# Trap the SIGINT signal
trap handle_sigint SIGINT
# Run the gradle run command in the background
gradle run &
gradle_pid=$!
# Wait for 20 seconds
sleep 20
# Open the URL in a separate process, calling the function to get the port
open "http://localhost:$(get_server_port)" &
# Wait for the gradle process to end
wait $gradle_pid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment