File: example.ia_ask

package info (click to toggle)
shellia 5.10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: sh: 7,840; makefile: 34
file content (61 lines) | stat: -rwxr-xr-x 1,852 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# vim: set filetype=sh :
#        file: example.ia_ask
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
#     license: GNU General Public License, version 3
# description: test function ia_ask
#    see also: test.ia_ask
set -e
set -u

dir="$(realpath $(dirname $0))"
pdir="$(realpath $(dirname $0)/..)"
name="$(basename $0)"
host="$(hostname)"
[ "${ia_logfile:-}" ] || ia_logfile="$dir/$name.log"
. $pdir/ia

eval "$ia_init"

# ssh options are only for manual tests 
# ssh login to localhost must be possible without password
ssh_t=""
ssh_T=""
ssh_TT=""
while [ $# -gt 0 ]; do
  if [ "$1" = "-t" ]; then
    ssh_t="$1"
    shift
  elif [ "$1" = "-T" ]; then
    ssh_T="$1"
    shift
  elif [ "$1" = "-TT" ]; then
    ssh_TT="$1"
    shift
  else
    ia_err "Usage test_ask [-t|-T|-TT]
  -t run <ssh -t $host ...>
  -T run <ssh -T $host ...>
  -TT run <ssh -T $host ssh -T $host ...>"
    exit 0
  fi
done

ia_nocheck && ia_add "[ ! -n \"$ssh_t\" ] || { my_ssh --ia -x -t $host \"cd $pdir; ./tests/$name <-i>\"; exit; }"
ia_nocheck && ia_add "[ ! -n \"$ssh_T\" ] || { my_ssh --ia -x -T $host \"cd $pdir; ./tests/$name <-i>\"; exit; }"
ia_nocheck && ia_add "[ ! -n \"$ssh_TT\" ] || { my_ssh --ia -x -T $host \"cd $pdir; ./tests/$name <-i> -T\"; exit; }"

ia_add "ia_logerr \"=== default ===\""
# ia_ask <question> <default> <problem> <prompt> <regex>
ia_add "A=\$(ia_ask \"please answer y or n (default=n)\" \"n\" \"q\" \"? \" \"^(y|n)$\")"
ia_add "ia_logerr \"A=<$<A>>\""

ia_add "ia_logerr \"=== -f, no default ===\""
ia_add "A=\$(ia_ask -f \"please answer y or n\" \"\" \"q\" \"? \" \"^(y|n)$\") # no default"
ia_add "ia_logerr \"A=<$<A>>\""

ia_add "ia_logerr \"=== -p -2, no default ===\""
ia_add "A=\$(ia_ask -p -2 \"password\" \"\" \"q\" \"? \" \"^\S\") # no default, no eof"
ia_add "ia_logerr \"A=<$<A>>\""

ia -c