2 # --- T2-COPYRIGHT-NOTE-BEGIN ---
3 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
5 # T2 SDE: misc/tail/formats/tail.in
6 # Copyright (C) 2004 - 2005 The T2 SDE Project
8 # More information can be found in the files COPYING and README.
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # T2 Automated Init Language - Tail
17 # http://wiki.t2-project.org/index.cgi?TailFormat
18 # Alejandro Mery <amery@geeks.cl>
21 local verbose
=1 file= output
= query
=
24 if [ "$1" == "-q" ]; then
30 while [ $# -gt 1 ]; do
35 query
="${query}$1\\( \\|\$\\)"
37 output
="$( grep -e "^
$query" $file | cut -f$count- )"
38 [ "$verbose" ] && echo "$output"
40 grep -q -e "^$query" $file
44 local style
=$1 tailfile
="$2"
50 local servicedir
=$
( echo `eval echo $1` )
53 mkdir
-vp "$servicedir"
56 # run /tailrun/ options
58 eval "`tail_read $tailfile tailrun $style`"
62 if tail_read
-q $tailfile env
; then
63 mkdir
-p "$servicedir/env"
64 runprefix
="$runprefix${runprefix:+ }envdir ./env"
65 tail_read
$tailfile env |
while read x y
; do
66 echo "TAIL: ./env/$x = $y"
67 echo "$y" | sde_substitute
> $servicedir/env
/$x
73 cat <<-EOT > /tmp/tail.$$
78 if tail_read
-q $tailfile input
; then
79 echo "exec < $( tail_read $tailfile input )" >> /tmp
/tail.$$
82 if tail_read
-q $tailfile user
; then
83 runprefix
="$runprefix${runprefix:+ }envuidgid $( tail_read $tailfile user )"
86 echo "exec $runprefix${runprefix:+ }$( tail_read $tailfile run )" >> /tmp
/tail.$$
88 sde_substitute
/tmp
/tail.$$
> $servicedir/run
89 chmod +x
$servicedir/run
93 for x
in `tail_read $tailfile conf | cut -f1 | sort -u`; do
96 if [ "${y%/*}" != "$y" ]; then
97 if [ "${y:0:1}" != "/" ]; then
103 tail_read
$tailfile conf
$x | sde_substitute
> $y
108 if tail_read
-q $tailfile log
; then
109 mkdir
-vp "$servicedir/log/main"
111 if [ -z "$logdir" ]; then
112 if [ "${localstatedir%$pkg}" != "$localstatedir" ]; then
113 logdir
=$localstatedir/log
115 logdir
=$localstatedir/log
/$pkg
120 for x
in `tail_read $tailfile log | cut -f1 | sort -u`; do
121 echo "TAIL: ./log/$x"
122 mkdir
-vp $root/$logdir/$x
123 chown
9:9 $root/$logdir/$x
125 ln -vnfs $logdir/$x $servicedir/log
/main
/
129 y
="`tail_read $tailfile log $x`"
130 [ "$y" ] && echo "$y" > $root/$logdir/$x/config || true
132 cat <<-EOT > "$servicedir/log/run"
136 exec setuidgid log svlogd -t $z
138 chmod +x
"$servicedir/log/run"
143 abort
"tail_install: unknown style '$style' for $tailfile."