source: trunk/install.sh @ 102

Last change on this file since 102 was 102, checked in by pinsard, 14 years ago

improve shell scripts robustness

  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1#!/bin/sh
2#+
3#
4# ==========
5# install.sh
6# ==========
7#
8# ----------------------------------------------
9# publication of HTML files and associated files
10# ----------------------------------------------
11#
12# SYNOPSIS
13# ========
14#
15# ::
16#
17#  $ install.sh -w dirwww -p dirpublish -u urlpublish -l login
18#
19# DESCRIPTION
20# ===========
21#
22# publication (rsync) of dirwww content on dirpublish given in argument
23#
24# If the host of publication is cerbere.locean-ipsl.upmc.fr, a specific update
25# is launched.
26#
27# -w  input directort
28# -p  output directory
29# -u  output url
30# -l  login used to access on output url
31#
32# If needed, existing directories might be removed before (to erase obsolete
33# files), using ncftp tool :
34#
35# For example, to clean directory on LOCEAN web server ::
36#
37#  $ ncftp -u fplod www.locean-ipsl.upmc.fr
38#  ncftp> cd fplod
39#  ncftp> rm -f pageperso/.DS_Store
40#  ncftp> rm -rf pageperso
41#  ncftp> exit
42#
43# EXAMPLES
44# ========
45#
46# EVOLUTIONS
47# ==========
48#
49# $Id$
50#
51# - fplod 2008-09-16T15:24:26Z aedon.locean-ipsl.upmc.fr (Darwin)
52#
53#   * comments in ReStructured Text
54#
55# - fplod 2008-06-17T09:10:19Z aedon.locean-ipsl.upmc.fr (Darwin)
56#
57#   * add -l parameter only used in specific case at LOCEAN when user
58#     parameter of persoweb must be different tthan login (ex: acmo vs fplod)
59#   * replace http://www.lodyc.jussieu.fr/info_reseau/persoweb/?fastupdate=1&user=${user}" by
60#     http://intranet.locean-ipsl.upmc.fr/persoweb/?fastupdate=1&user=${user}
61#
62# - fplod 2008-03-28T10:26:58Z aedon.locean-ipsl.upmc.fr (Darwin)
63#
64#   * new personnal webpages policy at LOCEAN so new command and new parameter (-u)
65#
66# - fplod 2007-09-28T09:30:43Z aedon.locean-ipsl.upmc.fr (Darwin)
67#
68#   * parametrisation and translation
69#
70# - smasson 2007-06-07T16:43:42Z arete.locean-ipsl.upmc.fr (Darwin)
71#
72#   * can give the answer with input parameters
73#
74# - fplod 2007-04-26T11:51:42Z aedon.locean-ipsl.upmc.fr (Darwin)
75#
76#-
77system=$(uname)
78case "${system}" in
79   AIX|IRIX64)
80      echo " www : no specific posix checking"
81   ;;
82   *)
83      set -o posix
84   ;;
85esac
86unset system
87#
88command=$(basename ${0})
89log_date=$(date -u +"%Y%m%dT%H%M%SZ")
90log=/tmp/$(basename ${command} .sh).log.${log_date}
91#
92usage=" Usage : ${command} -w dirwww -p dirpublish -u urlpublish -l login"
93#
94minargcount=4
95#echo " narg ${#}"
96if [ ${#} -lt ${minargcount} ]
97then
98   echo "eee : not enought arguments"
99   echo "${usage}"
100   exit 1
101fi
102unset minargcount
103#
104# default
105dirpublish="none"
106urlpublish="none"
107login="none"
108#
109set +u
110while [ ! -z "${1}" ]
111do
112   case ${1} in
113      -w)
114         dirwww=${2}
115         shift
116      ;;
117      -p)
118         dirpublish=${2}
119         shift
120      ;;
121      -u)
122         urlpublish=${2}
123         shift
124      ;;
125      -l)
126         login=${2}
127         shift
128      ;;
129   esac
130   # next flag
131   shift
132done
133#
134set -u
135#
136# ++ check directories
137#
138answer=${1:-" "}
139case ${answer} in
140   y|Y|n|N)
141   ;;
142   *)
143      if [ "${dirpublish}" != "none" ]
144      then
145         echo "Do you want to install on ${dirpublish} (y|[n]) ?"
146         read answer
147      fi
148      if [ "${urlpublish}" != "none" ]
149      then
150         echo "Do you want to install on ${urlpublish} (y|[n]) ?"
151         read answer
152      fi
153   ;;
154esac
155#
156case  ${answer} in
157   y|Y)
158      if [ "${dirpublish}" != "none" ]
159      then
160         # copy of ${dirwww} on $dirpublish
161         echo "iii : update of ${dirpublish}"
162         rsync -av --exclude=".DS_Store" -e ssh ${dirwww}/ ${dirpublish}
163         # detect if in dirpublish following this pattern [USER@]HOST:SRC, HOST
164         # is cerbere.locean-ipsl.upmc.fr. If so, a specific update is launched
165         userhost=${dirpublish%%:*}
166         host=${userhost##*@}
167         if [ ${login} = "none" ]
168         then
169            user=${userhost%%@*}
170         else
171            user=${login}
172         fi
173         if [ "${host}" = "cerbere.locean-ipsl.upmc.fr" ]
174         then
175            wget -q "http://intranet.locean-ipsl.upmc.fr/persoweb/?fastupdate=1&user=${user}" -O /dev/null
176         fi
177      else
178         # urlpublish=http://www.locean-ipsl.upmc.fr/~ginette/produit
179         dirpublish=${urlpublish##*~}
180         cd ${dirwww}
181         #lftp -e "mirror -R . ${dirpublish};quit" -u ${LOGNAME} skyros.locean-ipsl.upmc.fr
182         lftp -e "mirror -R . ${dirpublish};quit" -u ${LOGNAME} www.locean-ipsl.upmc.fr
183         # pour acmo a la main ++
184         #++lftp -e 'mirror -R . acmo/nouveaux/;quit' -u fplod www.locean-ipsl.upmc.fr
185         # ++ log
186      fi
187   ;;
188   *)
189      echo "no update of ${dirpublish} or ${urlpublish}"
190   ;;
191esac
192#
193# normal exit
194exit 0
Note: See TracBrowser for help on using the repository browser.