File: o-saft

package info (click to toggle)
o-saft 19.01.19-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,764 kB
  • sloc: perl: 18,248; tcl: 2,857; sh: 2,089; makefile: 1,956; awk: 274; ruby: 75; xml: 38; php: 8
file content (148 lines) | stat: -rwxr-xr-x 4,851 bytes parent folder | download
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/sh
#?
#? NAME
#?      $0 - simple wrapper to call  o-saft.pl or o-saft.tcl
#?
#? SYNOPSIS
#?      $0 [options] target
#?
#? DESCRIPTION
#?      Calls  o-saft.pl or o-saft.tcl  with all specified arguments.
#?      o-saft.pl's  output is piped to the command specified with the  -post=
#?      option. The program given there must be located in contrib/ directory,
#?      or must be found via  PATH  environment variable. The default is  cat,
#?      which means that all output is on  STDOUT.
#?
#? OPTIONS
#?      -h      got it
#?      -list   list available programs in ./contrib/ directory
#?      -cli    start o-saft.pl  with remaining arguments; this is the default
#?      -cgi    start o-saft.cgi with remaining arguments
#?      -gui    start o-saft.tcl with remaining arguments
#       -tcl    alias for -gui
#?      -docker start o-saft-docker with remaining arguments
#?      -id=*   passed to o-saft-docker
#?      -tag=*  passed to o-saft-docker
#?      -post="program [options]"
#?              program to pipe output of  o-saft.pl  to
#?      --      pass all remaining arguments to  o-saft.pl  or  o-saft.tcl
#?
#? LIMITATIONS
#?      All option listed above must preceed options to be passed through.
#?      $0  must be install in the same directory as the tools it will call
#?          $0.pl  $0.cgi  $0.tcl
#?
#? EXAMPLES
#?          $0 +cmd --option target
#?          $0 -post='bunt.pl'      ' +cmd --option target
#?          $0 -post='bunt.pl -blind' +cmd --option target
#?          $0 -gui target
#?
#?          $0 -docker +cmd --option target
#?          $0 -docker -post='bunt.pl'      ' +cmd --option target
#?          $0 -docker -post='bunt.pl -blind' +cmd --option target
#?          $0 -docker -gui target
#?
#?      Specify program to execute script (if hashbang in file fails):
#?          $0 -docker -post='perl contrib/bunt.pl' ' +cmd --option target
#?
# 
# Hacker's INFO
#       Uses options  -h  and  -post=  and not  --h  or  --help  or  --post  to
#       avoid conflicts with same option for  o-saft.pl .
#
#? VERSION
#?      @(#) o-saft 1.14 18/10/02 00:33:42
#?
#? AUTHOR
#?      17-dec-17 Achim Hoffmann
#?
# -----------------------------------------------------------------------------

ich=${0##*/}
dir=${0%/*};    [ "$dir" = "$0" ] && dir="."    # $0 found via $PATH in .
prg=$dir/$ich.pl     # most likely ich=o-saft  ..
gui=$dir/$ich.tcl
cgi=$dir/$ich.cgi
dok=$dir/$ich-docker
    # all tools are prefix with the path $dir to avoid incomplete $PATH settings
contrib=$dir/contrib
try=
post="cat"      # default, avoids special handling if -post= missing
mode=cli        # cli, cgi, gui
docker=0        # cli or gui mode; cannot use $mode because it is needed for docker too
docker_id=
docker_tag=

while [ $# -gt 0 ]; do
    case "$1" in
        -h  | '-?')
            \sed -ne "s/\$0/$ich/g" -e '/^#?/s/#?//p' $0
            \cat <<EoT
 NOTE
    To get help for  o-saft.pl, please use:
        $0 --help
    or
        o-saft.pl --help

EoT
            exit 0
            ;;
        -list)
            for exe in $contrib/* ; do
                [ -d "$exe" ] && continue
                [ -x "$exe" ] && echo "$exe"
            done
            exit 0
            ;;
        -n      | --n)      try=echo    ; ;;
        -cgi    | --cgi)    mode=cgi    ; ;;
        -cli    | --cli)    mode=cli    ; ;;
        -gui    | --gui)    mode=gui    ; ;;
        -tcl    | --tcl)    mode=gui    ; ;;
        -docker | --docker) docker=1    ; ;;
        -id*)           docker_id="$1"  ; ;;
        -tag*)          docker_tag="$1" ; ;;
        -post=*)
            post="`expr "$1" ':' '-post=\(.*\)'`"
            cmd=`echo "$post" | awk '{print $1}'`   # remove additional trailing arguments
            [ -x "$contrib/$cmd" ] && post="$contrib/$post"
            shift
            break
            ;;
        --) shift; break; ;;
        *)  break; ;;
    esac
    shift
done

# Note: using $* (instead of $@) does not contain parsed options
[ -n "$try" ] && echo "# docker=$docker, mode=$mode, post=$post, $*#"

# docker mode is special
if [ $docker -eq 1 ]; then
    if [ -n "$osaft_vm_build" ]; then
        echo "**WARNING: option -docker ignored inside VM; exit"
    else
        echo $dok $docker_id $docker_tag -$mode -post=$post $*
        [ -n "$try" ] && exit 0
             $dok $docker_id $docker_tag -$mode -post=$post $*
        exit $?
    fi
fi

# all other modes
case "$mode" in
    cgi) $try $cgi --cgi $* | $post  ; ;;
    gui) $try $gui --post="$post" $* ; ;;
    *)   echo "$prg $docker_id $docker_tag $* | $post"
         [ -n "$try" ] && exit 0
               $prg $docker_id $docker_tag $* | $post 
         ;;
esac
exit 0


# NOTE: $gui
#       all parameters are passed to $gui, even they are not yet (2018) used
#       properly, but most likely treated as hostname