source: trunk/geomag_profile.sh

Last change on this file was 48, checked in by pinsard, 10 years ago

fix thanks to coding rules

  • Property svn:executable set to *
  • Property svn:keyword set to Id
File size: 7.4 KB
Line 
1#! /bin/sh
2#
3#+
4# .. _geomag_profile.sh:
5#
6# =================
7# geomag_profile.sh
8# =================
9#
10# -------------------------
11# define GEOMAG environment
12# -------------------------
13#
14# SYNOPSIS
15# ========
16#
17# Online usage
18#
19# .. code-block:: bash
20#
21#    . geomag_profile.sh -d directory -i indir -o outdir -t tempdir
22#
23# In :file:`${HOME}/.profile`, add the following line:
24#
25# .. code-block:: bash
26#
27#    . geomag_profile.sh -d directory -i indir -o outdir -t tempdir
28#
29# DESCRIPTION
30# ===========
31#
32# .. option:: -d <directory>
33# .. option:: -i <indir>
34# .. option:: -o <outdir>
35# .. option:: -t <tempdir>
36#
37# define GEOMAG environment
38#
39# ${GEOMAG} is the base directory of tools.
40#
41# ${GEOMAG_LOG} is the directory where log files will be written.
42#
43# ${GEOMAG_ID} is the directory where input files must be.
44#
45# ${GEOMAG_OD} is the directory where output files will be written.
46#
47# MANPATH++
48#
49# EXAMPLES
50# ========
51#
52# For fplod, on aedon.locean-ipsl.upmc.fr:
53#
54# .. code-block:: bash
55#
56#    cd /usr/home/fplod/incas/geomag/geomag_ws
57#    . geomag_profile.sh -d /usr/home/fplod/incas/geomag/geomag_ws/ -i ${HOME}/geomag_d/ -o ${HOME}/geomag_d/ -t /usr/temp/${LOGNAME}/log/
58#
59# For reee522 on rhodes.idris.fr:
60#
61# .. code-block:: bash
62#
63#    cd ${HOME}/incas/geomag/geomag_ws/
64#    . geomag_profile.sh -d ${HOME}/incas/geomag/geomag_ws/ -i ${HOMEGAYA}/geomag_d/ -o ${HOMEGAYA}/geomag_d/ -t /tmp/${LOGNAME}/log/
65#
66# TODO
67# ====
68#
69# ++ option bavarde
70#
71# ++ machine dependant
72#
73# ++ besoin de posix
74#
75# ++ pas de MANPATH defini par défaut sur zeus
76#
77# EVOLUTIONS
78# ==========
79#
80# $Id$
81#
82# - fplod 20100426T094821Z aedon.locean-ipsl.upmc.fr (Darwin)
83#
84#   * improve PATH and MANPATH modification
85#
86# - fplod 20100423T143134Z aedon.locean-ipsl.upmc.fr (Darwin)
87#
88#   * add error handling on mkdir
89#
90# - fplod 20100318T073619Z aedon.locean-ipsl.upmc.fr (Darwin)
91#
92#   * unset
93#
94# - reee522 2007-06-14T14:25:00Z rhodes (IRIX64)
95#
96#   * add -i, -o and -t parameters to be more flexible
97#   * some bug fixes
98#   * more checking
99#
100# - fplod 2007-03-13T16:12:41Z zeus.locean-ipsl.upmc.fr (Linux)
101#
102#   * add creation of ${GEOMAG_ID} and ${GEOMAG_OD} if they don't exist
103#
104# - reee522 2006-11-23T11:41:41Z rhodes (IRIX64)
105#
106#   * pas de set -o posix sur rhodes (IRIX64)
107#
108# - fplod 2006-03-22T10:13:38Z aedon.lodyc.jussieu.fr (Darwin)
109#
110#   * creation
111#
112#-
113#
114command=geomag_profile.sh
115#
116usage=" Usage : ${command} -d directory -i indir -o outdir -t tempdir"
117#
118set -u
119pb=0
120#
121minargcount=8
122maxargcount=8
123narg=${#}
124#
125if [ ${narg} -lt ${minargcount} ]
126then
127    echo "eee : not enought arguments (${narg} vs ${minargcount})"
128    echo "${usage}"
129    # nb : no exit because this file should be launched by login process
130    pb=1
131fi
132unset minargcount
133#
134if [ ${narg} -gt ${maxargcount} ]
135then
136    echo "eee : too many arguments (${narg} vs ${maxargcount})"
137    echo "${usage}"
138    # nb : no exit because this file should be launched by login process
139    pb=1
140fi
141unset maxargcount
142unset narg
143#
144if [ ${pb} -eq 0 ]
145then
146    #
147    while [ ${#} -gt 0 ]
148    do
149       case ${1} in
150          -d)
151             # directory for application choosen by user
152             # (see svn checkout command used)
153             directory=${2}
154             shift
155          ;;
156          -i)
157             # directory for inputs choosen by user
158             indir=${2}
159             shift
160          ;;
161          -o)
162             # directory for outputs choosen by user
163             outdir=${2}
164             shift
165          ;;
166          -t)
167             # directory for temporary outputs choosen by user
168             tempdir=${2}
169             shift
170          ;;
171          *)
172             # other choice
173             echo "eee : unknown option ${1}"
174             echo "${usage}"
175             # nb : no exit because this file should be launched by login process
176          ;;
177       esac
178       # next flag
179       shift
180    done
181    unset usage
182fi
183if [ ${pb} -eq 0 ]
184then
185    #
186    # check for ${directory}
187    if [ ! -d ${directory} ]
188    then
189       echo " eee : ${directory} not found"
190       # nb : no exit because this file should be launched by login process
191    fi
192    #
193    # check for permission on directory
194    if [ ! -x ${directory} ]
195    then
196       echo " eee : ${directory} not reachable"
197       # nb : no exit because this file should be launched by login process
198    fi
199    #
200    system=$(uname)
201    case "${system}" in
202       IRIX64)
203          echo " www : no specific posix checking"
204       ;;
205       *)
206          set -o posix
207       ;;
208    esac
209    unset system
210    #
211    GEOMAG=${directory}
212    export GEOMAG
213    unset directory
214    #
215    # add GEOMAG tools to PATH
216    # if not already done
217    suppath=$(echo ${GEOMAG} | tr -s "/")
218    echo ${PATH} | grep -q "${suppath}:"
219    test_path=${?}
220    if [ ${test_path} -ne 0 ]
221    then
222       PATH=${suppath}:${PATH}
223       export PATH
224    else
225       # option bavarde oui/non pas encore implantée ++
226       echo "${command} : iii : ${suppath}/ already in \${PATH}"
227    fi
228    unset test_path
229    unset suppath
230    #
231    # add GEOMAG manuals to MANPATH
232    # if not already done
233    suppath=$(echo ${GEOMAG}/doc/manuals/man/ | tr -s "/")
234    echo ${MANPATH} | grep -q "${suppath}:"
235    test_manpath=${?}
236    if [ ${test_manpath} -ne 0 ]
237    then
238       MANPATH=${suppath}:${MANPATH}
239       export MANPATH
240    else
241       # option bavarde oui/non pas encore implantée ++
242       echo "${command} : iii : ${suppath} already in \${MANPATH}"
243    fi
244    unset test_manpath
245    unset suppath
246    #
247    GEOMAG_LOG=${tempdir}
248    export GEOMAG_LOG
249    unset tempdir
250    if [ ! -d ${GEOMAG_LOG} ]
251    then
252       mkdir -p ${GEOMAG_LOG}
253       status=${?}
254       if [ ${status} -ne 0 ]
255       then
256          echo "${command} : eee : can not create \${GEOMAG_LOG}"
257          # nb : no exit because this file should be launched by login process
258       else
259          echo "${command} : iii : creation of \${GEOMAG_LOG}"
260       fi
261       unset status
262    fi
263    # check for permission on GEOMAG_LOG
264    if [ ! -x ${GEOMAG_LOG} ]
265    then
266       echo " eee : ${GEOMAG_LOG} not reachable"
267       # nb : no exit because this file should be launched by login process
268    fi
269    #
270    # check for permission on GEOMAG_LOG
271    if [ ! -w ${GEOMAG_LOG} ]
272    then
273       echo " eee : ${GEOMAG_LOG} not writable"
274       # nb : no exit because this file shouldreachable be launched
275       # by login process
276    fi
277    #
278    EDITOR=vi
279    export EDITOR
280    #
281    # io directories
282    GEOMAG_ID=${indir}
283    export GEOMAG_ID
284    unset indir
285    if [ ! -d ${GEOMAG_ID} ]
286    then
287       mkdir -p ${GEOMAG_ID}
288       echo "${command} : iii : creation of \${GEOMAG_ID}"
289    fi
290    # check for permission on GEOMAG_ID
291    if [ ! -x ${GEOMAG_ID} ]
292    then
293       echo " eee : ${GEOMAG_ID} not reachable"
294       # nb : no exit because this file should be launched by login process
295    fi
296    #
297    GEOMAG_OD=${outdir}
298    export GEOMAG_OD
299    unset outdir
300    if [ ! -d ${GEOMAG_OD} ]
301    then
302       mkdir -p ${GEOMAG_OD}
303       echo "${command} : iii : creation of \${GEOMAG_OD}"
304    fi
305    # check for permission on GEOMAG_OD
306    if [ ! -x ${GEOMAG_OD} ]
307    then
308       echo " eee : ${GEOMAG_OD} not reachable"
309       # nb : no exit because this file should be launched by login process
310    fi
311    if [ ! -w ${GEOMAG_OD} ]
312    then
313       echo " eee : ${GEOMAG_OD} not writable"
314       # nb : no exit because this file should be launched by login process
315    fi
316    #
317fi
318unset pb
319# end
320unset command
321# nb : no exit because this file should be launched by login process
Note: See TracBrowser for help on using the repository browser.