-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendfile.sh
executable file
·44 lines (35 loc) · 1.1 KB
/
sendfile.sh
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
# the parser API to send files to host
sendfile()
{
# the fifo
FILEFIFO="$FIFODIR/sendfile.fifo"
FILEBLOCK="$TMPDIR/sendfile.blocked"
# first secure the options are empty
unset FILE DESTINATION
# arguments parser
TEMP=$(getopt -o b:l:f:d: --long --block:--file:--dest: \
-n 'example.bash' -- "$@")
if [ $? != 0 ] ; then echo "Error running sendfile." >&2 ; return 1 ; fi
eval set -- "$TEMP"
while true ; do
case "$1" in
-b|--block) BLOCK=$2
shift 2 ;;
-f|--file) FILE=$2
shift 2 ;;
-d|--dest) DESTINATION=$2
shift 2 ;;
--) shift ; break ;;
*) echo "Internal error on sendfile." ; return 1 ;;
esac
done
HOST=$1
# end parser
# block host to receive files
test ! -z "$BLOCK" && echo "$BLOCK" >> $FILEBLOCK && return 0
# check the arguments data
test -z "$FILE" && exit 1
test -z "$DESTINATION" && exit 1
test -z "$HOST" && exit 1
echo "$HOST $FILE $DESTINATION" >> $FILEFIFO
}