Files
up-and-share/uas.sh
2015-07-07 16:26:41 +03:00

62 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
########################################################################
# Copyright (C) 2015 Max Mehl <mail@mehl.mx>
########################################################################
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
########################################################################
#
# This script enables users to easily upload files via a SSH connection
# and creates a link to download them.
#
########################################################################
BASENAME=$(basename $0)
if [ "$1" = "" ]; then
echo "Usage: $BASENAME <file-to-upload>"
exit 1
fi
# Transform to full path
PWD=$(pwd)
FILE="$1"
FILEABS="$PWD/$FILE"
if [ ! -e "$FILEABS" ]; then
echo "File $FILEABS does not exist."
exit 1
fi
# Jump to dir of where the executable relies to load config
BINDIR="$(dirname "$(readlink -f "$0")")"
# Test if config.cfg exists and set needed variables
if [ ! -e "$BINDIR"/config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
source "$BINDIR"/config.cfg
# Replace spaces by underscores for better downloading
DEST=$(echo "$FILE" | sed 's/ /_/g')
scp "$FILEABS" "$SSH"/"$DEST"
# Output download link
echo "File has been uploaded. Download link:"
echo "$URL/$DEST"
exit 0