source: trunk/src/project_profile.sh

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

fix thanks to coding rules and pep8; typo; dupe empty lines

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