blob: b3d6be509a9126883c37de46b598ad99bcedc725 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#!/bin/bash
set -eu
port=8000
disp_quick_usage()
{
cat <<EOF
Quick one-shot share
####################
Instead of wget --content-disposition, you can use:
wget-qs1 ${HOSTNAME}
Dependings on the current lan configuration,
you can access the file with one of:
wget --content-disposition ${HOSTNAME}.local:${port}
wget --content-disposition ${HOSTNAME}:${port}
EOF
for ip in $(ip -oneline -family inet address show \
| sed 's/^.*inet \([0-9.]\+\).*$/\1/') \
$(ip -oneline -family inet6 address show \
| sed 's/^.*inet6 \([0-9:a-fA-F]\+\).*$/\1/'); do
echo " wget --content-disposition ${ip}:${port}"
done
echo ""
echo "Note: --content-disposition is optional => use remote filename"
echo "=================================================="
}
disp_quick_usage
filename="$1"
sfilename="$(echo x$filename | sed 's/^x//;s/"//')"
(
echo "HTTP/1.1 200 OK"
#echo "Content-Type: $(file -bni "$1")"
echo "Content-Type: application/octet-stream"
echo "Content-Transfer-Encoding: binary"
echo "Content-Disposition: attachment; filename=\"$sfilename\""
echo "Content-Length: $(du -b "$filename" | cut -f1)"
echo ""
cat -- "$filename"
) | nc -l -q0 -p $port >/dev/null 2>&1
|