source: trunk/project_profile.sh @ 352

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

fix thanks to coding rules; typo

  • Property svn:executable set to *
  • Property svn:keywords set to Id URL
File size: 8.6 KB
Line 
1#! /bin/sh
2#+
3#
4# .. program:: project_profile.sh
5#
6# ===================
7# project_profile.sh
8# ===================
9#
10#
11# SYNOPSIS
12# ========
13#
14# On line usage:
15#
16# .. code-block:: sh
17#
18#  ./project_profile.sh -d directory -i indir -o outdir -t tempdir
19#
20# In :file:`${HOME}/.profile`, add the following line:
21#
22# .. code-block:: sh
23#
24#    . project_profile.sh -d directory  -i indir -o outdir -t tempdir
25#
26# DESCRIPTION
27# ===========
28#
29# .. option:: -d <directory>
30# .. option:: -i <indir>
31# .. option:: -o <outdir>
32# .. option:: -t <tempdir>
33# .. option:: -jv <jabref version>
34# .. option:: -j <jabref dir>
35#
36# define SUPERBIB 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# MANPATH++
47#
48# :envvar:`${xmlcmd}` is set to either xml or xmlstarlet if one of these
49# is available.
50#
51# EXAMPLES
52# ========
53#
54# For fplod, on cratos.locean-ipsl.upmc.fr:
55#
56# .. code-block:: bash
57#
58#    cd /usr/home/fplod/src/superbib/superbib_ws/
59#    SUPERBIB=${HOME}/superbib_ws/
60#    export SUPERBIB
61#    . ${SUPERBIB}/project_profile.sh \
62#    -d ${SUPERBIB} \
63#    -i /usr/temp/${LOGNAME}/superbib_d/ \
64#    -o /usr/temp/${LOGNAME}/superbib_d/ \
65#    -t /usr/temp/${LOGNAME}/log/ \
66#    -jv 2.6 \
67#    -j /usr/home/incas/francoise/jabref-2.6_cratos/
68#    -b ++
69#
70# TODO
71# ====
72#
73# ++ option bavarde
74#
75# ++ machine dependant
76#
77# ++ pas de MANPATH défini par défaut sur zeus
78#
79# réintégration de bibliolocean dans trunk ou projet bibliolocean à part
80#
81# doc sur jabref dir bibtool
82#
83# EVOLUTIONS
84# ==========
85#
86# $Id$
87#
88# $URL$
89#
90# - fplod 20131010T113730Z callisto.locean-ipsl.upmc.fr (Linux)
91#
92#   * dynamic xmlstarlet vs xml
93#
94# - fplod 20130418T110932Z cratos.locean-ipsl.upmc.fr (Linux)
95#
96#   * add PYTHONPATH (seems to be need be sphinx-apidoc + sphinx-build)
97#
98# - fplod 20120629T120311Z cratos (Linux)
99#
100#   * path with branches/bibliolocean/src
101#
102# - fplod 20120405T085555Z cratos (Linux)
103#
104#   * rename and replace SUPERBIB by PROJECT
105#
106# - fplod 20100426T094821Z aedon.locean-ipsl.upmc.fr (Darwin)
107#
108#   * improve PATH and MANPATH modification
109#
110# - fplod 20100423T144248Z aedon.locean-ipsl.upmc.fr (Darwin)
111#
112#   * add error handling on mkdir
113#
114# - fplod 2008-10-31T11:17:24Z aedon.locean-ipsl.upmc.fr (Darwin)
115#
116#   * creation ++ pas encore en service
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#
132# as this script might be launch in .profile, command is forced.
133command=project_profile.sh
134#
135usage=" Usage : ${command} -d directory -i indir -o outdir -t tempdir -jv jabrefversion -j jabrefdir -b bibtooldir"
136#
137while [ ${#} -gt 0 ]
138do
139    case ${1} in
140        -d)
141            # directory for application chosen by user
142            # (see svn checkout command used)
143            directory=${2}
144            shift
145        ;;
146        -i)
147            # directory for inputs chosen by user
148            indir=${2}
149            shift
150        ;;
151        -o)
152            # directory for outputs chosen by user
153            outdir=${2}
154            shift
155        ;;
156        -t)
157            # directory for temporary outputs chosen by user
158            tempdir=${2}
159            shift
160        ;;
161        -jv)
162            jabrefversion=${2}
163            shift
164        ;;
165        -j)
166            jabrefdir=${2}
167            shift
168        ;;
169        -b)
170            bibtooldir=${2}
171            shift
172        ;;
173        *)
174            # other choice
175            echo "eee : unknown option ${1}"
176            echo "${usage}"
177            # nb : no exit because this file should be launched by
178            # login process
179        ;;
180    esac
181    # next flag
182    shift
183done
184unset usage
185#
186# check for ${directory}
187if [ ! -d ${directory} ]
188then
189    echo " eee : ${directory} not found"
190    # nb : no exit because this file should be launched by login process
191fi
192#
193# check for permission on directory
194if [ ! -x ${directory} ]
195then
196    echo " eee : ${directory} not reachable"
197    # nb : no exit because this file should be launched by login process
198fi
199#
200PROJECT=${directory}
201export PROJECT
202#
203# add PROJECT tools to PATH
204# if not already done
205suppath=$(echo ${PROJECT} | tr -s "/")
206echo ${PATH} | grep -q "${suppath}:"
207test_path=${?}
208if [ ${test_path} -ne 0 ]
209then
210    PATH=${suppath}:${PATH}
211    export PATH
212else
213    # option bavarde oui/non pas encore implantée ++
214    echo "${command} : iii : ${suppath} already in \${PATH}"
215fi
216unset test_path
217unset suppath
218#
219suppath=$(echo ${PROJECT}/../branches/bibliolocean/src | tr -s "/")
220echo ${PATH} | grep -q "${suppath}:"
221test_path=${?}
222if [ ${test_path} -ne 0 ]
223then
224    PATH=${suppath}:${PATH}
225    export PATH
226else
227    # option bavarde oui/non pas encore implantée ++
228    echo "${command} : iii : ${suppath} already in \${PATH}"
229fi
230unset test_path
231#
232# add PROJECT tools to PYTHONPATH
233# if not already done
234suppath=$(echo ${PROJECT}/aeres/scripts/ | tr -s "/")
235echo ${PYTHONPATH} | grep -q "${suppath}:"
236test_path=${?}
237if [ ${test_path} -ne 0 ]
238then
239    PYTHONPATH=${suppath}:${PYTHONPATH}
240    export PYTHONPATH
241else
242    # option bavarde oui/non pas encore implantée ++
243    echo "${command} : iii : ${suppath} already in \${PYTHONPATH}"
244fi
245unset test_path
246unset suppath
247#
248# add PROJECT tools to PYTHONPATH
249# if not already done
250suppath=$(echo ${PROJECT}/| tr -s "/")
251echo ${PYTHONPATH} | grep -q "${suppath}:"
252test_path=${?}
253if [ ${test_path} -ne 0 ]
254then
255    PYTHONPATH=${suppath}:${PYTHONPATH}
256    export PYTHONPATH
257else
258    # option bavarde oui/non pas encore implantée ++
259    echo "${command} : iii : ${suppath} already in \${PYTHONPATH}"
260fi
261unset test_path
262unset suppath
263#
264# add PROJECT manuals to MANPATH
265# if not already done
266suppath=$(echo ${PROJECT}/doc/manuals/man | tr -s "/")
267echo ${MANPATH} | grep -q "${suppath}:"
268test_manpath=${?}
269if [ ${test_manpath} -ne 0 ]
270then
271    MANPATH=${suppath}:${MANPATH}
272    export MANPATH
273else
274    # option bavarde oui/non pas encore implantée ++
275    echo "${command} : iii : ${suppath} already in \${MANPATH}"
276fi
277unset test_manpath
278unset suppath
279#
280PROJECT_LOG=${tempdir}
281export PROJECT_LOG
282unset tempdir
283if [ ! -d ${PROJECT_LOG} ]
284then
285    mkdir -p ${PROJECT_LOG}
286    status=${?}
287    if [ ${status} -ne 0 ]
288    then
289        echo "${command} : eee : can not create \${PROJECT_LOG}"
290        # nb : no exit because this file should be launched by login process
291    else
292        echo "${command} : iii : creation of \${PROJECT_LOG}"
293    fi
294    unset status
295fi
296# check for permission on PROJECT_LOG
297if [ ! -x ${PROJECT_LOG} ]
298then
299    echo " eee : ${PROJECT_LOG} not reachable"
300    # nb : no exit because this file should be launched by login process
301fi
302#
303# check for permission on PROJECT_LOG
304if [ ! -w ${PROJECT_LOG} ]
305then
306    echo " eee : ${PROJECT_LOG} not writable"
307    # nb : no exit because this file shouldreachable be launched
308    # by login process
309fi
310#
311EDITOR=vi
312export EDITOR
313#
314# io directories
315PROJECT_ID=${indir}
316export PROJECT_ID
317unset indir
318if [ ! -d ${PROJECT_ID} ]
319then
320    mkdir -p ${PROJECT_ID}
321    echo "${command} : iii : creation of \${PROJECT_ID}"
322fi
323# check for permission on PROJECT_ID
324if [ ! -x ${PROJECT_ID} ]
325then
326    echo " eee : ${PROJECT_ID} not reachable"
327    # nb : no exit because this file should be launched by login process
328fi
329#
330PROJECT_OD=${outdir}
331export PROJECT_OD
332unset outdir
333if [ ! -d ${PROJECT_OD} ]
334then
335    mkdir -p ${PROJECT_OD}
336    echo "${command} : iii : creation of \${PROJECT_OD}"
337fi
338# check for permission on PROJECT_OD
339if [ ! -x ${PROJECT_OD} ]
340then
341    echo " eee : ${PROJECT_OD} not reachable"
342    # nb : no exit because this file should be launched by login process
343fi
344if [ ! -w ${PROJECT_OD} ]
345then
346    echo " eee : ${PROJECT_OD} not writable"
347    # nb : no exit because this file should be launched by login process
348fi
349#
350JABREF_DIR=${jabrefdir}
351export JABREF_DIR
352unset jabref_dir
353JABREF_VERSION=${jabrefversion}
354export JABREF_VERSION
355unset jabrefversion
356#
357BIBTOOL_DIR=${bibtooldir}
358export BIBTOOL_DIR
359unset bibtooldir
360PATH=${BIBTOOL_DIR}:${PATH}
361export PATH
362#
363# test if which xml is available xml or xmlstarlet
364tool=xml
365type ${tool} 1> /dev/null 2>&1
366status=${?}
367if [ ${status} -ne 0 ]
368then
369    #echo "${command} : www : tool ${tool} not found"
370    tool=xmlstarlet
371    type ${tool} 1> /dev/null 2>&1
372    status=${?}
373    if [ ${status} -ne 0 ]
374    then
375        echo "${command} : eee : tool ${tool} not found"
376    else
377        xmlcmd=xmlstarlet
378    fi
379else
380    xmlcmd=xml
381fi
382export xmlcmd
383#
384unset status
385unset tool
386
387# end
388unset command
389# nb : no exit because this file should be launched by login process
Note: See TracBrowser for help on using the repository browser.