diff import_local_file.sh @ 0:c772c8912663

Uploaded
author david-hoover
date Tue, 28 Feb 2012 12:36:45 -0500
parents
children 01687750c862
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/import_local_file.sh	Tue Feb 28 12:36:45 2012 -0500
@@ -0,0 +1,49 @@
+###
+### The shell script: import_local.sh
+###
+### The script copies the source file (param 1) 
+### to the destination file (param 2, which is galaxy's dataset_NNNNN.dat).
+###
+### The extra code tries to make it as safe as possible, allowing imports only
+### from limited areas.
+###
+### The script can be changed from copying to linking - would be even faster.
+###
+### cpx is a C executable that copies a file from a source to a destination
+### only if the source file is readable by the user given in the third arg.
+### cpx must be setuid root, so be careful who has access to it!  It can also
+### be allowed using sudo, if you know how to do it.
+#!/bin/sh
+
+INPUT="$1"
+OUTPUT="$2"
+EMAIL="$3"
+USER=`echo $EMAIL | sed -e 's#@.*##'`
+
+if [ -z "$OUTPUT" ]; then
+	echo "Usage: $0 [INPUT] [OUTPUT]" >&2
+	exit 1
+fi
+
+# Filter any unwanted directories
+
+if [[ `echo $INPUT | grep -c ^/data/` -lt 1 ]] && [[ `echo $INPUT | grep -c ^/home/` -lt 1 ]] ; then
+  echo "Error: \"$INPUT\" is not allowed" >&2
+  exit 1
+fi
+
+# Do the deed
+cpx $INPUT $OUTPUT "$USER"
+if [ $? != 0  ]; then
+  echo "Error: $USER failed to copy \"$INPUT\"" >&2
+  exit 1
+fi
+
+echo "File \"$INPUT\" imported"
+
+exit 0
+
+###
+###
+###
+