source: trunk/insertphp.sh

Last change on this file was 353, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo

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