source: trunk/insertphp.sh @ 140

Last change on this file since 140 was 116, checked in by pinsard, 13 years ago

Consolidation of shell scripts

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