source: trunk/insertphp.sh @ 164

Last change on this file since 164 was 146, checked in by pinsard, 12 years ago

xmlstarlet vs xml

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