-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.bash
executable file
·91 lines (74 loc) · 3.13 KB
/
build.bash
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
#!/bin/bash
mkdir -p build install log
# ================================= Edit Here ================================ #
# Change these values to use different versions of ROS or different base images. The rest of the script should be left unchanged.
BASE_IMAGE=osrf/ros
BASE_TAG=iron-desktop
IMAGE_NAME=qcsc
# =============================== Help Function ============================== #
helpFunction()
{
echo ""
echo "Usage: $0 [-a] [-d] [-h] [-p] [-r] [-t]"
echo -e "\t-a --all Install all the optional packages."
echo -e "\t-d --development Install additional packages for development purposes."
echo -e "\t-h --help Print the help."
echo -e "\t-p --plot Install latex in the image. Bigger image, but plot.py can be used to plot some figures."
echo -e "\t-r --rebuild Rebuild the image."
echo -e "\t-t --terrain-gen Install bly (blender Python API) to generate terrains from heightmaps."
echo -e "\t --tracing Install ros2trace and tracetools-analysis."
exit 1 # Exit script after printing help
}
# =============================== Build Options ============================== #
# Initialie the build options
DEVELOPMENT=0
PLOT=0
REBUILD=0
TERRAIN_GEN=0
TRACING=0
# Auxiliary functions
die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }
no_arg() { if [ -n "$OPTARG" ]; then die "No arg allowed for --$OPT option"; fi; }
# Get the script options. This accepts both single dash (e.g. -a) and double dash options (e.g. --all)
while getopts adhprt-: OPT; do
# support long options: https://stackoverflow.com/a/28466267/519360
if [ "$OPT" = "-" ]; then # long option: reformulate OPT and OPTARG
OPT="${OPTARG%%=*}" # extract long option name
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty)
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=`
fi
case "$OPT" in
a | all ) no_arg; DEVELOPMENT=1; PLOT=1; TERRAIN_GEN=1; TRACING=1 ;;
d | development ) no_arg; DEVELOPMENT=1 ;;
h | help ) no_arg; helpFunction ;;
p | plot ) no_arg; PLOT=1 ;;
r | rebuild ) no_arg; REBUILD=1 ;;
t | terrain_gen ) no_arg; TERRAIN_GEN=1 ;;
tracing ) no_arg; TRACING=1 ;;
??* ) die "Illegal option --$OPT" ;; # bad long option
? ) exit 2 ;; # bad short option (error reported via getopts)
esac
done
shift $((OPTIND-1)) # remove parsed options and args from $@ list
# ========================= Pull And Build The Image ========================= #
docker pull $BASE_IMAGE:$BASE_TAG
GID="$(id -g $USER)"
if [ "$REBUILD" -eq 1 ]; then
cache="--no-cache"
else
cache=""
fi
docker build \
${cache} \
--build-arg BASE_IMAGE=$BASE_IMAGE \
--build-arg BASE_TAG=$BASE_TAG \
--build-arg MYUID=${UID} \
--build-arg MYGID=${GID} \
--build-arg USER=${USER} \
--build-arg "PWDR=$PWD" \
--build-arg DEVELOPMENT=$DEVELOPMENT \
--build-arg PLOT=$PLOT \
--build-arg TERRAIN_GEN=$TERRAIN_GEN \
--build-arg TRACING=$TRACING \
-t $IMAGE_NAME .