Last active
October 16, 2023 10:20
-
-
Save XxUnkn0wnxX/c8c42f5784c99a516276736c4e6e87e5 to your computer and use it in GitHub Desktop.
macOS runtime script for trickster-is-weak/Surviving-Maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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