-
Notifications
You must be signed in to change notification settings - Fork 25
/
run_container.sh
executable file
·66 lines (55 loc) · 1.85 KB
/
run_container.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
#!/bin/bash
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
readonly CONTAINER_WORK_DIR=/repo
readonly IMAGE_NAME="ot-sca"
CONTAINER_NAME=${IMAGE_NAME}
function usage() {
cat <<USAGE
Run OpenTitan SCA/FI container.
Usage: $0 -d DEVICE [-d DEVICE] -m SHM_SIZE -w HOST_WORK_DIR [-n CONTAINER_NAME] [-h]
-d: Host device to be added to the container. This option can be used multiple times.
-m: Shared memory size (/dev/shm) of the container. Should be at least 1/3 of total memory.
-w: Host directory that will be mounted into the container as /repo.
-h: Print usage information and exit.
USAGE
}
function error() {
echo "$1" 2>&1
usage
exit 1
}
DEVICES=()
while getopts ':d:m:w:n:h' opt; do
case "${opt}" in
d) DEVICES+=("${OPTARG}") ;;
m) SHM_SIZE="${OPTARG}" ;;
w) HOST_WORK_DIR="${OPTARG}" ;;
n) CONTAINER_NAME="${OPTARG}" ;;
h) usage; exit 0 ;;
:) error "Option '-${OPTARG}' requires an argument." ;;
\?) error "Invalid option: '-${OPTARG}'" ;;
*) error "Invalid option: '-${opt}'" ;;
esac
done
readonly DEVICES
readonly SHM_SIZE
readonly HOST_WORK_DIR
readonly CONTAINER_NAME
# Make sure that there are no additional arguments.
shift $((OPTIND-1))
if [[ "$#" -gt 0 ]]; then
error "Unexpected arguments: '$*'"
fi
# Make sure that all required options are present.
if [[ -z "${HOST_WORK_DIR}" ]] || [[ -z "${SHM_SIZE}" ]] || [[ ${#DEVICES[@]} -eq 0 ]]; then
error "Missing options: '-m SHM_SIZE', '-w HOST_WORK_DIR', and '-d DEVICE' are required."
fi
podman run --rm -it \
--userns=keep-id \
--shm-size "${SHM_SIZE}" \
-v "${HOST_WORK_DIR}":"${CONTAINER_WORK_DIR}" \
-w "${CONTAINER_WORK_DIR}" \
"${DEVICES[@]/#/--device=}" \
--hostname "${CONTAINER_NAME}" --name "${CONTAINER_NAME}" "${IMAGE_NAME}"