GIMIv1.0Tutorial: oml2-server-hook.sh

File oml2-server-hook.sh, 3.1 KB (added by zink@cs.umass.edu, 12 years ago)
Line 
1#!/bin/bash
2#
3# Example event hook for the OML server, copying an Sqlite database elsewhere
4# when the last client has exited.
5# Copyright 2012 National ICT Australia (NICTA), Australia
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25irodsUserName=rods
26irodsHost=emmy8.casa.umass.edu
27irodsPort=1247
28irodsZone=geniRenci
29export irodsUserName irodsHost irodsPort irodsZone
30
31# XXX: You might need to initialise the iRODS password for the UNIX user
32# running tho oml2-server by running 'iinit' to create ~/.irods/.irodsA on its
33# behalf for iput to work
34IPUT=iput
35OPTION=-f
36echo "OML HOOK READY"
37while read COMMAND ARGUMENTS; do
38        echo "`date` '${COMMAND}' '${ARGUMENTS}'" >> oml2-server-hook.log
39        case "${COMMAND}" in
40                "DBCLOSED")
41                        case "${ARGUMENTS}" in
42                                file:*)
43                                        DBFILE=${ARGUMENTS/file:/}
44                                        echo "db ${DBFILE} closed, pushing to iRODS..." >&2
45                                        echo ${IPUT} ${OPTION} ${DBFILE}
46                                        NAME=${DBFILE:12:6};
47                                        FILE=${DBFILE:12};
48                                        LENGTH=${#FILE}
49                                        SLICE=${FILE:0:$LENGTH-4}
50                                        DATE=`date`
51                                        ${IPUT} ${OPTION}  ${DBFILE}
52                                          if [[ $NAME =~ ^gimi[0-9] ]]; then
53                                             echo "Entered..."
54                                            ichmod -M own $NAME /geniRenci/home/$NAME/$FILE
55                                            iput -f ${DBFILE} /geniRenci/home/$NAME/$FILE;
56                                            imeta add -d /geniRenci/home/$NAME/$FILE Date ${DATE}
57                                            imeta add -d /geniRenci/home/$NAME/$FILE UserName $NAME
58                                            imeta add -d /geniRenci/home/$NAME/$FILE SliceName $SLICE
59 
60                                          fi
61                                       ;;
62                                *)
63                                        echo "db ${ARGUMENTS} closed, but don't know how to handle it..." >&2
64                                        ;;
65                        esac
66                        ;;
67                "EXIT")
68                        echo "exiting..." >&2
69                        exit 0
70                        ;;
71                *)
72                        ;;
73        esac
74done