File: files2dav.sh

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (311 lines) | stat: -rwxr-xr-x 8,048 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/sh
#
#  mkdemo.sh
#
#  $Id$
#
#  Creates a demo database
#  
#  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
#  project.
#  
#  Copyright (C) 1998-2012 OpenLink Software
#  
#  This project is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; only version 2 of the License, dated June 1991.
#  
#  This program is distributed in the hope that it will be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write to the Free Software Foundation, Inc.,
#  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#  
#  

# ----------------------------------------------------------------------
#  Fix issues with LOCALE
# ----------------------------------------------------------------------
LANG=C
LC_ALL=POSIX
export LANG LC_ALL



PORT=${PORT-1112}
HOST=${HOST-localhost}

DSN="$HOST:$PORT"
LOGFILE=mkdemo.output
DEMO=`pwd`
export DEMO LOGFILE
SILENT=${SILENT-0}

#==============================================================================
#  Standard functions
#==============================================================================

ECHO()
{
    echo "$*"		| tee -a $DEMO/$LOGFILE
}


RUN()
{
    echo "+ $*"		>> $DEMO/$LOGFILE	

    STATUS=1		
    if test $SILENT -eq 1
    then
	eval $*		>> $DEMO/$LOGFILE 2>/dev/null
    else
	eval $*		>> $DEMO/$LOGFILE 
    fi
    STATUS=$?
}


LINE()
{
    ECHO "====================================================================="
}


BREAK()
{
    ECHO ""
    ECHO "---------------------------------------------------------------------"
    ECHO ""
}


BANNER()
{
    ECHO ""
    LINE
    ECHO "=  $*"
    ECHO "= " `date`
    LINE
    ECHO ""
}


START_SERVER()
{
  timeout=60

  ECHO "Starting Virtuoso DEMO server ..."     
  virtuoso +wait 

  starth=`date | cut -f 2 -d :`
  starts=`date | cut -f 3 -d :|cut -f 1 -d " "`

  for i in $(seq 1 10) 
    do
      sleep 6
      if (netstat -an | grep "$PORT" | grep LISTEN > /dev/null) 
        then 
	  ECHO "Virtuoso server started"     
	  return 0
	fi
  done
	  ECHO "***WARNING: Could not start Virtuoso DEMO Server within $timeout seconds"
	  return 1
}

STOP_SERVER()
{
    RUN isql $DSN dba dba '"EXEC=raw_exit();"' VERBOSE=OFF PROMPT=OFF ERRORS=STDOUT
}


DO_COMMAND()
{
  command=$1
  uid=${2-dba}
  passwd=${3-dba}
  isql $DSN $uid $passwd ERRORS=stdout VERBOSE=OFF PROMPT=OFF "EXEC=$command" 	>> $DEMO/$LOGFILE
  if test $? -ne 0 
  then
    ECHO "***FAILED: $command"
  else
    ECHO "PASSED: $command"
  fi
}


CHECK_LOG()
{
    passed=`grep "PASSED:" $DEMO/$LOGFILE | wc -l`
    failed=`grep "\*\*\*.*FAILED:" $DEMO/$LOGFILE | wc -l`
    aborted=`grep "\*\*\*.*ABORTED:" $DEMO/$LOGFILE | wc -l`

    ECHO ""
    LINE
    ECHO "=  Checking log file $LOGFILE for statistics:"
    ECHO "="
    ECHO "=  Total number of tests PASSED  : $passed"
    ECHO "=  Total number of tests FAILED  : $failed"
    ECHO "=  Total number of tests ABORTED : $aborted"
    LINE
    ECHO ""

    if (expr $failed + $aborted \> 0 > /dev/null)
    then
       ECHO "*** Not all tests completed successfully"
       ECHO "*** Check the file $LOGFILE for more information"
    fi
}


LOAD_SQL()
{
  sql=$1
  uid=${2-dba}
  passwd=${3-dba}

  RUN isql $DSN $uid $passwd ERRORS=stdout VERBOSE=OFF PROMPT=OFF $sql
  if test $? -ne 0 
  then
    ECHO "***FAILED: LOAD $sql"
  else
    ECHO "PASSED: LOAD $sql"
  fi
}  


MAKE_WS()
{
#  DO_COMMAND "create user WS" dba dba
#  DO_COMMAND "user_set_qualifier('WS', 'WS')" dba dba
  DO_COMMAND "create user SOAP" dba dba
  DO_COMMAND "user_set_qualifier('SOAP', 'WS')" dba dba
 
  DO_COMMAND "grant select on Demo.demo.Customers     to SOAP" dba dba
  DO_COMMAND "grant select on Demo.demo.Orders        to SOAP" dba dba
  DO_COMMAND "grant select on Demo.demo.Order_Details to SOAP" dba dba
  DO_COMMAND "grant select on Demo.demo.Products      to SOAP" dba dba
  DO_COMMAND "grant select on Demo.demo.Categories    to SOAP" dba dba
}


