[76] | 1 | #! /bin/sh |
---|
| 2 | #+ |
---|
[80] | 3 | # |
---|
[109] | 4 | # .. program:: insertphp.sh |
---|
[103] | 5 | # |
---|
[95] | 6 | # ============ |
---|
| 7 | # insertphp.sh |
---|
| 8 | # ============ |
---|
[76] | 9 | # |
---|
[95] | 10 | # ----------------------------------------------- |
---|
| 11 | # ajoute des commandes php dans des fichiers html |
---|
| 12 | # ----------------------------------------------- |
---|
[76] | 13 | # |
---|
[93] | 14 | # SYNOPSIS |
---|
[76] | 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 | # |
---|
[108] | 28 | # .. option:: -i <input file> |
---|
| 29 | # .. option:: -o <output file> |
---|
| 30 | # .. option:: -s <sedfile> |
---|
| 31 | # .. option:: -d <depth> |
---|
[76] | 32 | # |
---|
| 33 | # EXAMPLES |
---|
| 34 | # ======== |
---|
| 35 | # |
---|
[100] | 36 | # To do the job on "one" branch:: |
---|
[76] | 37 | # |
---|
| 38 | # $ ./insertphp.sh -i template_beforesed.php -o ./template_one.php -d 2 -s insertphp_one.sed |
---|
| 39 | # |
---|
[100] | 40 | # To check:: |
---|
[76] | 41 | # |
---|
[100] | 42 | # $ diff template_beforesed.php template.php |
---|
[76] | 43 | # |
---|
| 44 | # |
---|
[100] | 45 | # To do the job on "many" branch:: |
---|
[76] | 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 | # ========== |
---|
[101] | 53 | # |
---|
[76] | 54 | # $Id$ |
---|
[101] | 55 | # |
---|
[76] | 56 | # - fplod 2008-09-18T08:55:50Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 57 | # |
---|
[101] | 58 | # * add -d and -d option to perform one and many transformation |
---|
[76] | 59 | # with the same shell script |
---|
[101] | 60 | # |
---|
[76] | 61 | # - fplod 2008-09-17T15:12:32Z aedon.locean-ipsl.upmc.fr (Darwin) |
---|
| 62 | # |
---|
[101] | 63 | # * creation to encapsulate insertphp_one.sed usage and use |
---|
[76] | 64 | # main.xml title |
---|
[80] | 65 | # |
---|
[76] | 66 | #- |
---|
| 67 | system=$(uname) |
---|
| 68 | case "${system}" in |
---|
[100] | 69 | AIX|IRIX64) |
---|
| 70 | echo " www : no specific posix checking" |
---|
| 71 | ;; |
---|
| 72 | *) |
---|
| 73 | set -o posix |
---|
| 74 | ;; |
---|
[76] | 75 | esac |
---|
[100] | 76 | unset system |
---|
| 77 | # |
---|
[76] | 78 | command=$(basename ${0}) |
---|
[93] | 79 | log_date=$(date -u +"%Y%m%dT%H%M%SZ") |
---|
| 80 | log=/tmp/$(basename ${command} .sh).log.${log_date} |
---|
[76] | 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 |
---|
[100] | 88 | echo " eee : ${tool} not found" |
---|
| 89 | exit 1 |
---|
[76] | 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 | # |
---|
[102] | 106 | set +u |
---|
[76] | 107 | while [ ! -z "${1}" ] |
---|
| 108 | do |
---|
[100] | 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 | ;; |
---|
[101] | 126 | *) |
---|
| 127 | # other choice |
---|
[100] | 128 | echo "eee : unknown option ${1}" |
---|
| 129 | echo "${usage}" |
---|
| 130 | exit 1 |
---|
| 131 | ;; |
---|
| 132 | esac |
---|
[101] | 133 | # next flag |
---|
| 134 | shift |
---|
[76] | 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 ] |
---|
[101] | 156 | then |
---|
[76] | 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 |
---|
[100] | 176 | dirphp=${dirphp}"../" |
---|
| 177 | idepth=$((${idepth} + 1)) |
---|
[76] | 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 |
---|