1#!/usr/bin/env bash 2 3set -e 4 5rootdir=$(readlink -f $(dirname $0))/.. 6 7function usage { 8 echo "Replaces FTL_* variables in config files inside the config/ directory." 9 echo "The following varaibles are replaced:" 10 echo "- FTL_CONF_DIR - config directory" 11 echo "- FTL_TRANSPORT_ADDR - SSD's PCIe address (defaults to first lnvm device)" 12 echo "- FTL_BDEV_NAME - name of the bdev" 13 echo "- FTL_BDEV_PUNITS - bdev's parallel unit range (e.g. 0-3)" 14 echo "- FTL_BDEV_UUID - bdev's uuid (used when in restore mode)" 15 echo 16 echo "Usage: $0 -a TRANSPORT_ADDR -n BDEV_NAME -l PUNITS [-u UUID]" 17 echo "UUID is required when restoring device state" 18} 19 20function generate_config { 21 fname=$1 22 output=${1%.in} 23 24 cp $fname $output 25 for var in ${!vmap[@]}; do 26 sed -i "s,$var,${vmap[$var]},g" $output 27 done 28} 29 30while getopts ":a:n:l:m:u:" arg; do 31 case "$arg" in 32 a) addr=$OPTARG ;; 33 n) name=$OPTARG ;; 34 l) punits=$OPTARG ;; 35 u) uuid=$OPTARG ;; 36 h) usage 37 exit 0 ;; 38 *) usage 39 exit 1 ;; 40 esac 41done 42 43if [[ -z "$addr" || -z "$name" || -z "$punits" ]]; then 44 usage 45 exit 1 46fi 47 48declare -A vmap 49vmap[FTL_CONF_DIR]=$rootdir/test/ftl/config 50vmap[FTL_TRANSPORT_ADDR]=$addr 51vmap[FTL_BDEV_NAME]=$name 52vmap[FTL_BDEV_PUNITS]=$punits 53vmap[FTL_BDEV_UUID]=${uuid:-} 54 55for file in $(find $rootdir/test/ftl/config -type f -iname "*.in"); do 56 generate_config $file 57done 58