smart-underworld / seestar_alp

Complete Control and Automation for Seestar S50
Other
42 stars 24 forks source link

One Click installer - seestar.bat #7

Open bigsk1 opened 1 month ago

bigsk1 commented 1 month ago

I made a one click installer for those that get lost trying to install requirements needed on windows.

Instead of a pull request will just drop it here if anyone is interested, this will check and install git, will skip if you have. Will check and install python (miniconda) and skip if you have. Will check and install Microsoft C++ build tools, will skip if you have it all ready. Will download everything needed include clone the repo and start python app.py. Tested in windows sandbox.

Feel free to edit as needed. Should be able to use it as a start script also since it should skip existing requirements when already installed.

Create a text file seestar.bat and double click!

@echo off
SETLOCAL EnableExtensions EnableDelayedExpansion

:: Temporarily change the execution policy to allow script execution
powershell -Command "Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force"

:: Define paths for Miniconda and its scripts
SET "MINICONDA_PATH=%UserProfile%\Miniconda3"
SET "MINICONDA_SCRIPTS_PATH=%UserProfile%\Miniconda3\Scripts"

:: Install Git if not present and update the PATH
where git >nul 2>nul
if %errorlevel% neq 0 (
    echo Git is not installed. Installing Git...
    powershell -command "Invoke-WebRequest -Uri 'https://github.com/git-for-windows/git/releases/download/v2.45.1.windows.1/Git-2.45.1-64-bit.exe' -OutFile 'GitInstaller.exe'; Start-Process -FilePath './GitInstaller.exe' -ArgumentList '/VERYSILENT /NORESTART' -Wait; Remove-Item -Path './GitInstaller.exe'"
    SET PATH=%PATH%;C:\Program Files\Git\cmd
)

:: Clone repository if not already cloned
if not exist "seestar_alp\" (
    echo Cloning repository...
    git clone https://github.com/smart-underworld/seestar_alp.git
) else (
    echo Repository already cloned.
)

:: Install Microsoft Build Tools if not present
where cl >nul 2>nul
if %errorlevel% neq 0 (
    echo Microsoft Build Tools not installed. Installing...
    powershell -command "Invoke-WebRequest -Uri 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile 'BuildToolsInstaller.exe'; Start-Process -FilePath './BuildToolsInstaller.exe' -ArgumentList '--quiet --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended' -Wait; Remove-Item -Path './BuildToolsInstaller.exe'"
)

:: Check for any Python installation
where python >nul 2>nul
if %errorlevel% neq 0 (
    echo No Python installation detected. Installing Miniconda...
    powershell -command "Invoke-WebRequest -Uri 'https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe' -OutFile 'MinicondaInstaller.exe'; Start-Process -FilePath './MinicondaInstaller.exe' -ArgumentList '/InstallationType=JustMe /RegisterPython=0 /S /D=%UserProfile%\Miniconda3' -Wait; Remove-Item -Path './MinicondaInstaller.exe'"
    SET "PYTHON_EXE=%UserProfile%\Miniconda3\python.exe"
    SET "PIP_EXE=%UserProfile%\Miniconda3\Scripts\pip.exe"
    call %UserProfile%\Miniconda3\Scripts\conda init cmd.exe
    SET "PATH=%UserProfile%\Miniconda3;%UserProfile%\Miniconda3\Scripts;%UserProfile%\Miniconda3\Library\bin;%PATH%"
    call %PYTHON_EXE% --version
) else (
    echo Python is installed.
    set "PYTHON_EXE=python"
    set "PIP_EXE=pip"
)

:: Check for Conda installation
where conda >nul 2>nul
if %errorlevel% neq 0 (
    echo Conda is not installed, using venv for environment management.
    if not exist "seestar_env\" (
        %PYTHON_EXE% -m venv seestar_env
    )
    call seestar_env\Scripts\activate.bat
) else (
    echo Conda is available.
    conda info --envs | findstr "seestar" >nul
    if %errorlevel% neq 0 (
        echo Creating Conda environment 'seestar'.
        call conda create --name seestar python=3.11 -y
    ) else (
        echo Condaenvironment 'seestar' already exists.
    )
    call conda activate seestar
)

cd seestar_alp

:: Install requirements if not already installed
if exist "requirements.txt" (
    call %PIP_EXE% install -r requirements.txt
) else (
    echo Requirements file not found.
)

:: Change to the correct directory and run the Python script
cd device
echo Starting application...
call %PYTHON_EXE% app.py

echo Script completed. Press any key to exit.
pause >nul
ENDLOCAL