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