source: trunk/src/ircaam_profile.sh @ 91

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

fix thanks to coding rules

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