-
Notifications
You must be signed in to change notification settings - Fork 6
/
run.ps1
61 lines (50 loc) · 1.41 KB
/
run.ps1
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
# change this variable to the path to your project directory
$work="C:\Users\Username\csci350"
$docker_compose=".\docker-compose.yml"
$img_name="cs350_docker"
# TODO: check if work/docker-compose variables are set
if (-Not (Test-Path $work)) {
Write-Output "Invalid path to project directory: $work"
Return
} else {
$env:work=$work
}
function usage() {
Write-Output "this script manages the linux container"
Write-Output " start - run the docker container"
Write-Output " shell - start a shell to run commands in xv6"
Write-Output " stop - kill the linux container"
}
function docker_up() {
$built=( docker images | Select-String -Pattern "$img_name")
if ( [string]::IsNullOrEmpty($built) ) {
Write-Output "Running Docker image"
} else {
Write-Output "Pulling Docker image"
}
docker-compose -f "$docker_compose" up -d
}
function docker_down () {
docker-compose -f "$docker_compose" down
}
function docker_shell() {
$container=(docker ps | Select-String -Pattern "$img_name" -AllMatches)
if ( $container.Matches.Count -eq 0 ) {
Write-Output "No container running. Please run first!"
Return
}
docker exec -it "$img_name" /bin/bash
}
if ($args.Count -lt 1) {
Write-Output "Please specify a command to run"
}
$Command=$args[0]
if ($Command -eq "start") {
docker_up
} elseif ($Command -eq "stop") {
docker_down
} elseif ($Command -eq "shell") {
docker_shell
} else {
usage
}