Skip to content

Commit

Permalink
first version of automatic development setup for Rust and bare
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterPennings committed Jun 11, 2024
1 parent afc790b commit 66c784f
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 0 deletions.
83 changes: 83 additions & 0 deletions scripts/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
$GITHUB_RELEASE = "v0.1.0-beta"
$BASE_DOWNLOAD_URL = "https://github.com/StrijpT-Ellie/contour-wall/releases/$GITHUB_RELEASE/"

function Init-Rust {
Write-Host "Initialising ContourWall environment for Rust in current directory" -ForegroundColor Blue

$output = cargo init $project_name --bin 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "`nFailed to initialise the Rust ContourWall development environment." -ForegroundColor Red
Write-Host "Failed command: `"`"cargo init $project_name --bin`"`""
Write-Host "exiting..."
exit 1
}

$output = cargo add contourwall 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "`nFailed to add package `"`"contourwall`"`" to your Cargo project" -ForegroundColor Red
Write-Host "Link to cargo package: https://crates.io/crates/contourwall"
Write-Host "exiting..."
exit 1
}

Write-Host "Successfully initialised your ContourWall environment for Rust" -ForegroundColor Green
exit 0
}

function Init-Python {
Write-Host "Initialising ContourWall environment for Python in current directory" -ForegroundColor Blue
New-Item -Path . -Name "$project_name.py" -ItemType "file" -Force
exit 0
}

function Init-Bare {
Write-Host "Pulling the core library binary" -ForegroundColor Blue
New-Item -Path . -Name $project_name -ItemType "directory" -Force
Set-Location -Path $project_name
$output = Invoke-WebRequest -Uri "$BASE_DOWNLOAD_URL/contourwall_core_linux.so" -OutFile "contourwall_core_linux.so" -ErrorAction SilentlyContinue
if ($LASTEXITCODE -ne 0) {
Write-Host "Failed to download binary from Github release $GITHUB_RELEASE" -ForegroundColor Red
Write-Host "exiting..."
exit 1
}
Write-Host "Successfully initialised your Contour Wall environment" -ForegroundColor Green
exit 0
}

Write-Host "Welcome to ContourWall!" -ForegroundColor White
Write-Host "`nThis script uses Github release: $GITHUB_RELEASE"
Write-Host "This script will setup the development environment for the ContourWall. If at any time you want to quit this script, press: ctrl + c`n"

Write-Host $BASE_DOWNLOAD_URL

$project_name = Read-Host "What is the name of your project?"

Write-Host ""

$choice = Read-Host "What language do you want to use:
1) Python
2) Rust
3) Bare (no language, just binary)
4) Quit initialisation
"

Write-Host ""

switch ($choice) {
{$_ -eq 1 -or $_ -eq "python" -or $_ -eq "Python"} {
Init-Python
}
{$_ -eq 2 -or $_ -eq "rust" -or $_ -eq "Rust"} {
Init-Rust
}
{$_ -eq 3 -or $_ -eq "bare" -or $_ -eq "Bare"} {
Init-Bare
}
{$_ -eq 4} {
exit 0
}
default {
Write-Host "`n'$choice' is not a choice.`nexiting..."
exit 1
}
}
83 changes: 83 additions & 0 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
GITHUB_RELEASE=v0.1.0-beta
BASE_DOWNLOAD_URL=https://github.com/StrijpT-Ellie/contour-wall/releases/$GITHUB_RELEASE/

function init_rust {
echo -e "\e[0;34mInitialising ContourWall environement for Rust in current directory\e[0;30m"

# cargo init $project_name --bin
output=$(cargo init $project_name --bin 2>&1)

if [[ $? -ne 0 ]]; then
echo -e "\n\e[1;31mFailed to initialise the Rust ContourWall development environement.\e[0m"
echo -e "Failed command: \"cargo init "$project_name" --bin\" "
echo -e "exiting..."
exit 1
fi

output=$(cargo add contourwall 2>&1)

if [[ $? -ne 0 ]]; then
echo -e "\n\e[1;31mFailed to add package \"contourwall\" to your Cargo project\e[0m"
echo -e "Link to cargo package: https://crates.io/crates/contourwall"
echo -e "exiting..."
exit 1
fi

echo -e "\e[1;32mSuccessfully initialised your ContourWall environement for Rust\e[0m"
exit 0
}

function init_python {
echo -e "\e[0;34mInitialising ContourWall environement for Python in current directory\e[0;30m"

touch '$project_name'.py
exit 0
}

function init_bare {
echo -e "\e[0;34mPulling the core library binary\e[0;30m"
mkdir $project_name
cd $project_name
output=$(curl -f -o contourwall_core_linux.so $BASE_DOWNLOAD_URL$GITHUB_RELEASE/contourwall_core_linux.so 2>&1)
if [[ $? -ne 0 ]]; then
echo -e "\e[1;31mFailed to download binary from Github release ${GITHUB_RELEASE}\e[0m"
echo -e "exiting..."
exit 1
fi
echo -e "\e[1;32mSuccessfully initialised your Contour Wall environment\e[0m"
exit 0
}

echo -e "\e[1;37mWelcome to ContourWall!\e[0m\n"
echo -e "This script uses Github release:" ${GITHUB_RELEASE}
echo -e "This script will setup the development enviroment for the ContourWall. If at anytime you want to quit this script, press: ctrl + c\n"

echo -e $BASE_DOWNLOAD_URL

read -p "What is the name of your project?
> " project_name

echo ""

read -p "What language do you want to use:
1) Python
2) Rust
3) Bare (no language, just binary)
4) Quit initialisation
> " choice

echo ""

if [[ $choice -eq 1 || $choice == "python" || $choice == "Python" ]]; then
init_python
elif [[ $choice -eq 2 || $choice == "rust" || $choice == "Rust" ]]; then
init_rust
elif [[ $choice -eq 3 || $choice == "bare" || $choice == "Bare" ]]; then
init_bare
elif [[ $choice -eq 4 ]]; then
exit 0
else

echo -e "\n'"$choice"'" "is not a choice.\nexiting..."
exit 1
fi

0 comments on commit 66c784f

Please sign in to comment.