Updating scripts for building on Linux and Windows

This commit is contained in:
FlUxIuS 2024-07-14 23:17:07 +02:00
parent 1f4844a1d3
commit c83f00f1b9
No known key found for this signature in database
GPG Key ID: E8B96449EE4FA72F
2 changed files with 103 additions and 56 deletions

View File

@ -1,82 +1,126 @@
@echo off @echo off
REM This code is part of RF Switch by @Penthertz
:: This code is part of RF Switch by @Penthertz REM Author(s): Sébastien Dudek (@FlUxIuS)
:: Author(s): Sébastien Dudek (@FlUxIuS)
setlocal enabledelayedexpansion setlocal enabledelayedexpansion
set "GOVERSION=1.22.5"
install_go() ( set "GREEN="
go version >nul 2>&1 && ( set "RED="
echo golang is already installed. moving on set "YELLOW="
exit /b 0 set "NC="
)
if not exist thirdparty mkdir thirdparty REM Function to check Docker installation
cd thirdparty :check_docker
for /f "tokens=2 delims==" %%a in ('"wmic os get osarchitecture /value"') do set "arch=%%a" docker --version >nul 2>&1
set "arch=!arch: =!" if %errorlevel% neq 0 (
echo Docker is not installed. Do you want to install it now? (yes/no)
set "prog=" set /p install_docker="Choose an option: "
if "!arch!"=="64-bit" ( if "%install_docker%" == "yes" (
set "prog=go%GOVERSION%.windows-amd64.zip" echo Installing Docker...
) else if "!arch!"=="32-bit" ( powershell -Command "Invoke-WebRequest -UseBasicParsing https://get.docker.com/ | Invoke-Expression"
set "prog=go%GOVERSION%.windows-386.zip" powershell -Command "Start-Service docker"
powershell -Command "Set-Service -Name docker -StartupType Automatic"
echo Docker installed successfully.
) else ( ) else (
echo Unsupported architecture: "!arch!" -> Download or build Go instead echo Docker is required to proceed. Exiting.
exit /b 2 exit /b 1
) )
) else (
echo Docker is already installed. Moving on.
)
goto :eof
powershell -command "Invoke-WebRequest -Uri https://go.dev/dl/%prog% -OutFile %prog%" REM Function to install Go
rmdir /s /q C:\Go :install_go
powershell -command "Expand-Archive -Path %prog% -DestinationPath C:\Go" where go >nul 2>&1
setx PATH "%PATH%;C:\Go\bin" if %errorlevel% == 0 (
cd .. echo golang is already installed and in PATH. Moving on.
rmdir /s /q thirdparty goto :eof
) )
building_rfswift() ( if exist "C:\Go\bin\go.exe" (
cd go\rfswift echo golang is already installed in C:\Go\bin. Moving on.
go build . goto :eof
move rfswift.exe ..\..
cd ..\..
) )
echo [+] Installing Go if not exist thirdparty mkdir thirdparty
install_go cd thirdparty
set "arch=%PROCESSOR_ARCHITECTURE%"
set "prog="
set "version=1.22.5"
echo [+] Building RF Switch Go Project if "%arch%" == "AMD64" (
building_rfswift set "prog=go%version%.windows-amd64.zip"
) else if "%arch%" == "x86" (
set "prog=go%version%.windows-386.zip"
) else (
echo Unsupported architecture: "%arch%" -> Download or build Go instead
exit /b 2
)
REM Prompt the user if they want to build a Docker container or pull an image powershell -Command "Invoke-WebRequest -OutFile %prog% https://go.dev/dl/%prog%"
echo Do you want to build a Docker container or pull an existing image? powershell -Command "Expand-Archive -Path %prog% -DestinationPath C:\"
setx PATH "%PATH%;C:\Go\bin"
cd ..
rmdir /s /q thirdparty
echo Go installed successfully.
goto :eof
REM Function to build RF Switch Go Project
:building_rfswift
cd go\rfswift
go build .
move rfswift.exe ..\..\
cd ..\..
echo RF Switch Go Project built successfully.
goto :eof
REM Main script execution
echo Checking Docker installation
call :check_docker
echo Installing Go
call :install_go
echo Building RF Switch Go Project
call :building_rfswift
REM Prompt the user if they want to build a Docker container, pull an image, or exit
echo Do you want to build a Docker container, pull an existing image, or exit?
echo 1) Build Docker container echo 1) Build Docker container
echo 2) Pull Docker image echo 2) Pull Docker image
set /p option=Choose an option (1 or 2): echo 3) Exit
set /p option="Choose an option (1, 2, or 3): "
if "%option%"=="1" ( if "%option%" == "1" (
REM Set default values REM Set default values
set "DEFAULT_IMAGE=myrfswift:latest" set "DEFAULT_IMAGE=myrfswift:latest"
set "DEFAULT_DOCKERFILE=Dockerfile" set "DEFAULT_DOCKERFILE=Dockerfile"
REM Prompt the user for input with default values REM Prompt the user for input with default values
set /p imagename=Enter image tag value (default: %DEFAULT_IMAGE%): set /p imagename="Enter image tag value (default: %DEFAULT_IMAGE%): "
set /p dockerfile=Enter value for Dockerfile to use (default: %DEFAULT_DOCKERFILE%): set /p dockerfile="Enter value for Dockerfile to use (default: %DEFAULT_DOCKERFILE%): "
REM Use default values if variables are empty REM Use default values if variables are empty
if not defined imagename set "imagename=%DEFAULT_IMAGE%" if "!imagename!" == "" set "imagename=%DEFAULT_IMAGE%"
if not defined dockerfile set "dockerfile=%DEFAULT_DOCKERFILE%" if "!dockerfile!" == "" set "dockerfile=%DEFAULT_DOCKERFILE%"
echo [+] Building the Docker container echo Building the Docker container
docker build . -t %imagename% -f %dockerfile% docker build . -t !imagename! -f !dockerfile!
) else if "%option%"=="2" ( ) else if "%option%" == "2" (
set "DEFAULT_IMAGE=penthertz/rfswift:latest" set "DEFAULT_PULL_IMAGE=penthertz/rfswift:latest"
set /p pull_image=Enter the image tag to pull (default: %DEFAULT_IMAGE%): set /p pull_image="Enter the image tag to pull (default: %DEFAULT_PULL_IMAGE%): "
if not defined pull_image set "pull_image=%DEFAULT_IMAGE%" if "!pull_image!" == "" set "pull_image=%DEFAULT_PULL_IMAGE%"
echo [+] Pulling the Docker image echo Pulling the Docker image
docker pull %pull_image% docker pull !pull_image!
) else if "%option%" == "3" (
echo Exiting without building or pulling Docker images.
exit /b 0
) else ( ) else (
echo Invalid option. Exiting. echo Invalid option. Exiting.
exit /b 1 exit /b 1
) )
endlocal
exit /b 0

