client/upload: Create .tar.xz transparently if given path is dir
This commit is contained in:
parent
dcec5f0b04
commit
dd9417ab9e
@ -10,7 +10,7 @@ set -e
|
|||||||
set -u
|
set -u
|
||||||
load_config
|
load_config
|
||||||
|
|
||||||
[ ! -f "$1" ] && echo "File $1 does not exist" && exit 1
|
[ ! -e "$1" ] && echo "Path $1 does not exist" && exit 1
|
||||||
|
|
||||||
|
|
||||||
random=$(pwgen -s -n 25)
|
random=$(pwgen -s -n 25)
|
||||||
@ -26,18 +26,32 @@ if [ $# -eq 3 ] ; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
ssh $UPLOADER_SSH_SERVER mkdir $UPLOADER_UPLOAD_DIR/$random
|
ssh $UPLOADER_SSH_SERVER mkdir $UPLOADER_UPLOAD_DIR/$random
|
||||||
name=$( basename "$1" )
|
|
||||||
|
BASENAME=$( basename "$1" )
|
||||||
|
|
||||||
if [ $PLAIN -eq 1 ] ; then
|
if [ $PLAIN -eq 1 ] ; then
|
||||||
scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$name
|
scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$BASENAME
|
||||||
echo "$UPLOADER_URL_PREFIX/$random/$name"
|
echo "$UPLOADER_URL_PREFIX/$random/$BASENAME"
|
||||||
else
|
else
|
||||||
KEYBASE=$(openssl rand -base64 32)
|
KEYBASE=$(openssl rand -base64 32)
|
||||||
KEYASHEX=$(echo -n $KEYBASE | base64 -d | xxd -p -c 10000) # linebreak after 10000 chars. i.e. never
|
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"
|
UPLOADED_NAME="$BASENAME"
|
||||||
MIMETYPE=$(file -i "$1" | awk '{print $2}' | sed -e 's/;//g' )
|
FSNAME="$BASENAME"_enc
|
||||||
echo "$UPLOADER_URL_PREFIX#$random/"$name"_enc:$KEYBASE:$MIMETYPE:$name"
|
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
|
fi
|
||||||
|
|
||||||
ssh $UPLOADER_SSH_SERVER chown -R $UPLOADER_FILE_OWNER $UPLOADER_UPLOAD_DIR/$random/
|
ssh $UPLOADER_SSH_SERVER chown -R $UPLOADER_FILE_OWNER $UPLOADER_UPLOAD_DIR/$random/
|
||||||
|
Loading…
Reference in New Issue
Block a user