From ff7c32c21f8017169c3e181615ef879e9de8497a Mon Sep 17 00:00:00 2001 From: Dan Koller <57103678+dan-koller@users.noreply.github.com> Date: Mon, 5 Aug 2024 10:49:10 +0200 Subject: [PATCH] chore: Added setup scripts for Windows and Linux/Mac --- setup.bat | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 insertions(+) create mode 100644 setup.bat create mode 100644 setup.sh diff --git a/setup.bat b/setup.bat new file mode 100644 index 0000000..e984b25 --- /dev/null +++ b/setup.bat @@ -0,0 +1,107 @@ +@echo off +setlocal EnableDelayedExpansion + +rem This script is used to help the user setup the entire project + +echo "---------------------------------" +echo " __ __ _____ " +echo " | \/ | /\ | __ \ " +echo " | \ / | / \ | |__) | _ " +echo " | |\/| | / /\ \ | ___/ | | | " +echo " | | | |/ ____ \| | | |_| | " +echo " |_| |_/_/ \_\_| \__, | " +echo " __/ | " +echo " |___/ " +echo "---------------------------------" + +echo Welcome to the MAPy setup script! +echo Press any key to continue... +pause >nul + +rem Check if Docker is running +docker info >nul 2>&1 +if %errorlevel% equ 0 ( + echo Docker is installed and running. + echo Proceeding with Docker setup... + rem Setup the Docker container + docker build -t mapy . + + rem Ask the user for the port (default is 8080) + set /p "port=Please enter the port for the Docker container (default is 8080): " + if not defined port set port=8080 + + rem Validate the port + call :CHECK_PORT %port% + if "!isValidPort!"=="false" ( + echo Invalid port. Please enter a port number between 1 and 65535: + set /p "port=" + call :CHECK_PORT %port% + ) + + echo Starting MAPy container on port !port!... + docker run -p !port!:!port! --name mapy mapy +) else ( + rem Setup a local environment + echo It appears that Docker is not installed or the Docker daemon is not running. + echo Would you like to setup a local environment instead? (y/n^) + set /p "yn=" + if /i "!yn!"=="y" ( + echo Setting up local environment... + ) else ( + echo Exiting... + exit /b + ) + + rem Check if Python is installed + python --version >nul 2>&1 + if %errorlevel% equ 0 ( + echo Python installation found. Proceeding... + ) else ( + echo Python is not installed. Please install Python 3.10 or higher. + echo Exiting... + exit /b + ) + + rem Ask the user for the host (default is 127.0.0.1) + set /p "host=Please enter the host for the local environment (default is 127.0.0.1): " + if not defined host set host=127.0.0.1 + + rem Ask the user for the port (default is 8080) + set /p "port=Please enter the port for the local environment (default is 8080): " + if not defined port set port=8080 + + rem Validate the port + call :CHECK_PORT %port% + if "!isValidPort!"=="false" ( + echo Invalid port. Please enter a port number between 1 and 65535: + set /p "port=" + call :CHECK_PORT %port% + ) + + rem Setup python virtual environment + python -m venv .venv + call .venv\Scripts\activate + + rem Install dependencies + pip install -r requirements.txt + + rem Run the app with the user's configuration + echo Starting MAPy on !host!:!port!... + python start.py -b !host! -p !port! +) + +rem Function to check if the port is valid +:CHECK_PORT +set port=%1 +if not defined port set port=8080 +if "%port%"=="0" ( + set "isValidPort=false" +) else ( + set "isValidPort=true" + for /L %%i in (1,1,65535) do ( + if "!port!"=="%%i" set "isValidPort=true" + ) +) +exit /b + +endlocal \ No newline at end of file diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..5667be2 --- /dev/null +++ b/setup.sh @@ -0,0 +1,107 @@ +#!/bin/zsh + +# This script is used to help the user setup the entire project + +banner=$(cat << "EOF" +-------------------------------- + __ __ _____ + | \/ | /\ | __ \ + | \ / | / \ | |__) | _ + | |\/| | / /\ \ | ___/ | | | + | | | |/ ____ \| | | |_| | + |_| |_/_/ \_\_| \__, | + __/ | + |___/ +-------------------------------- +EOF +) + +echo "$banner" +echo "Welcome to the MAPy setup script!" +echo "Press any key to continue..." +read -n 1 -s + +# Function to check if the port is valid +is_valid_port() { + local port=$1 + if [[ $port =~ ^[0-9]+$ ]] && [ $port -ge 1 ] && [ $port -le 65535 ]; then + return 0 + else + return 1 + fi +} + +# Check if Docker is running +DOCKER_INSTALLED=$(docker info > /dev/null 2>&1) + +if [ -n "$DOCKER_INSTALLED" ]; then + echo "Docker is installed and running." + echo "Proceeding with Docker setup..." + # Setup the Docker container + docker build -t mapy . + + # Ask the user for the port (default is 8080) + echo "Please enter the port for the Docker container (default is 8080):" + read -p "" port + port=${port:-8080} + + # Validate the port + while ! is_valid_port $port; do + echo "Invalid port. Please enter a port number between 1 and 65535:" + read -p "" port + port=${port:-8080} + done + + echo "Starting MAPy container on port $port..." + docker run -p $port:$port --name mapy mapy +else + # Setup a local environment + echo "It appears that Docker is not installed or the Docker daemon is not running." + echo "Would you like to setup a local environment instead? (y/n)" + while true; do + read -p "" yn + case $yn in + [Yy]* ) echo "Setting up local environment..."; break;; + [Nn]* ) echo "Exiting..."; exit;; + * ) echo "Please answer 'y' or 'n'.";; + esac + done + + # Check if Python 3 is installed + PYTHON_INSTALLED=$(python3 --version > /dev/null 2>&1) + if [ -n "$PYTHON_INSTALLED" ]; then + echo "Python 3 installation found. Proceeding..." + else + echo "Python 3 is not installed. Please install Python 3.10 or higher." + echo "Exiting..." + exit + fi + + # Ask the user for the host (default is 127.0.0.1) + echo "Please enter the host for the local environment (default is 127.0.0.1):" + read -p "" host + host=${host:-127.0.0.1} + + # Ask the user for the port (default is 8080) + echo "Please enter the port for the local environment (default is 8080):" + read -p "" port + port=${port:-8080} + + # Validate the port + while ! is_valid_port $port; do + echo "Invalid port. Please enter a port number between 1 and 65535:" + read -p "" port + port=${port:-8080} + done + + # Setup python virtual environment + python3 -m venv .venv + source .venv/bin/activate + + # Install dependencies + pip3 install -r requirements.txt + + # Run the app with the user's configuration + echo "Starting MAPy on $host:$port..." + .venv/bin/python start.py -b $host -p $port +fi \ No newline at end of file