blob: 88577599dbb8e172f74a58872c808b8b451f4c4c [file] [log] [blame]
Leonardo Sandoval42065f32020-08-28 15:29:01 -05001#!/bin/bash
2#
3# Copyright (c) 2020, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Creates a dockerfile based on a fvp model (model).
9
10# The scripts takes two argument: the model tarball's filename (first argument)
11# and target directory to store the created Dockerfile (second argument)
12#
13
14# globals
15OS="${OS:-ubuntu}"
Boyan Karatotev3fdb34a2023-01-10 08:57:37 +000016OS_VER="${OS_VERSION:-jammy}"
Leonardo Sandoval42065f32020-08-28 15:29:01 -050017MODEL_DIR="${MODEL_DIR:-/opt/model}"
18
19function usage() {
20 echo "Usage: $0 model-tarball target-dir" 1>&2
21 exit 1
22}
23
24function get_model_model_ver() {
25 local tgz=$1
26 local arr_model=(${tgz//./ })
27 local x=${arr_model[0]##*_}
28 local y=${arr_model[1]}
29 local z=${arr_model[2]}
30 if [ -n "$z" -a "$z" != "tgz" ]; then
31 MODEL_VER="${x}.${y}.${z}"
32 else
33 MODEL_VER="${x}.${y}"
34 fi
35 MODEL=$(echo $tgz | sed "s/_${MODEL_VER}.tgz//")
36}
37
38function main() {
39 local tarball=$1
40 local target_dir=$2
41
42 # get MODEL and MODEL_VER
43 get_model_model_ver $tarball
44
45 # check variables are populated
46 MODEL="${MODEL:?}"
47 MODEL_VER="${MODEL_VER:?}"
48
49 # replace template macros with real model values
50 sed -e "s|\${OS}|${OS}|g" \
51 -e "s|\${OS_VER}|${OS_VER}|g" \
52 -e "s|\${MODEL}|${MODEL}|g" \
53 -e "s|\${MODEL_VER}|${MODEL_VER}|g" \
54 -e "s|\${MODEL_DIR}|${MODEL_DIR}|g" < dockerfile-template > $target_dir/Dockerfile
55}
56
57[ $# -ne 2 ] && usage
58
59tarball=$1; target_dir=$2; main ${tarball} ${target_dir}