Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
chore: Added setup scripts for Windows and Linux/Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
dikayx committed Aug 5, 2024
1 parent 4c7f76b commit ff7c32c
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 0 deletions.
107 changes: 107 additions & 0 deletions setup.bat
Original file line number Diff line number Diff line change
@@ -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
107 changes: 107 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ff7c32c

Please sign in to comment.