LOAD_XML_DAV()
{
  doc_col_id=$1
  doc_col_parent=$2
  doc_col_name=$3
  doc_col_fs_path=$4
  _cvs_entries='CVS/Entries'

#  ECHO "CVS ENTRIES in " $HOME/docsrc$doc_col_fs_path$_cvs_entries
  doc_files=`cat $HOME/docsrc$doc_col_fs_path$_cvs_entries | grep '^[^D]' | cut -f 2 -d '/'`
#  ECHO "DOC FILES :" $doc_files
  TMP=/tmp/isql.$$

  ECHO "Building sql script for loading $doc_col_fs_path files"
  echo "insert into WS.WS.SYS_DAV_COL (col_id, col_name ,col_owner, col_group, col_parent, col_cr_time, col_mod_time, col_perms) values ($doc_col_id, '$doc_col_name', 1, 1, $doc_col_parent, now(), now(), '110100100');" > $TMP

  cd $HOME/docsrc/$doc_col_fs_path

  for filename in $doc_files 
    do
      echo "insert into WS.WS.SYS_DAV_RES (RES_OWNER,  RES_COL, RES_TYPE, RES_CR_TIME, RES_MOD_TIME, RES_PERMS, RES_ID, RES_NAME, RES_CONTENT) values (1, $doc_col_id, http_mime_type('$filename'), now(), now(), '110100100', WS.WS.getid ('R'), '$filename', file_to_string ('$HOME/docsrc$doc_col_fs_path$filename'));" >> $TMP
  done	

  LOAD_SQL $TMP dba dba
  rm $TMP

  cd $DEMO
}


LOAD_XML_DAV_SS()
{
  doc_col_id=$1
  doc_col_parent=$2
  doc_col_name=$3
  doc_col_fs_path=$4
  stylesheet=$5
  _cvs_entries='CVS/Entries'

#  ECHO "CVS ENTRIES in " $HOME/docsrc$doc_col_fs_path$_cvs_entries
  doc_files=`cat $HOME/docsrc$doc_col_fs_path$_cvs_entries | grep '^[^D]' | cut -f 2 -d '/'`
#  ECHO "DOC FILES :" $doc_files
  TMP=/tmp/isql.$$

  ECHO "Building sql script for loading $doc_col_fs_path files"
  echo "insert into WS.WS.SYS_DAV_COL (col_id, col_name ,col_owner, col_group, col_parent, col_cr_time, col_mod_time, col_perms) values ($doc_col_id, '$doc_col_name', 1, 1, $doc_col_parent, now(), now(), '110100100');" > $TMP

  cd $HOME/docsrc/$doc_col_fs_path

  for filename in $doc_files 
    do
      echo "WS.WS.INSERT_RES_XSLT (1, $doc_col_id, '$filename', http_mime_type ('$filename'), file_to_string ('$HOME/docsrc$doc_col_fs_path$filename', '$stylesheet'));" >> $TMP 
  done	

  LOAD_SQL $TMP dba dba
  rm $TMP

  cd $DEMO
}

XSL_TRANSFORM ()
{
  xml_src=$1
  xsl_stylesheet=$2
  dst=$3
  src_path=$4
  xsl_params=$5

  TMP=/tmp/isql.$$

  echo "SRC: $xml_src"
  echo "SRCPATH: $src_path"
  DO_COMMAND "WS.WS.XML_ENTITY_TO_FILE (xslt ('$xsl_stylesheet', \
                                        xtree_doc (file_to_string ('$xml_src'), 0, \
						   '$src_path'), \
				        vector ($xsl_params)), \
				  '$dst');"
}

DUMP_XML_ENTITY ()
{
  xml_src=$1
  src_path=$2
  dst=$3
  
  TMP=/tmp/isql.$$

  echo "SRC: $xml_src"
  echo "DST: $dst"
  echo "WS.WS.XML_ENTITY_TO_FILE (xtree_doc (file_to_string ('$xml_src'), 0,\
						    'src_path'), '$dst');" > $TMP

  LOAD_SQL $TMP dba $DBPWD
  rm $TMP


}

#==============================================================================
#  MAIN ROUTINE
#==============================================================================
LOAD_SQL $HOME/binsrc/samples/xpath/presetup.sql dba dba
LOAD_SQL $HOME/binsrc/samples/xpath/desk.sql dba dba
LOAD_SQL $HOME/binsrc/samples/xpath/metadata.sql dba dba


DO_COMMAND "delete from WS.WS.SYS_DAV_COL where col_id=120" dba dba
DO_COMMAND "insert into WS.WS.SYS_DAV_COL (col_id, col_name ,col_owner, col_group, col_parent, col_cr_time, col_mod_time, col_perms) values (120, 'xpdemo', 1, 1, 1, now(), now(), '110100100')" dba dba 
files=`ls $HOME/binsrc/samples/xpath/data`
for i in $files
do
   DO_COMMAND     "insert into WS.WS.SYS_DAV_RES (RES_OWNER,  RES_COL, RES_TYPE, RES_CR_TIME, RES_MOD_TIME, RES_PERMS, RES_ID, RES_NAME, RES_CONTENT) values (1, 120, http_mime_type('$i'), now(), now(), '110100100', WS.WS.getid ('R'), '$i', file_to_string ('$HOME/binsrc/samples/xpath/data/$i'))"  dba dba 
done	

LOAD_SQL $HOME/binsrc/samples/xpath/postsetup.sql dba dba
DO_COMMAND checkpoint