source: trunk/insertphp.sh @ 101

Last change on this file since 101 was 101, checked in by pinsard, 14 years ago

improve environnement definition

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1#! /bin/sh
2#+
3#
4# ============
5# insertphp.sh
6# ============
7#
8# -----------------------------------------------
9# ajoute des commandes php dans des fichiers html
10# -----------------------------------------------
11#
12# SYNOPSIS
13# ========
14#
15# ::
16#
17#  $ insertphp.sh -i filein -o fileout -s sedfile -d depth
18#
19#
20# DESCRIPTION
21# ===========
22#
23# ajoute des commandes php dans des fichiers html
24# en fonction d'info dans main.xml
25#
26# -i  input file
27# -o  output file
28# -s  sedfile
29# -d  depth
30#
31# EXAMPLES
32# ========
33#
34# To do the job on "one" branch::
35#
36#  $ ./insertphp.sh -i template_beforesed.php -o ./template_one.php -d 2 -s insertphp_one.sed
37#
38# To check::
39#
40#  $ diff template_beforesed.php template.php
41#
42#
43# To do the job on "many" branch::
44#
45#  $ ./insertphp.sh -i template_beforesed.php -o ./template_many.php -d 3 -s insertphp_many.sed
46#
47# see makefile
48#
49# EVOLUTIONS
50# ==========
51#
52# $Id$
53#
54# - fplod 2008-09-18T08:55:50Z aedon.locean-ipsl.upmc.fr (Darwin)
55#
56#   * add -d and -d option to perform one and many transformation
57#     with the same shell script
58#
59# - fplod 2008-09-17T15:12:32Z aedon.locean-ipsl.upmc.fr (Darwin)
60#
61#   * creation to encapsulate insertphp_one.sed usage and use
62#     main.xml title
63#
64#-
65system=$(uname)
66case "${system}" in
67   AIX|IRIX64)
68      echo " www : no specific posix checking"
69   ;;
70   *)
71     set -o posix
72   ;;
73esac
74unset system
75#
76command=$(basename ${0})
77log_date=$(date -u +"%Y%m%dT%H%M%SZ")
78log=/tmp/$(basename ${command} .sh).log.${log_date}
79#
80# test if xml is available
81tool=xml
82type ${tool} 1> /dev/null 2>&1
83status=${?}
84if [ ${status} -ne 0 ]
85then
86   echo " eee : ${tool} not found"
87   exit 1
88fi
89unset status
90unset tool
91#
92usage=" Usage : ${command} -i filein -o fileout -s sedfile -d depth"
93#
94minargcount=8
95#echo " narg ${#}"
96if [ ${#} -lt ${minargcount} ]
97then
98   echo "eee : not enought arguments"
99   echo "${usage}"
100   exit 1
101fi
102unset minargcount
103#
104while [ ! -z "${1}" ]
105do
106   case ${1} in
107      -i)
108         filein=${2}
109         shift
110       ;;
111      -o)
112         fileout=${2}
113         shift
114      ;;
115      -s)
116         sedfile=${2}
117         shift
118      ;;
119      -d)
120         depth=${2}
121         shift
122      ;;
123      *)
124         # other choice
125         echo "eee : unknown option ${1}"
126         echo "${usage}"
127         exit 1
128      ;;
129   esac
130   # next flag
131   shift
132done
133unset usage
134#
135set -u
136#
137# check for filein
138if [ ! -f ${filein} ]
139then
140   echo "eee : ${filein} not found"
141   exit 1
142fi
143#
144# check for sedfile
145if [ ! -f ${sedfile} ]
146then
147   echo "eee : ${sedfile} not found"
148   exit 1
149fi
150#
151# check for depth
152if [ ${depth} -lt 0 ]
153then
154   echo "eee : ${depth} must be greater than 0"
155   exit 1
156fi
157# ++ check for fileout ++ overwrite
158#
159# check for main.xml  ++ path
160if [ ! -f ./main.xml ]
161then
162   echo "eee : ./main.xml not found"
163   exit 1
164fi
165#
166# get title from main.xml
167title=$(xml sel -N d="http://docbook.org/ns/docbook" -t -m "/d:article/d:title/node()" -c . main.xml)
168#
169dirphp="./"
170idepth=1
171while [ ${idepth} -le ${depth} ]
172do
173   dirphp=${dirphp}"../"
174   idepth=$((${idepth} + 1))
175done
176sed -f ${sedfile} \
177   -e "s@${title}@${title} <?php include(\"${dirphp}php/timestamp.php\"); ?>@" \
178   ${filein} > ${fileout}
179# end
180exit 0
Note: See TracBrowser for help on using the repository browser.