OpenSDE Framework (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.3 KiB

  1. #!/bin/sh
  2. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # T2 SDE: misc/tail/formats/tail.in
  6. # Copyright (C) 2004 - 2006 The T2 SDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  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 ---
  15. # T2 Automated Init Language - Tail
  16. # http://wiki.t2-project.org/index.cgi?TailFormat
  17. # Alejandro Mery <amery@geeks.cl>
  18. tail_read() {
  19. local verbose=1 file= output= query=
  20. local query= count=2
  21. if [ "$1" == "-q" ]; then
  22. verbose=
  23. shift
  24. fi
  25. file="$1"; shift
  26. while [ $# -gt 1 ]; do
  27. query="${query}$1 "
  28. shift;
  29. (( count++ ))
  30. done
  31. query="${query}$1\\( \\|\$\\)"
  32. output="$( grep -e "^$query" $file | cut -f$count- )"
  33. [ "$verbose" ] && echo "$output"
  34. grep -q -e "^$query" $file
  35. }
  36. tail_install() {
  37. local style=$1 tailfile="$2"
  38. local x= y= z=
  39. shift 2
  40. case "$style" in
  41. runit)
  42. local servicedir=$( echo `eval echo $1` )
  43. local runprefix=
  44. mkdir -vp "$servicedir"
  45. rm -f /tmp/tail.$$
  46. # run /tailrun/ options
  47. #
  48. eval "`tail_read $tailfile tailrun $style`"
  49. # ./env/
  50. #
  51. if tail_read -q $tailfile env; then
  52. mkdir -p "$servicedir/env"
  53. runprefix="$runprefix${runprefix:+ }envdir ./env"
  54. tail_read $tailfile env | while read x y; do
  55. echo "TAIL: ./env/$x = $y"
  56. echo "$y" | rock_substitute > $servicedir/env/$x
  57. done
  58. fi
  59. # ./run
  60. #
  61. cat <<-EOT > /tmp/tail.$$
  62. #!/bin/sh
  63. exec 2>&1
  64. EOT
  65. if tail_read -q $tailfile input; then
  66. echo "exec < $( tail_read $tailfile input )" >> /tmp/tail.$$
  67. fi
  68. if tail_read -q $tailfile user; then
  69. runprefix="$runprefix${runprefix:+ }envuidgid $( tail_read $tailfile user )"
  70. fi
  71. echo "exec $runprefix${runprefix:+ }$( tail_read $tailfile run )" >> /tmp/tail.$$
  72. rock_substitute /tmp/tail.$$ > $servicedir/run
  73. chmod +x $servicedir/run
  74. # ./conffile
  75. #
  76. for x in `tail_read $tailfile conf | cut -f1 | sort -u`; do
  77. y="$x"
  78. echo "TAIL: $x ..."
  79. if [ "${y%/*}" != "$y" ]; then
  80. if [ "${y:0:1}" != "/" ]; then
  81. y="$servicedir/$y"
  82. fi
  83. mkdir -vp ${y%/*}
  84. fi
  85. rm -vf $y
  86. tail_read $tailfile conf $x | rock_substitute > $y
  87. done
  88. # ./log/
  89. #
  90. if tail_read -q $tailfile log; then
  91. mkdir -vp "$servicedir/log/main"
  92. if [ -z "$logdir" ]; then
  93. if [ "${localstatedir%$pkg}" != "$localstatedir" ]; then
  94. logdir=$localstatedir/log
  95. else
  96. logdir=$localstatedir/log/$pkg
  97. fi
  98. fi
  99. z=
  100. for x in `tail_read $tailfile log | cut -f1 | sort -u`; do
  101. echo "TAIL: ./log/$x"
  102. mkdir -vp $root/$logdir/$x
  103. chown 9:9 $root/$logdir/$x
  104. ln -vnfs $logdir/$x $servicedir/log/main/
  105. z="$z main/$x"
  106. y="`tail_read $tailfile log $x`"
  107. [ "$y" ] && echo "$y" > $root/$logdir/$x/config || true
  108. done
  109. cat <<-EOT > "$servicedir/log/run"
  110. #!/bin/sh
  111. exec 2>&1
  112. exec setuidgid log svlogd -t $z
  113. EOT
  114. chmod +x "$servicedir/log/run"
  115. fi
  116. ;;
  117. *)
  118. abort "tail_install: unknown style '$style' for $tailfile."
  119. ;;
  120. esac
  121. }