uploader/client/upload

66 baris
1.8 KiB
Plaintext
Mentah Pandangan Normal Riwayat

2021-03-21 21:15:24 +01:00
#!/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
2021-03-21 21:15:24 +01:00
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" )
LINK=""
2021-03-21 21:15:24 +01:00
if [ $PLAIN -eq 1 ] ; then
scp -r "$1" $UPLOADER_SSH_SERVER:$UPLOADER_UPLOAD_DIR/$random/$BASENAME
LINK="$UPLOADER_URL_PREFIX/$random/$BASENAME"
2021-03-21 21:15:24 +01:00
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"
LINK="$UPLOADER_URL_PREFIX#$random/$FSNAME:$KEYBASE:$MIMETYPE:$UPLOADED_NAME"
2021-03-21 21:15:24 +01:00
fi
echo "$LINK"
echo ""
echo "Press any key to copy the link to your clipboard" 1>&2
read -n 1 -t 5 ANSWER
if [ -n "$ANSWER" ] ; then
echo "$LINK" | xclip -selection clipboard
fi
2021-03-21 21:15:24 +01:00
ssh $UPLOADER_SSH_SERVER chown -R $UPLOADER_FILE_OWNER $UPLOADER_UPLOAD_DIR/$random/
ssh $UPLOADER_SSH_SERVER "echo $when:$random >> $UPLOADER_EXPIRATION_FILE"