Leonardo Sandoval | 98d2590 | 2020-05-24 19:50:27 -0700 | [diff] [blame] | 1 | #!/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 |
| 15 | OS="${OS:-ubuntu}" |
Maksims Svecovs | 7b948ce | 2022-04-21 09:40:09 +0100 | [diff] [blame] | 16 | OS_VER="${OS_VERSION:-focal}" |
Leonardo Sandoval | 98d2590 | 2020-05-24 19:50:27 -0700 | [diff] [blame] | 17 | MODEL_DIR="${MODEL_DIR:-/opt/model}" |
| 18 | |
| 19 | function usage() { |
| 20 | echo "Usage: $0 model-tarball target-dir" 1>&2 |
| 21 | exit 1 |
| 22 | } |
| 23 | |
| 24 | function 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 | |
| 38 | function main() { |
Paul Sokolovsky | b5cc774 | 2022-11-16 22:08:00 +0300 | [diff] [blame] | 39 | TARBALL=$1 |
Leonardo Sandoval | 98d2590 | 2020-05-24 19:50:27 -0700 | [diff] [blame] | 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" \ |
Paul Sokolovsky | b5cc774 | 2022-11-16 22:08:00 +0300 | [diff] [blame] | 52 | -e "s|\${TARBALL}|${TARBALL}|g" \ |
Leonardo Sandoval | 98d2590 | 2020-05-24 19:50:27 -0700 | [diff] [blame] | 53 | -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 | |
| 60 | tarball=$1; target_dir=$2; main ${tarball} ${target_dir} |