blob: bd4d61e455e060e941fdb3be88855d79f2719c04 [file] [log] [blame]
Leonardo Sandoval98d25902020-05-24 19:50:27 -07001#!/bin/bash
2#
3# Copyright (c) 2021, 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}"
Maksims Svecovs7b948ce2022-04-21 09:40:09 +010016OS_VER="${OS_VERSION:-focal}"
Leonardo Sandoval98d25902020-05-24 19:50:27 -070017MODEL_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() {
Paul Sokolovskyb5cc7742022-11-16 22:08:00 +030039 TARBALL=$1
Leonardo Sandoval98d25902020-05-24 19:50:27 -070040 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" \
Paul Sokolovskyb5cc7742022-11-16 22:08:00 +030052 -e "s|\${TARBALL}|${TARBALL}|g" \
Leonardo Sandoval98d25902020-05-24 19:50:27 -070053 -e "s|\${MODEL}|${MODEL}|g" \
54 -e "s|\${MODEL_VER}|${MODEL_VER}|g" \
55 -e "s|\${MODEL_DIR}|${MODEL_DIR}|g" < dockerfile-template > $target_dir/Dockerfile
56}
57
58[ $# -ne 2 ] && usage
59
60tarball=$1; target_dir=$2; main ${tarball} ${target_dir}