From e4fd674d6e2bb56c0f8f9c04bddd74994c1fe535 Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 15 Nov 2024 23:17:38 -0600 Subject: Update start scripts --- Dockerfile | 2 +- app/package.json | 2 +- app/yarn.lock | 8 +++--- dev.bat | 77 -------------------------------------------------------- dev.sh | 20 --------------- docker_start.sh | 6 +++++ linklogger.bat | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ linklogger.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 8 files changed, 161 insertions(+), 107 deletions(-) delete mode 100644 dev.bat delete mode 100755 dev.sh create mode 100755 docker_start.sh create mode 100644 linklogger.bat mode change 100644 => 100755 linklogger.sh diff --git a/Dockerfile b/Dockerfile index 16cc8c1..98db666 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ COPY --from=build-ui /app/dist /usr/share/nginx/html # Replace the default site with the LinkLogger config COPY nginx.conf /etc/nginx/sites-enabled/default -CMD ["./linklogger.sh"] \ No newline at end of file +CMD ["./docker_start.sh"] \ No newline at end of file diff --git a/app/package.json b/app/package.json index 0462111..d50bf85 100644 --- a/app/package.json +++ b/app/package.json @@ -29,7 +29,7 @@ "globals": "^15.11.0", "typescript": "~5.6.2", "typescript-eslint": "^8.11.0", - "vite": "^5.4.10" + "vite": "^5.4.11" }, "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } diff --git a/app/yarn.lock b/app/yarn.lock index 189fe6d..69f6fda 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -1587,10 +1587,10 @@ uri-js@^4.2.2: dependencies: punycode "^2.1.0" -vite@^5.4.10: - version "5.4.10" - resolved "https://registry.yarnpkg.com/vite/-/vite-5.4.10.tgz#d358a7bd8beda6cf0f3b7a450a8c7693a4f80c18" - integrity sha512-1hvaPshuPUtxeQ0hsVH3Mud0ZanOLwVTneA1EgbAM5LhaZEqyPWGRQ7BtaMvUrTDeEaC8pxtj6a6jku3x4z6SQ== +vite@^5.4.11: + version "5.4.11" + resolved "https://registry.yarnpkg.com/vite/-/vite-5.4.11.tgz#3b415cd4aed781a356c1de5a9ebafb837715f6e5" + integrity sha512-c7jFQRklXua0mTzneGW9QVyxFjUgwcihC4bXEtujIo2ouWCe1Ajt/amn2PCxYnhYfd5k09JX3SB7OYWFKYqj8Q== dependencies: esbuild "^0.21.3" postcss "^8.4.43" diff --git a/dev.bat b/dev.bat deleted file mode 100644 index 32c0c3e..0000000 --- a/dev.bat +++ /dev/null @@ -1,77 +0,0 @@ -@echo off -setlocal enabledelayedexpansion - -@REM Check for Python (at least 3.10) -@echo Checking for Python installation... - -set PYTHON_CMD= -for %%P in (python python3) do ( - %%P --version 2>nul >nul - if !errorlevel! equ 0 ( - set PYTHON_CMD=%%P - goto CheckPythonVersion - ) -) - -@echo Error: Neither Python nor Python3 is installed. Please install Python 3.10 or higher. -exit /b 1 - -:CheckPythonVersion -for /f "tokens=2 delims= " %%V in ('%PYTHON_CMD% --version') do set PYTHON_VERSION=%%V -@echo Detected Python version: %PYTHON_VERSION% - -for /f "tokens=1,2 delims=." %%M in ("%PYTHON_VERSION%") do ( - set MAJOR=%%M - set MINOR=%%N -) - -if %MAJOR% lss 3 ( - @echo Error: Python version is too old. Please install Python 3.10 or higher. - exit /b 1 -) -if %MAJOR% equ 3 if %MINOR% lss 10 ( - @echo Error: Python version is too old. Please install Python 3.10 or higher. - exit /b 1 -) - -@echo Python version is compatible. - -@REM Check for Node.js -@echo Checking if Node.js is installed... -node -v >nul 2>nul -if errorlevel 1 ( - @echo Error: Node.js is not installed. Please install it and try again. - exit /b 1 -) - -@REM Check for pip -@echo Checking if pip is installed... -pip --version >nul 2>nul -if errorlevel 1 ( - @echo Error: pip is not installed. Please install it and try again. - exit /b 1 -) - -@REM @REM Check for Yarn -@REM @echo Checking if Yarn is installed... -@REM yarn -v >nul 2>nul -@REM if errorlevel 1 ( -@REM @echo Error: Yarn is not installed. Please install it and try again. -@REM exit /b 1 -@REM ) - -@REM All dependencies are verified -@echo All dependencies are installed and compatible. - -@REM Install UI dependencies and start the UI -@echo Install UI dependencies and starting UI in new window... -start cmd /k "cd app && yarn install && start cmd /c yarn add vite && yarn dev" - -@REM Run linklogger.py concurrently in a new window -@echo Installing API dependencies... -%PYTHON_CMD% -m pip install -r requirements.txt -@echo Starting API... -%PYTHON_CMD% linklogger.py - -@REM Prevent the script from closing immediately after both commands complete -pause diff --git a/dev.sh b/dev.sh deleted file mode 100755 index e9d2d0b..0000000 --- a/dev.sh +++ /dev/null @@ -1,20 +0,0 @@ -#! /bin/bash -# If on Linux or MacOS - check tmux -if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then - python3 linklogger.py & - cd app || return - yarn dev -fi - -# If on Windows -if [[ "$OSTYPE" == "msys" ]]; then - python3 linklogger.py & - cd app || return - yarn dev - # echo -e "This script is not supported on Windows. Please run the API and UI manually." - # echo -e "\t1. Install node.js, yarn, python3, and pip" - # echo -e "\t2. Run 'pip install -r requirements.txt' in the root directory" - # echo -e "\t3. Run 'python3 linklogger.py' in the root directory" - # echo -e "\t4. Run 'cd app' and then 'yarn dev'" - # exit 1 -fi \ No newline at end of file diff --git a/docker_start.sh b/docker_start.sh new file mode 100755 index 0000000..a2a0f44 --- /dev/null +++ b/docker_start.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# Start nginx in the background +service nginx start + +# Run the Python script +python -u linklogger.py \ No newline at end of file diff --git a/linklogger.bat b/linklogger.bat new file mode 100644 index 0000000..32c0c3e --- /dev/null +++ b/linklogger.bat @@ -0,0 +1,77 @@ +@echo off +setlocal enabledelayedexpansion + +@REM Check for Python (at least 3.10) +@echo Checking for Python installation... + +set PYTHON_CMD= +for %%P in (python python3) do ( + %%P --version 2>nul >nul + if !errorlevel! equ 0 ( + set PYTHON_CMD=%%P + goto CheckPythonVersion + ) +) + +@echo Error: Neither Python nor Python3 is installed. Please install Python 3.10 or higher. +exit /b 1 + +:CheckPythonVersion +for /f "tokens=2 delims= " %%V in ('%PYTHON_CMD% --version') do set PYTHON_VERSION=%%V +@echo Detected Python version: %PYTHON_VERSION% + +for /f "tokens=1,2 delims=." %%M in ("%PYTHON_VERSION%") do ( + set MAJOR=%%M + set MINOR=%%N +) + +if %MAJOR% lss 3 ( + @echo Error: Python version is too old. Please install Python 3.10 or higher. + exit /b 1 +) +if %MAJOR% equ 3 if %MINOR% lss 10 ( + @echo Error: Python version is too old. Please install Python 3.10 or higher. + exit /b 1 +) + +@echo Python version is compatible. + +@REM Check for Node.js +@echo Checking if Node.js is installed... +node -v >nul 2>nul +if errorlevel 1 ( + @echo Error: Node.js is not installed. Please install it and try again. + exit /b 1 +) + +@REM Check for pip +@echo Checking if pip is installed... +pip --version >nul 2>nul +if errorlevel 1 ( + @echo Error: pip is not installed. Please install it and try again. + exit /b 1 +) + +@REM @REM Check for Yarn +@REM @echo Checking if Yarn is installed... +@REM yarn -v >nul 2>nul +@REM if errorlevel 1 ( +@REM @echo Error: Yarn is not installed. Please install it and try again. +@REM exit /b 1 +@REM ) + +@REM All dependencies are verified +@echo All dependencies are installed and compatible. + +@REM Install UI dependencies and start the UI +@echo Install UI dependencies and starting UI in new window... +start cmd /k "cd app && yarn install && start cmd /c yarn add vite && yarn dev" + +@REM Run linklogger.py concurrently in a new window +@echo Installing API dependencies... +%PYTHON_CMD% -m pip install -r requirements.txt +@echo Starting API... +%PYTHON_CMD% linklogger.py + +@REM Prevent the script from closing immediately after both commands complete +pause diff --git a/linklogger.sh b/linklogger.sh old mode 100644 new mode 100755 index a2a0f44..71ab398 --- a/linklogger.sh +++ b/linklogger.sh @@ -1,6 +1,74 @@ #!/bin/bash -# Start nginx in the background -service nginx start -# Run the Python script -python -u linklogger.py \ No newline at end of file +# Define color variables for easier use +RED='\033[1;31m' +GREEN='\033[1;32m' +NC='\033[0m' # No Color (reset to default) + +# Function to detect the appropriate Python version +function check_python_version() { + # Check for python3 first + if command -v python3 &> /dev/null; then + PYTHON_CMD="python3" + elif command -v python &> /dev/null; then + PYTHON_CMD="python" + else + printf "${RED}No Python installation found. Please install Python.${NC}\n" + exit 1 + fi + + # Check Python version (>= 3.10) + PYTHON_VERSION=$($PYTHON_CMD -c 'import platform; print(platform.python_version())') + REQUIRED_VERSION="3.10" + + if [[ "$(printf '%s\n' "$REQUIRED_VERSION" "$PYTHON_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]]; then + printf "${RED}Python version $PYTHON_VERSION is installed, but version 3.10 or higher is required.${NC}\n" + exit 1 + fi +} + +# Function to check that pip is installed +function check_pip_installed() { + if ! command -v pip &> /dev/null; then + printf "${RED}Pip is not installed. Please install Pip before proceeding.${NC}\n" + exit 1 + fi +} + +# Function to check if yarn is installed +function check_yarn_installed() { + if ! command -v yarn &> /dev/null; then + printf "${RED}Yarn is not installed. Please install Yarn before proceeding.${NC}\n" + exit 1 + fi +} + +# If on Linux or macOS +if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then + check_python_version + printf "${GREEN}Python version $PYTHON_VERSION is installed.${NC}\n" + check_pip_installed + printf "${GREEN}Pip is installed.${NC}\n" + check_yarn_installed + printf "${GREEN}Yarn is installed.${NC}\n" + + # Install the UI dependencies + printf "${GREEN}Installing UI dependencies...${NC}\n" + cd app || { printf "${RED}Failed to enter 'app' directory. Exiting.${NC}\n"; exit 1; } + yarn install | head -n 5 + yarn add vite | head -n 5 + cd .. || { printf "${RED}Failed to return to the previous directory. Exiting.${NC}\n"; exit 1; } + printf "${GREEN}UI dependencies installed.${NC}\n" + + # Start the API and UI + printf "${GREEN}Starting API and UI...${NC}\n" + $PYTHON_CMD linklogger.py & + cd app || { printf "${RED}Failed to enter 'app' directory. Exiting.${NC}\n"; exit 1; } + yarn dev +fi + +# If on Windows (MSYS environment) +if [[ "$OSTYPE" == "msys" ]]; then + printf "${RED}This script is not for Windows. Please run dev.bat instead.${NC}\n" + exit 1 +fi -- cgit v1.2.3-70-g09d2