#!/bin/bash function load_config() { scriptPath=$(dirname "$(readlink -f "$BASH_SOURCE")") . $scriptPath/.upload_config } [ $# -lt 2 ] && echo "missing args: $0 path duration [plain]" && exit 1 set -e set -u load_config [ ! -f "$1" ] && echo "File $1 does not exist" && exit 1 random=$(pwgen -s -n 25) when="" if [ $# -eq 2 ] ; then when=$( date -d +"$2" +%s ) echo "Storing until: $(date -d @$when)" fi PLAIN=0 if [ $# -eq 3 ] ; then if [ $3 = "plain" ] ; then PLAIN=1 fi fi ssh $UPLOADER_SSH_SERVER mkdir $UPLOADER_UPLOAD_DIR/$random name=$( basename "$1" ) if [ $PLAIN -eq 1 ] ; then scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$name echo "$UPLOADER_URL_PREFIX/$random/$name" else KEYBASE=$(openssl rand -base64 32) KEYASHEX=$(echo -n $KEYBASE | base64 -d | xxd -p -c 10000) # linebreak after 10000 chars. i.e. never cat "$1" | openssl enc -aes-256-cbc -K "$KEYASHEX" -iv $(printf '0%.0s' {1..32}) | # print '0' 32 times = 16 bytes as hex ssh $UPLOADER_SSH_SERVER "cat > $UPLOADER_UPLOAD_DIR/$random/"$name"_enc" MIMETYPE=$(file -i "$1" | awk '{print $2}' | sed -e 's/;//g' ) echo "$UPLOADER_URL_PREFIX#$random/"$name"_enc:$KEYBASE:$MIMETYPE:$name" fi ssh $UPLOADER_SSH_SERVER chown -R $UPLOADER_FILE_OWNER $UPLOADER_UPLOAD_DIR/$random/ ssh $UPLOADER_SSH_SERVER "echo $when:$random >> $UPLOADER_EXPIRATION_FILE"