#!/bin/sh # --- T2-COPYRIGHT-NOTE-BEGIN --- # This copyright note is auto-generated by ./scripts/Create-CopyPatch. # # T2 SDE: misc/tail/formats/tail.in # Copyright (C) 2004 - 2005 The T2 SDE Project # # More information can be found in the files COPYING and README. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. A copy of the # GNU General Public License can be found in the file COPYING. # --- T2-COPYRIGHT-NOTE-END --- # T2 Automated Init Language - Tail # http://wiki.t2-project.org/index.cgi?TailFormat # Alejandro Mery tail_read() { local verbose=1 file= output= query= local query= count=2 if [ "$1" == "-q" ]; then verbose= shift fi file="$1"; shift while [ $# -gt 1 ]; do query="${query}$1 " shift; (( count++ )) done query="${query}$1\\( \\|\$\\)" output="$( grep -e "^$query" $file | cut -f$count- )" [ "$verbose" ] && echo "$output" grep -q -e "^$query" $file } tail_install() { local style=$1 tailfile="$2" local x= y= z= shift 2 case "$style" in runit) local servicedir=$( echo `eval echo $1` ) local runprefix= mkdir -vp "$servicedir" rm -f /tmp/tail.$$ # run /tailrun/ options # eval "`tail_read $tailfile tailrun $style`" # ./env/ # if tail_read -q $tailfile env; then mkdir -p "$servicedir/env" runprefix="$runprefix${runprefix:+ }envdir ./env" tail_read $tailfile env | while read x y; do echo "TAIL: ./env/$x = $y" echo "$y" | sde_substitute > $servicedir/env/$x done fi # ./run # cat <<-EOT > /tmp/tail.$$ #!/bin/sh exec 2>&1 EOT if tail_read -q $tailfile input; then echo "exec < $( tail_read $tailfile input )" >> /tmp/tail.$$ fi if tail_read -q $tailfile user; then runprefix="$runprefix${runprefix:+ }envuidgid $( tail_read $tailfile user )" fi echo "exec $runprefix${runprefix:+ }$( tail_read $tailfile run )" >> /tmp/tail.$$ sde_substitute /tmp/tail.$$ > $servicedir/run chmod +x $servicedir/run # ./conffile # for x in `tail_read $tailfile conf | cut -f1 | sort -u`; do y="$x" echo "TAIL: $x ..." if [ "${y%/*}" != "$y" ]; then if [ "${y:0:1}" != "/" ]; then y="$servicedir/$y" fi mkdir -vp ${y%/*} fi rm -vf $y tail_read $tailfile conf $x | sde_substitute > $y done # ./log/ # if tail_read -q $tailfile log; then mkdir -vp "$servicedir/log/main" if [ -z "$logdir" ]; then if [ "${localstatedir%$pkg}" != "$localstatedir" ]; then logdir=$localstatedir/log else logdir=$localstatedir/log/$pkg fi fi z= for x in `tail_read $tailfile log | cut -f1 | sort -u`; do echo "TAIL: ./log/$x" mkdir -vp $root/$logdir/$x chown 9:9 $root/$logdir/$x ln -vnfs $logdir/$x $servicedir/log/main/ z="$z main/$x" y="`tail_read $tailfile log $x`" [ "$y" ] && echo "$y" > $root/$logdir/$x/config || true done cat <<-EOT > "$servicedir/log/run" #!/bin/sh exec 2>&1 exec setuidgid log svlogd -t $z EOT chmod +x "$servicedir/log/run" fi ;; *) abort "tail_install: unknown style '$style' for $tailfile." ;; esac }