#!/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 [ ! -e "$1" ] && echo "Path $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 BASENAME=$( basename "$1" ) if [ $PLAIN -eq 1 ] ; then scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$BASENAME echo "$UPLOADER_URL_PREFIX/$random/$BASENAME" else KEYBASE=$(openssl rand -base64 32) KEYASHEX=$(echo -n $KEYBASE | base64 -d | xxd -p -c 10000) # linebreak after 10000 chars. i.e. never UPLOADED_NAME="$BASENAME" FSNAME="$BASENAME"_enc PIPER="cat $1" MIMETYPE="" if [ -d "$1" ] ; then PIPER="tar cJf - $1" MIMETYPE="application/x-xz" UPLOADED_NAME="$BASENAME".tar.xz FSNAME="$UPLOADED_NAME"_enc else MIMETYPE=$(file -i "$1" | awk '{print $2}' | sed -e 's/;//g' ) fi $PIPER | 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/$FSNAME" echo "$UPLOADER_URL_PREFIX#$random/$FSNAME:$KEYBASE:$MIMETYPE:$UPLOADED_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"