#!/bin/sh
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
#

usage="
Usage: example.mylib [<shellia-opts>] [--sshopts <sshopts>]

<sshopts>      additional options for ssh
<shellia-opts> options like -i see man shellia(1)
"
ssh_options=""
ssh_errmsg="need password-less ssh to localhost for next tests"

SCRIPT_DIR="$(realpath $(dirname $0))"
PWD_DIR="$PWD"
. "$SCRIPT_DIR/mylib"

eval "$ia_init"

while [ $# -gt 0 ]; do
  case "$1" in
    --sshopts)
      ssh_options="$ssh_options $2"
      shift 2
      ;;
    *)
      err "Unknown option <$1> $usage"
      ;;
  esac
done

MY_ADD "ia_file $<SCRIPT_DIR>/hello_world <-i>"
MY_ADD "ia_file $<SCRIPT_DIR>/hello_world_fun <-i> \"debian linux\""

MY_ADD "ssh $<ssh_options> localhost : || err \"$<ssh_errmsg>\""

MY_ADD "ia_ssh $<ssh_options> localhost \"cd $<PWD_DIR>; $<SCRIPT_DIR>/hello_world <-i>\""
MY_ADD "ia_ssh $<ssh_options> localhost \"cd $<PWD_DIR>; $<SCRIPT_DIR>/hello_world_fun <-i> \\\"debian linux\\\"\""

ia -c
