-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.bash
executable file
·82 lines (66 loc) · 2.7 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
#!/bin/bash
# ================================= Edit Here ================================ #
# TODO: Change these values to use different versions of ROS or different base images. The rest of the script should be left unchanged.
# Remember to change the ROS_NUMBER in accordance to the ROS version, otherwise you're stupid and deserve a painful death.
BASE_IMAGE=osrf/ros
BASE_TAG=humble-desktop
ROS_NUMBER=2
IMAGE_NAME=control_and_state_estimator_exp
# =============================== Preliminaries ============================== #
mkdir -p build log src
if [[ $ROS_NUMBER == 1 ]]; then
mkdir -p devel
elif [[ $ROS_NUMBER == 2 ]]; then
mkdir -p install
fi
mkdir -p ~/.vscode ~/.vscode-server ~/.config/Code
# =============================== Help Function ============================== #
helpFunction()
{
echo ""
echo "Usage: $0 [-r]"
echo -e "\t-h --help Print the help."
echo -e "\t-r --rebuild Rebuild the image."
exit 1 # Exit script after printing help
}
# =============================== Build Options ============================== #
# Initialie the build options
REBUILD=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 hr-: 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
h | help ) no_arg; helpFunction ;;
r | rebuild ) no_arg; REBUILD=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 ROS_NUMBER=$ROS_NUMBER \
--build-arg MYUID=${UID} \
--build-arg MYGID=${GID} \
--build-arg USER=${USER} \
--build-arg "PWDR=$PWD" \
-t $IMAGE_NAME .