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 | # |
---|
25 | irodsUserName=rods |
---|
26 | irodsHost=emmy9.casa.umass.edu |
---|
27 | irodsPort=1247 |
---|
28 | irodsZone=geniRenci |
---|
29 | export 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 |
---|
34 | IPUT=iput |
---|
35 | |
---|
36 | echo "OML HOOK READY" |
---|
37 | while read COMMAND ARGUMENTS; do |
---|
38 | echo "`date` '${COMMAND}' '${ARGUMENTS}'" >> /tmp/oml2-server-hook.log |
---|
39 | case "${COMMAND}" in |
---|
40 | "DBCLOSED") |
---|
41 | case "${ARGUMENTS}" in |
---|
42 | file:*) |
---|
43 | DBFILE=${ARGUMENTS/file:/} |
---|
44 | echo ${IPUT} ${OPTION} ${DBFILE} >> /tmp/oml2-server-hook.log |
---|
45 | FILENAME=`echo $DBFILE | awk -F"/" '{print $5}'` |
---|
46 | SLICE=`echo $FILENAME | awk -F"-" '{print $1}'` |
---|
47 | EXP=`echo $FILENAME | awk -F"-" '{print $2}'` |
---|
48 | EXP=`echo $EXP | awk -F"." '{print $1}'` |
---|
49 | DATE=`date` |
---|
50 | echo "b db ${DBFILE} closed, pushing to iRODS..." >> /tmp/oml2-server-hook.log |
---|
51 | |
---|
52 | if [[ $SLICE =~ ^gimi[0-40] ]]; then |
---|
53 | echo "Entered iput and imeta phase" >> /tmp/oml2-server-hook.log |
---|
54 | iput -f ${DBFILE} /geniRenci/home/$SLICE/$FILENAME |
---|
55 | ichmod -M own $SLICE /geniRenci/home/$SLICE/$FILENAME |
---|
56 | imeta add -d /geniRenci/home/$SLICE/$FILENAME Date ${DATE} |
---|
57 | imeta add -d /geniRenci/home/$SLICE/$FILENAME SliceName ${SLICE} |
---|
58 | imeta add -d /geniRenci/home/$SLICE/$FILENAME ExpName ${EXP} |
---|
59 | |
---|
60 | fi |
---|
61 | echo "a iRODS operation finished" >> /tmp/oml2-server-hook.log |
---|
62 | ;; |
---|
63 | *) |
---|
64 | echo "db ${ARGUMENTS} closed, but don't know how to handle it..." >&2 |
---|
65 | ;; |
---|
66 | esac |
---|
67 | ;; |
---|
68 | "EXIT") |
---|
69 | echo "exiting..." >&2 |
---|
70 | exit 0 |
---|
71 | ;; |
---|
72 | *) |
---|
73 | ;; |
---|
74 | esac |
---|
75 | done |
---|