Add execution mode option

This commit is contained in:
Mario Romero 2023-09-24 05:13:38 -03:00
parent 418a65185d
commit 7734f733a9

163
run.ps1
View File

@ -1,76 +1,89 @@
param([switch] $remote = $false) param([switch] $remote = $false)
Write-Host "OSIC-Stacks Container Creation" -ForegroundColor Green Write-Host "OSIC-Stacks Container Creation" -ForegroundColor Green
Write-Host "Checking requirements and WSL updates" -ForegroundColor DarkGray Write-Host "Checking requirements and WSL updates" -ForegroundColor DarkGray
Write-Host "" Write-Host ""
wsl --install Ubuntu --no-launch wsl --install Ubuntu --no-launch
wsl --update wsl --update
Write-Host "" Write-Host ""
Write-Host "Please select an image index:" Write-Host "Please select an image index:"
$imageoptions = @( $stacks_options = @(
'analog-xk' 'analog-xk'
'analog-xm' 'analog-xm'
'analog-heavy' 'analog-heavy'
'digital-ator' 'digital-ator'
'digital-icarus' 'digital-icarus'
'digital-heavy' 'digital-heavy'
'heavy' 'heavy'
) )
for($i = 0; $i -lt $imageoptions.Length; $i++) { for($i = 0; $i -lt $stacks_options.Length; $i++) {
$imageoption = $imageoptions[$i] $stack_option = $stacks_options[$i]
Write-Host "$i - $imageoption" -ForegroundColor Cyan Write-Host "[$($i+1)] - $stack_option" -ForegroundColor Cyan
} }
$imageindex = Read-Host -Prompt "Container image to initialize [0-$($imageoptions.Length-1)]" $stack_index = Read-Host -Prompt "Container image to initialize [1-$($stacks_options.Length)]"
$imagename = $imageoptions[$imageindex] $selected_stack = $stacks_options[$stack_index-1]
$containername = Read-Host -Prompt "Container instance name [default=$imagename]" $container_name = Read-Host -Prompt "Container instance name [default=$selected_stack]"
if (!$containername) { $containername = $imagename } if (!$container_name) { $container_name = $selected_stack }
$additionaloptions = '' $execmode = ''
if($remote) { while(!$execmode) {
$image = "git.1159.cl/mario1159/$imagename" Write-Host "Please select an execution mode index"
$additionaloptions = '--pull always ' Write-Host '[1] - desktop' -ForegroundColor Cyan
} else { Write-Host '[2] - web' -ForegroundColor Cyan
$image = $imagename $response = Read-Host "Execution mode [1-2]"
} if ($response -eq '1') {
$execmode = 'desktop'
$response = Read-Host "Do you want to bind the container home directory into a windows directory? [N/y]" } elseif ($response -eq '2') {
$execmode = 'web'
} else {
if ($response -eq 'y') { Write-Host "Unexpected respose, please try again" -ForegroundColor Red
$directory = Read-Host "Write the windows directory destination relative to WSL, for example `"/mnt/c/Users/Username/Desktop/ExampleFolder`"`n" }
mkdir -Force $directory | Out-Null }
$additionaloptions = -join($additionaloptions, "-v ${directory}:/home/designer/shared ")
} $additional_options = ''
if($remote) {
$response = Read-Host -Prompt "Do you want to set additional arguments for the container instantiation? [N/y]" $image = "git.1159.cl/mario1159/$selected_stack-$execmode"
$additional_options = '--pull always '
if ($response -eq 'y') { } else {
$response = Read-Host -Prompt "Write the additional arguments, for example -v <wsl_path>:<container_path>." $image = "$selected_stack-$execmode"
$additionaloptions = -join($additionaloptions, $response) }
}
$response = Read-Host "Do you want to bind the container home directory into a windows directory? [N/y]"
Write-Host ""
if ($response -eq 'y') {
$dockercommand = ("docker run -d " + $directory = Read-Host "Write the windows directory destination relative to WSL, for example `"/mnt/c/Users/Username/Desktop/ExampleFolder`"`n"
"--name $containername " + $additionaloptions = -join($additionaloptions, "-v ${directory}:/home/designer/shared ")
"-v /tmp/.X11-unix:/tmp/.X11-unix " + }
"-v /mnt/wslg:/mnt/wsl " +
"-e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY " + $response = Read-Host -Prompt "Do you want to set additional arguments for the container instantiation? [N/y]"
"-e DISPLAY=`$DISPLAY " +
"-e XDG_RUNTIME_DIR=/mnt/wslg " + if ($response -eq 'y') {
"$additionaloptions "+ $response = Read-Host -Prompt "Write the additional arguments, for example -v <wsl_path>:<container_path>."
$image) $additionaloptions = -join($additionaloptions, $response)
}
wsl -d Ubuntu bash -ic $dockercommand
Write-Host ""
if ($?) {
Write-Host "Container created successfully!" -ForegroundColor Green $dockercommand = ("docker run -d " +
Write-Host "Enter the container with `"docker exec -it $containername bash`"" -ForegroundColor DarkGray "--name $container_name " +
} else { "-v /tmp/.X11-unix:/tmp/.X11-unix " +
Write-Host "Container creation failed, see logs above" -ForegroundColor Red "-v /mnt/wslg:/mnt/wsl " +
"-e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY " +
"-e DISPLAY=`$DISPLAY " +
"-e XDG_RUNTIME_DIR=/mnt/wslg " +
"$additional_options "+
$image)
wsl -d Ubuntu bash -ic $dockercommand
if ($?) {
Write-Host "Container created successfully!" -ForegroundColor Green
Write-Host "Enter the container with `"docker exec -it $containername bash`"" -ForegroundColor DarkGray
} else {
Write-Host "Container creation failed, see logs above" -ForegroundColor Red
} }