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