Run script enhancement #18

Merged
Mario1159 merged 8 commits from modified-run-file into main 2023-10-14 22:30:04 +00:00
Showing only changes of commit 1c420008fb - Show all commits

View File

@ -1,68 +1,70 @@
param( param(
[switch] $remote = $false, [switch] $remote = $false,
[switch] $interactive = $false [switch] $interactive = $false,
[switch] $silent = $false,
[switch] $clean = $false
) )
$global:STACK_OPTIONS = [ordered]@{} $global:STACK_OPTIONS = [ordered]@{
1 = 'analog-xk'
2 = 'analog-xm'
3 = 'analog-heavy'
4 = 'digital-ator'
5 = 'digital-icarus'
6 = 'digital-heavy'
7 = 'heavy'
8 = "chipathon-tools"
}
$global:SELECTED_STACK='chipathon-tools' $global:SELECTED_STACK='chipathon-tools'
$global:CONTAINER_NAME='chipathon-tools' $global:CONTAINER_NAME=$global:SELECTED_STACK
$global:EXECMODE='desktop' $global:EXECMODE='desktop'
$global:PDK="gf180mcuC"
$global:DIRECTORY=Get-Location | Foreach-Object { $_.Path } $global:DIRECTORY=Get-Location | Foreach-Object { $_.Path }
$global:PARAMS = "" $global:PARAMS = ""
function validate-environment() { New-Alias Call Invoke-Expression
Write-Host "Checking requirements and WSL updates" -ForegroundColor DarkGrayWrite-Host ""
function validate-environment() {
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 ""
} }
function select-image() { function select-stack() {
Write-Host "Please select an image index:" Write-Host "Please select an stack index:"
$global:STACK_OPTIONS = [ordered]@{
1 = 'analog-xk'
2 = 'analog-xm'
3 = 'analog-heavy'
4 = 'digital-ator'
5 = 'digital-icarus'
6 = 'digital-heavy'
7 = 'heavy'
8 = "chipathon-tools"
}
$STACK_OPTIONS.GetEnumerator() | ForEach-Object { $STACK_OPTIONS.GetEnumerator() | ForEach-Object {
Write-Host "[$($_.Key)] - $($_.Value)" -ForegroundColor Cyan Write-Host "[$($_.Key)] - $($_.Value)" -ForegroundColor Cyan
} }
$response = Read-Host -Prompt "Container image to initialize [1-$($STACK_OPTIONS.Count)]" $response = Read-Host -Prompt "Container stack to initialize [1-$($STACK_OPTIONS.Count)]"
$global:SELECTED_STACK = $STACK_OPTIONS[$response-1] if ($response) {
$global:SELECTED_STACK = $STACK_OPTIONS[$response-1]
}
$global:CONTAINER_NAME = Read-Host -Prompt "Container instance name [default=$global:SELECTED_STACK]" $response = Read-Host -Prompt "Container instance name [default=$global:CONTAINER_NAME]"
if (!$global:CONTAINER_NAME) { if ($response) {
$global:CONTAINER_NAME = $global:SELECTED_STACK $global:CONTAINER_NAME = $response
} }
} }
function select-execmode() { function select-execmode() {
$global:EXECMODE = $null Write-Host "Please select an execution mode index"
while(!$global:EXECMODE) { Write-Host '[1] - desktop' -ForegroundColor Cyan
Write-Host "Please select an execution mode index" Write-Host '[2] - web' -ForegroundColor Cyan
Write-Host '[1] - desktop' -ForegroundColor Cyan $response = Read-Host "Execution mode [1-2] [default=$global:EXECMODE]"
Write-Host '[2] - web' -ForegroundColor Cyan
$response = Read-Host "Execution mode [1-2]" if ($response -eq '1') {
if ($response -eq '1') { $global:EXECMODE = 'desktop'
$global:EXECMODE = 'desktop' } elseif ($response -eq '2') {
} elseif ($response -eq '2') { $global:EXECMODE = 'web'
$global:EXECMODE = 'web' } else {
} else { Write-Host "Using default mode ($global:EXECMODE)"
Write-Host "Unexpected respose, please try again" -ForegroundColor Red
}
} }
} }
@ -83,47 +85,124 @@ function set-aditional-parameters() {
} }
} }
function run-docker() { function force-pull() {
if($remote) { $response = Read-Host -Prompt "Do you want to pull latest image? [N/y] [default=N]"
$image = "--pull always git.1159.cl/mario1159/$SELECTED_STACK-$EXECMODE"
} else { if ($response -eq 'y') {
$image = "$SELECTED_STACK-$EXECMODE" $global:PARAMS += " --pull-always"
} }
}
function select-pdk() {
Write-Host "Please select a pdk"
Write-Host '[1] - gf180mcuC' -ForegroundColor Cyan
Write-Host '[2] - sky130A' -ForegroundColor Cyan
$response = Read-Host "Execution mode [1-2] [default=$global:PDK]"
if ($response -eq '1') {
$global:PDK = 'gf180mcuC'
} elseif ($response -eq '2') {
$global:PDK = 'sky130A'
} else {
Write-Host "Using default pdk ($global:PDK)"
}
}
function attach-shell () {
Call "docker exec -it $global:CONTAINER_NAME bash"
}
function run-docker-wsl() {
# if($remote) {
# #$image = "--pull always git.1159.cl/mario1159/$SELECTED_STACK-$EXECMODE"
# $image = "git.1159.cl/mario1159/$SELECTED_STACK-$EXECMODE"
# } else {
# $image = "$SELECTED_STACK-$EXECMODE"
# }
$image = "git.1159.cl/mario1159/$SELECTED_STACK-$EXECMODE"
$global:PARAMS += " -d" $global:PARAMS += " -d"
$global:PARAMS += " --name $global:CONTAINER_NAME" $global:PARAMS += " --name $global:CONTAINER_NAME"
$global:PARAMS += " -v /tmp/.X11-unix:/tmp/.X11-unix" $global:PARAMS += " -v /tmp/.X11-unix:/tmp/.X11-unix"
$global:PARAMS += " -v /mnt/wslg:/mnt/wsl" $global:PARAMS += " -v /mnt/wslg:/mnt/wsl"
$global:PARAMS += " -e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY" $global:PARAMS += " -e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY"
$global:PARAMS += " -e DISPLAY=`$DISPLAY" $global:PARAMS += " -e DISPLAY=`$DISPLAY"
$global:PARAMS += " -e XDG_RUNTIME_DIR=/mnt/wslg" $global:PARAMS += " -e XDG_RUNTIME_DIR=/mnt/wslg"
$global:PARAMS += "-v ${global:DIRECTORY}:/home/designer/shared " $global:PARAMS += " -v /mnt/${global:DIRECTORY}:/home/designer/shared "
wsl -d Ubuntu bash -ic "docker run ${PARAMS} ${image}" #wsl -d Ubuntu bash -ic "docker run ${PARAMS} ${image}"
#wsl -d Ubuntu bash -ic docker run -d --name chipathon-tools -v /tmp/.X11-unix:/tmp/.X11-unix -v /mnt/wslg:/mnt/wsl -e WAYLAND_DISPLAY=$WAYLAND_DISPLAY -e DISPLAY=$DISPLAY -e XDG_RUNTIME_DIR=/mnt/wslg chipathon-tools-desktop echo "docker run ${PARAMS} ${image}"
if ($?) { if ($?) {
Write-Host "Container created successfully!" -ForegroundColor Green Write-Host "Container created successfully!" -ForegroundColor Green
Write-Host "Enter the container with `"docker exec -it $global:CONTAINER_NAME bash`"" -ForegroundColor DarkGray Write-Host "Enter the container with `"docker exec -it $global:CONTAINER_NAME bash`"" -ForegroundColor DarkGray
attach-shell
} else {
Write-Host "Container creation failed, see logs above" -ForegroundColor Red
}
}
function run-docker-win() {
$image = "git.1159.cl/mario1159/$SELECTED_STACK-$EXECMODE"
if ($clean) {
$global:PARAMS += "-it --rm"
$global:COMMAND = "bash"
} else {
$global:PARAMS += "-d"
$global:COMMAND = ""
}
$global:PARAMS += " --name $global:CONTAINER_NAME"
$global:PARAMS += " --security-opt seccomp=unconfined"
# $global:PARAMS += " -p '8888:8888'"
$global:PARAMS += " -v '\\wsl.localhost\Ubuntu\mnt\wslg:/tmp'"
$global:PARAMS += " -v ${global:DIRECTORY}:/home/designer/shared"
#$global:PARAMS += " -v '\\wsl.localhost\Ubuntu\mnt\wslg\runtime-dir'%XDG_RUNTIME_DIR%"
#$global:PARAMS += " -e WAYLAND_DISPLAY=`$WAYLAND_DISPLAY"
$global:PARAMS += " -e PDK=$global:PDK"
$global:PARAMS += " -e DISPLAY=:0"
# $global:PARAMS += " -e XDG_RUNTIME_DIR=/mnt/wslg"
# SET PARAMS=%PARAMS% -e DISPLAY=%DISPLAY%
# SET PARAMS=%PARAMS% -e WAYLAND_DISPLAY=%WAYLAND_DISPLAY%
# SET PARAMS=%PARAMS% -e XDG_RUNTIME_DIR=%XDG_RUNTIME_DIR%
Call "docker run ${PARAMS} ${image} $global:COMMAND"
if ($?) {
Write-Host "Container created successfully!" -ForegroundColor Green
Write-Host "Enter the container with `"docker exec -it $global:CONTAINER_NAME bash`"" -ForegroundColor DarkGray
attach-shell
} else { } else {
Write-Host "Container creation failed, see logs above" -ForegroundColor Red Write-Host "Container creation failed, see logs above" -ForegroundColor Red
} }
} }
function run(){ function run(){
Write-Host "OSIC-Stacks Container Creation" -ForegroundColor Green if ($silent) {
Remove-Alias Call
# validate-environment New-Alias Call Write-Host
if
($interactive) {
select-image
select-execmod
bind-to-directory
set-aditional-parameters
} }
run-docker Write-Host "OSIC-Stacks Container Creation" -ForegroundColor Green
validate-environment
if ($interactive) {
select-stack
select-execmode
bind-to-directory
set-aditional-parameters
force-pull
}
run-docker-win
} }
run run