View File

@ -32,13 +32,16 @@ check_docker() {
} }
install_go() { install_go() {
if command -v go &> /dev/null; then
echo -e "${GREEN}golang is already installed and in PATH. Moving on.${NC}"
return 0
fi
if [ -x "/usr/local/go/bin/go" ]; then if [ -x "/usr/local/go/bin/go" ]; then
echo -e "${GREEN}golang is already installed in /usr/local/go/bin. Moving on.${NC}" echo -e "${GREEN}golang is already installed in /usr/local/go/bin. Moving on.${NC}"
return 0 return 0
fi fi
go version && { echo -e "${GREEN}golang is already installed. Moving on.${NC}" && return 0 ; }
[ -d thirdparty ] || mkdir thirdparty [ -d thirdparty ] || mkdir thirdparty
cd thirdparty cd thirdparty
arch=$(uname -m) arch=$(uname -m)
@ -107,7 +110,7 @@ elif [ "$option" -eq 2 ]; then
pull_image=${pull_image:-penthertz/rfswift:latest} pull_image=${pull_image:-penthertz/rfswift:latest}
echo -e "${YELLOW}[+] Pulling the Docker image${NC}" echo -e "${YELLOW}[+] Pulling the Docker image${NC}"
sudo ./rfswift images pull -i $pull_image sudo docker pull $pull_image
elif [ "$option" -eq 3 ]; then elif [ "$option" -eq 3 ]; then
echo -e "${GREEN}Exiting without building or pulling Docker images.${NC}" echo -e "${GREEN}Exiting without building or pulling Docker images.${NC}"
exit 0 exit 0