| #!/bin/sh |
| |
| # Drop server |
| # Copyright 2015-2019 Rivoreo |
| |
| # This program 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; either version 2 of the License, or (at your option) |
| # any later version. |
| |
| # 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. |
| |
| DROP_TARGET="$HOME/drop" |
| |
| set -f |
| set -e |
| |
| [ -f /etc/drop.cfg ] && . /etc/drop.cfg |
| |
| if [ $# = 2 -a "$1" = -c ]; then |
| c="$2" |
| elif [ -n "$SSH_ORIGINAL_COMMAND" ]; then |
| c="$SSH_ORIGINAL_COMMAND" |
| [ -f "$HOME/.config/drop.cfg" ] && . "$HOME/.config/drop.cfg" |
| else |
| echo "incorrect command line" 1>&2 |
| exit 255 |
| fi |
| |
| if printf %s "$c" | grep -Eq '^-m [0-9]+ .+'; then |
| set -- $c |
| mode=$2 |
| f="`printf %s \"$c\" | sed -r 's/^-m [0-9]+ //'`" |
| else |
| mode= |
| f="$c" |
| fi |
| |
| if [ "$f" = . -o "$f" = .. ] || printf %s "$f" | grep -Fq /; then |
| echo "invalid file name" 1>&2 |
| exit 1 |
| fi |
| |
| [ -d "$DROP_TARGET" ] || mkdir "$DROP_TARGET" |
| |
| # XXX; need a portable way to get msec |
| new_file_name="`date -u +%F.%H-%M-%S`.$f" |
| # TODO: database |
| if [ -n "$mode" ]; then |
| chmod -- "$mode" "$DROP_TARGET/$new_file_name" > "$DROP_TARGET/$new_file_name" |
| fi |
| exec cat > "$DROP_TARGET/$new_file_name" |