1
1
# This is an example of how to run the docker container.
2
2
# This script is not part of the container, it is meant to be run on the host machine.
3
- # Usage: ./ run.ps1 <path_to_arduino_esp32>
3
+ # Usage: .\ run.ps1 <path_to_arduino_esp32>
4
4
5
- if (-not (Test-Path - Path (Get-Command docker).Source)) {
6
- Write-Host " ERROR: Docker is not installed! Please install docker first."
5
+ # Exit on error
6
+ $ErrorActionPreference = " stop"
7
+
8
+ # https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/
9
+ # Check if command exists
10
+ Function Test-CommandExists
11
+ {
12
+ Param ($command )
13
+ try {
14
+ if (Get-Command $command ) {
15
+ RETURN $true
16
+ }
17
+ }
18
+ catch {
19
+ RETURN $false
20
+ }
21
+ }
22
+
23
+ # Check if path exists
24
+ Function Test-PathExists
25
+ {
26
+ Param ($path )
27
+ try {
28
+ if (Test-Path - Path $path ) {
29
+ RETURN $true
30
+ }
31
+ }
32
+ catch {
33
+ RETURN $false
34
+ }
35
+ }
36
+
37
+ if (-not (Test-CommandExists docker)) {
38
+ Write-Host " ERROR: Docker is not installed! Please install docker first." - ForegroundColor red
7
39
exit 1
8
40
}
9
41
10
42
if ($args.Count -gt 0 ) {
11
- $ARDUINO_DIR = $args [0 ] -replace ' \\' , ' /'
12
- } else {
13
- $ARDUINO_DIR = ' '
43
+ $ARDUINO_DIR = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath ($args [0 ])
14
44
}
15
45
16
46
$DOCKER_ARGS = @ ()
17
47
$DOCKER_ARGS += ' -it'
18
48
$DOCKER_ARGS += ' -e' , ' TERM=xterm-256color'
19
49
20
- if ((Test-Path $ARDUINO_DIR )) {
21
- $DOCKER_ARGS += ' -v' , " $ARDUINO_DIR :/arduino-esp32"
50
+ if ((Test-PathExists $ARDUINO_DIR )) {
51
+ $DOCKER_ARGS += ' -v' , " ${ ARDUINO_DIR} :/arduino-esp32"
22
52
} else {
23
53
Write-Output " Warning: Invalid arduino directory: '$ARDUINO_DIR '. Ignoring it."
24
54
}
@@ -28,4 +58,4 @@ if ($env:LIBBUILDER_GIT_SAFE_DIR) {
28
58
}
29
59
30
60
Write-Output " Running: docker run $ ( $DOCKER_ARGS -join ' ' ) lucassvaz/esp32-arduino-lib-builder"
31
- # docker run @($DOCKER_ARGS) lucassvaz/esp32-arduino-lib-builder
61
+ docker run @ ($DOCKER_ARGS ) lucassvaz/ esp32- arduino- lib- builder
0 commit comments