-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrun.sh
executable file
·91 lines (74 loc) · 2.22 KB
/
run.sh
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
#!/usr/bin/env bash
# Change this folder to your project working directory
# this file is mounted to your Docker image whenever you
# spin up the container
# On Unix: CHANGE THIS LINE to your project directory
# example:
# work=/Users/tommytrojan/cs350/xv6-public-master
work=~/projects/xv6-public
img_name=cs350_docker
docker_compose="./docker-compose.yml"
# Check if mounting directory is set
if [[ -z "${work}" ]]; then
work=""
echo -e "No work directory set!\nMake sure to set at the top of the run.sh script, please!"
exit 1
fi
# Check if mount directory can be found
if [[ ! -d "${work}" ]]; then
echo -e "The work directory cannot be found!\nMake sure you set this at the top of the run.sh script, please!"
exit 1
else
export work=$work
fi
function docker_up() {
# Create docker image
built=$( docker image ls | grep -c "${img_name}")
if [[ $built ]]; then
echo "Running Docker image"
else
echo "Building Docker image"
fi
docker-compose -f "${docker_compose}" up -d || exit $?
echo "Done!"
}
function docker_down() {
# stop running docker image
docker-compose -f "${docker_compose}" down
}
function docker_shell() {
# check if a container is running
container=$(docker ps | grep -c "${img_name}")
if [[ $container == 0 ]]; then
echo "No container running. Please run first!"
exit 1;
fi
docker exec -it "${img_name}" /bin/bash
}
function docker_build() {
# check if a container is running
container=$(docker ps | grep -c "${img_name}")
if [[ $container == 0 ]]; then
echo "No container running. Please run first!"
exit 1;
fi
# We'll assume that xv6_docker contains the project directory
docker exec -it -w /xv6_docker "${img_name}" /usr/bin/make fs.img xv6.img
}
if [[ $1 = "start" ]]; then
docker_up
exit $?
elif [[ $1 = "stop" ]]; then
docker_down
elif [[ $1 = "shell" ]]; then
docker_shell
elif [[ $1 = "build" ]]; then
docker_build
else
echo this script manages the linux container
echo start - run the docker container
echo shell - start a shell to run commands in xv6
echo build - runs \`make fs.img xv6.img\`
echo stop - kill the linux container
exit 1
fi