client/upload: Create .tar.xz transparently if given path is dir
Этот коммит содержится в:
родитель
dcec5f0b04
Коммит
dd9417ab9e
@ -10,7 +10,7 @@ set -e
|
||||
set -u
|
||||
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)
|
||||
@ -26,18 +26,32 @@ if [ $# -eq 3 ] ; then
|
||||
fi
|
||||
fi
|
||||
ssh $UPLOADER_SSH_SERVER mkdir $UPLOADER_UPLOAD_DIR/$random
|
||||
name=$( basename "$1" )
|
||||
|
||||
BASENAME=$( basename "$1" )
|
||||
|
||||
if [ $PLAIN -eq 1 ] ; then
|
||||
scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$name
|
||||
echo "$UPLOADER_URL_PREFIX/$random/$name"
|
||||
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
|
||||
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"
|
||||
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' )
|
||||
echo "$UPLOADER_URL_PREFIX#$random/"$name"_enc:$KEYBASE:$MIMETYPE:$name"
|
||||
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/
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user