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 | #- |
---|
79 | system=$(uname) |
---|
80 | case "${system}" in |
---|
81 | AIX|IRIX64) |
---|
82 | echo " www : no specific posix checking" |
---|
83 | ;; |
---|
84 | Darwin) |
---|
85 | ;; |
---|
86 | *) |
---|
87 | set -o posix |
---|
88 | ;; |
---|
89 | esac |
---|
90 | unset system |
---|
91 | # |
---|
92 | set -u |
---|
93 | command=$(basename ${0}) |
---|
94 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
95 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
96 | # |
---|
97 | tool=${xmlcmd} |
---|
98 | type ${tool} 1> /dev/null 2>&1 |
---|
99 | status=${?} |
---|
100 | if [ ${status} -ne 0 ] |
---|
101 | then |
---|
102 | echo "${command} : eee : tool ${tool} not found" |
---|
103 | exit 1 |
---|
104 | fi |
---|
105 | # |
---|
106 | unset status |
---|
107 | unset tool |
---|
108 | # |
---|
109 | usage=" Usage : ${command} -i filein -o fileout -s sedfile -d depth" |
---|
110 | # |
---|
111 | minargcount=8 |
---|
112 | #echo " narg ${#}" |
---|
113 | if [ ${#} -lt ${minargcount} ] |
---|
114 | then |
---|
115 | echo "eee : not enough arguments" |
---|
116 | echo "${usage}" |
---|
117 | exit 1 |
---|
118 | fi |
---|
119 | unset minargcount |
---|
120 | # |
---|
121 | while [ ${#} -gt 0 ] |
---|
122 | do |
---|
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 |
---|
149 | done |
---|
150 | unset usage |
---|
151 | # |
---|
152 | # check for filein |
---|
153 | if [ ! -f ${filein} ] |
---|
154 | then |
---|
155 | echo "eee : ${filein} not found" |
---|
156 | exit 1 |
---|
157 | fi |
---|
158 | # |
---|
159 | # check for sedfile |
---|
160 | if [ ! -f ${sedfile} ] |
---|
161 | then |
---|
162 | echo "eee : ${sedfile} not found" |
---|
163 | exit 1 |
---|
164 | fi |
---|
165 | # |
---|
166 | # check for depth |
---|
167 | if [ ${depth} -lt 0 ] |
---|
168 | then |
---|
169 | echo "eee : ${depth} must be greater than 0" |
---|
170 | exit 1 |
---|
171 | fi |
---|
172 | # ++ check for fileout ++ overwrite |
---|
173 | # |
---|
174 | # check for main.xml ++ path |
---|
175 | if [ ! -f ./main.xml ] |
---|
176 | then |
---|
177 | echo "eee : ./main.xml not found" |
---|
178 | exit 1 |
---|
179 | fi |
---|
180 | # |
---|
181 | # get title from main.xml |
---|
182 | title=$(${xmlcmd} sel -N d="http://docbook.org/ns/docbook" -t -m "/d:article/d:title/node()" -c . main.xml) |
---|
183 | # |
---|
184 | dirphp="./" |
---|
185 | idepth=1 |
---|
186 | while [ ${idepth} -le ${depth} ] |
---|
187 | do |
---|
188 | dirphp=${dirphp}"../" |
---|
189 | idepth=$((${idepth} + 1)) |
---|
190 | done |
---|
191 | sed -f ${sedfile} \ |
---|
192 | -e "s@${title}@${title} <?php include(\"${dirphp}php/timestamp.php\"); ?>@" \ |
---|
193 | ${filein} > ${fileout} |
---|
194 | # end |
---|
195 | exit 0 |
---|