Add execution mode option

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

45
run.ps1
View File

@ -10,7 +10,7 @@ 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'
@ -20,30 +20,43 @@ $imageoptions = @(
'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 = ''
while(!$execmode) {
Write-Host "Please select an execution mode index"
Write-Host '[1] - desktop' -ForegroundColor Cyan
Write-Host '[2] - web' -ForegroundColor Cyan
$response = Read-Host "Execution mode [1-2]"
if ($response -eq '1') {
$execmode = 'desktop'
} elseif ($response -eq '2') {
$execmode = 'web'
} else {
Write-Host "Unexpected respose, please try again" -ForegroundColor Red
}
}
$additional_options = ''
if($remote) { if($remote) {
$image = "git.1159.cl/mario1159/$imagename" $image = "git.1159.cl/mario1159/$selected_stack-$execmode"
$additionaloptions = '--pull always ' $additional_options = '--pull always '
} else { } else {
$image = $imagename $image = "$selected_stack-$execmode"
} }
$response = Read-Host "Do you want to bind the container home directory into a windows directory? [N/y]" $response = Read-Host "Do you want to bind the container home directory into a windows directory? [N/y]"
if ($response -eq 'y') { if ($response -eq 'y') {
$directory = Read-Host "Write the windows directory destination relative to WSL, for example `"/mnt/c/Users/Username/Desktop/ExampleFolder`"`n" $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 ") $additionaloptions = -join($additionaloptions, "-v ${directory}:/home/designer/shared ")
} }
@ -57,13 +70,13 @@ if ($response -eq 'y') {
Write-Host "" Write-Host ""
$dockercommand = ("docker run -d " + $dockercommand = ("docker run -d " +
"--name $containername " + "--name $container_name " +
"-v /tmp/.X11-unix:/tmp/.X11-unix " + "-v /tmp/.X11-unix:/tmp/.X11-unix " +
"-v /mnt/wslg:/mnt/wsl " + "-v /mnt/wslg:/mnt/wsl " +
"-e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY " + "-e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY " +
"-e DISPLAY=`$DISPLAY " + "-e DISPLAY=`$DISPLAY " +
"-e XDG_RUNTIME_DIR=/mnt/wslg " + "-e XDG_RUNTIME_DIR=/mnt/wslg " +
"$additionaloptions "+ "$additional_options "+
$image) $image)
wsl -d Ubuntu bash -ic $dockercommand wsl -d Ubuntu bash -ic $dockercommand