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