forked from efabless/foss-asic-tools
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathstart_shell.bat
More file actions
103 lines (88 loc) · 4.82 KB
/
Copy pathstart_shell.bat
File metadata and controls
103 lines (88 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
@echo off
:: ========================================================================
:: SPDX-FileCopyrightText: 2022-2026 Harald Pretl and Georg Zachl
:: Johannes Kepler University, Department for Integrated Circuits
::.
:: Licensed under the Apache License, Version 2.0 (the "License");
:: you may not use this file except in compliance with the License.
:: You may obtain a copy of the License at
::.
:: http://www.apache.org/licenses/LICENSE-2.0
::.
:: Unless required by applicable law or agreed to in writing, software
:: distributed under the License is distributed on an "AS IS" BASIS,
:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
:: See the License for the specific language governing permissions and
:: limitations under the License.
:: SPDX-License-Identifier: Apache-2.0
:: ========================================================================
SETLOCAL
SET DEFAULT_DESIGNS=%USERPROFILE%\eda\designs
IF DEFINED DRY_RUN (
echo This is a dry run, all commands will be printed to the shell ^(Commands printed but not executed are marked with ^$^)!
SET ECHO_IF_DRY_RUN=ECHO $
)
IF "%DESIGNS%"=="" (
SET DESIGNS=%DEFAULT_DESIGNS%
)
echo Using/creating designs directory: %DESIGNS%
if not exist "%DESIGNS%" %ECHO_IF_DRY_RUN% mkdir "%DESIGNS%"
:: Select the container engine (Docker or Podman), can be overridden by
:: setting CONTAINER_ENGINE.
IF NOT DEFINED CONTAINER_ENGINE (
where /q docker
IF NOT ERRORLEVEL 1 (
SET CONTAINER_ENGINE=docker
) ELSE (
where /q podman
IF NOT ERRORLEVEL 1 (
SET CONTAINER_ENGINE=podman
) ELSE (
ECHO ERROR: No container engine found, please install Docker or Podman!
EXIT /B 1
)
)
)
ECHO Using container engine %CONTAINER_ENGINE%
IF "%DOCKER_USER%"=="" SET DOCKER_USER=hpretl
IF "%DOCKER_IMAGE%"=="" SET DOCKER_IMAGE=iic-osic-tools
IF "%DOCKER_TAG%"=="" SET DOCKER_TAG=latest
:: Fully qualify the image name (Podman does not resolve short names
:: non-interactively); set DOCKER_REGISTRY=none to use unqualified names.
IF "%DOCKER_REGISTRY%"=="" SET DOCKER_REGISTRY=docker.io
SET IMAGE_PREFIX=%DOCKER_REGISTRY%/
IF /I "%DOCKER_REGISTRY%"=="none" SET IMAGE_PREFIX=
:: An empty DOCKER_USER means the image sits at the root of the registry.
SET IMAGE_PATH=%DOCKER_IMAGE%
IF DEFINED DOCKER_USER SET IMAGE_PATH=%DOCKER_USER%/%DOCKER_IMAGE%
:: A DOCKER_USER that contains "." or ":", or is "localhost", already names a
:: registry (e.g. "myregistry:5000"), so the image name must not be prefixed.
IF DEFINED DOCKER_USER IF NOT "%DOCKER_USER%"=="%DOCKER_USER::=%" SET IMAGE_PREFIX=
IF DEFINED DOCKER_USER IF NOT "%DOCKER_USER%"=="%DOCKER_USER:.=%" SET IMAGE_PREFIX=
IF /I "%DOCKER_USER%"=="localhost" SET IMAGE_PREFIX=
SET IMAGE_NAME=%IMAGE_PREFIX%%IMAGE_PATH%:%DOCKER_TAG%
:: Docker Desktop and Podman machine expose the host WSLg directory at
:: different locations inside their WSL2 VMs.
SET WSLG_ROOT=/run/desktop/mnt/host/wslg
IF "%CONTAINER_ENGINE%"=="podman" SET WSLG_ROOT=/mnt/wslg
IF "%CONTAINER_USER%"=="" SET CONTAINER_USER=0
IF "%CONTAINER_GROUP%"=="" SET CONTAINER_GROUP=0
IF "%CONTAINER_NAME%"=="" SET CONTAINER_NAME=iic-osic-tools_shell
IF "%DISP%"=="" SET DISP=:0
IF "%WAYLAND_DISP%"=="" SET WAYLAND_DISP=wayland-0
IF %CONTAINER_USER% NEQ 0 if %CONTAINER_USER% LSS 1000 echo WARNING: Selected User ID %CONTAINER_USER% is below 1000. This ID might interfere with User-IDs inside the container and cause undefined behaviour!
IF %CONTAINER_GROUP% NEQ 0 if %CONTAINER_GROUP% LSS 1000 echo WARNING: Selected Group ID %CONTAINER_GROUP% is below 1000. This ID might interfere with Group-IDs inside the container and cause undefined behaviour!
SET PARAMS=--security-opt seccomp=unconfined
%CONTAINER_ENGINE% container inspect %CONTAINER_NAME% 2>&1 | find "Status" | find /i "running"
IF NOT ERRORLEVEL 1 (
ECHO Container is running! Stop with \"%CONTAINER_ENGINE% stop %CONTAINER_NAME%\" and remove with \"%CONTAINER_ENGINE% rm %CONTAINER_NAME%\" if required.
) ELSE (
%CONTAINER_ENGINE% container inspect %CONTAINER_NAME% 2>&1 | find "Status" | find /i "exited"
IF NOT ERRORLEVEL 1 (
echo Container %CONTAINER_NAME% exists. Restart with \"%CONTAINER_ENGINE% start %CONTAINER_NAME%\" or remove with \"%CONTAINER_ENGINE% rm %CONTAINER_NAME%\" if required.
) ELSE (
echo Container does not exist, pulling %IMAGE_NAME% and creating %CONTAINER_NAME% ...
%ECHO_IF_DRY_RUN% %CONTAINER_ENGINE% pull %IMAGE_NAME%
%ECHO_IF_DRY_RUN% %CONTAINER_ENGINE% run -it --user %CONTAINER_USER%:%CONTAINER_GROUP% -e DISPLAY=%DISP% -e WAYLAND_DISPLAY=%WAYLAND_DISP% -e XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir -e PULSE_SERVER=/mnt/wslg/PulseServer -v %WSLG_ROOT%/.X11-unix:/tmp/.X11-unix -v %WSLG_ROOT%:/mnt/wslg --device=/dev/dxg -v /usr/lib/wsl:/usr/lib/wsl %DOCKER_EXTRA_PARAMS% %PARAMS% -v "%DESIGNS%":/foss/designs --name %CONTAINER_NAME% %IMAGE_NAME% -s /bin/bash
)
)