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 | #- |
---|
67 | system=$(uname) |
---|
68 | case "${system}" in |
---|
69 | AIX|IRIX64) |
---|
70 | echo " www : no specific posix checking" |
---|
71 | ;; |
---|
72 | *) |
---|
73 | set -o posix |
---|
74 | ;; |
---|
75 | esac |
---|
76 | unset system |
---|
77 | # |
---|
78 | command=$(basename ${0}) |
---|
79 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
80 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
81 | # |
---|
82 | # test if xml is available |
---|
83 | tool=xml |
---|
84 | type ${tool} 1> /dev/null 2>&1 |
---|
85 | status=${?} |
---|
86 | if [ ${status} -ne 0 ] |
---|
87 | then |
---|
88 | echo " eee : ${tool} not found" |
---|
89 | exit 1 |
---|
90 | fi |
---|
91 | unset status |
---|
92 | unset tool |
---|
93 | # |
---|
94 | usage=" Usage : ${command} -i filein -o fileout -s sedfile -d depth" |
---|
95 | # |
---|
96 | minargcount=8 |
---|
97 | #echo " narg ${#}" |
---|
98 | if [ ${#} -lt ${minargcount} ] |
---|
99 | then |
---|
100 | echo "eee : not enought arguments" |
---|
101 | echo "${usage}" |
---|
102 | exit 1 |
---|
103 | fi |
---|
104 | unset minargcount |
---|
105 | # |
---|
106 | set +u |
---|
107 | while [ ! -z "${1}" ] |
---|
108 | do |
---|
109 | case ${1} in |
---|
110 | -i) |
---|
111 | filein=${2} |
---|
112 | shift |
---|
113 | ;; |
---|
114 | -o) |
---|
115 | fileout=${2} |
---|
116 | shift |
---|
117 | ;; |
---|
118 | -s) |
---|
119 | sedfile=${2} |
---|
120 | shift |
---|
121 | ;; |
---|
122 | -d) |
---|
123 | depth=${2} |
---|
124 | shift |
---|
125 | ;; |
---|
126 | *) |
---|
127 | # other choice |
---|
128 | echo "eee : unknown option ${1}" |
---|
129 | echo "${usage}" |
---|
130 | exit 1 |
---|
131 | ;; |
---|
132 | esac |
---|
133 | # next flag |
---|
134 | shift |
---|
135 | done |
---|
136 | unset usage |
---|
137 | # |
---|
138 | set -u |
---|
139 | # |
---|
140 | # check for filein |
---|
141 | if [ ! -f ${filein} ] |
---|
142 | then |
---|
143 | echo "eee : ${filein} not found" |
---|
144 | exit 1 |
---|
145 | fi |
---|
146 | # |
---|
147 | # check for sedfile |
---|
148 | if [ ! -f ${sedfile} ] |
---|
149 | then |
---|
150 | echo "eee : ${sedfile} not found" |
---|
151 | exit 1 |
---|
152 | fi |
---|
153 | # |
---|
154 | # check for depth |
---|
155 | if [ ${depth} -lt 0 ] |
---|
156 | then |
---|
157 | echo "eee : ${depth} must be greater than 0" |
---|
158 | exit 1 |
---|
159 | fi |
---|
160 | # ++ check for fileout ++ overwrite |
---|
161 | # |
---|
162 | # check for main.xml ++ path |
---|
163 | if [ ! -f ./main.xml ] |
---|
164 | then |
---|
165 | echo "eee : ./main.xml not found" |
---|
166 | exit 1 |
---|
167 | fi |
---|
168 | # |
---|
169 | # get title from main.xml |
---|
170 | title=$(xml sel -N d="http://docbook.org/ns/docbook" -t -m "/d:article/d:title/node()" -c . main.xml) |
---|
171 | # |
---|
172 | dirphp="./" |
---|
173 | idepth=1 |
---|
174 | while [ ${idepth} -le ${depth} ] |
---|
175 | do |
---|
176 | dirphp=${dirphp}"../" |
---|
177 | idepth=$((${idepth} + 1)) |
---|
178 | done |
---|
179 | sed -f ${sedfile} \ |
---|
180 | -e "s@${title}@${title} <?php include(\"${dirphp}php/timestamp.php\"); ?>@" \ |
---|
181 | ${filein} > ${fileout} |
---|
182 | # end |
---|
183 | exit 0 |
---|