-
Notifications
You must be signed in to change notification settings - Fork 0
/
share3.sh
executable file
·49 lines (43 loc) · 1 KB
/
share3.sh
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
46
47
48
49
#!/bin/bash
qrcode()
{
qrcode-terminal "http://"$(ip addr show wlp3s0 |grep -Eo $ipregex |head -n1 )":9000/"
cd ~/.webshare && python3 -m http.server 9000
( ping -c 3 localhost.run >/dev/null 2>&1 && ssh -i ~/tempkey -R 80:localhost:9000 localhost.run ) || echo 'no network tunnel failed'
}
share()
{
if [[ "$1" = "f" ]]
then
echo "success $1"
[[ ! -d ~/.webshare ]] && mkdir -p ~/.webshare
#cp -r --reflink "$2" ~/.webshare/
path="$(realpath "$2")"
ln -s "$path" "/home/$(whoami)/.webshare/"
qrcode
elif [[ "$1" = "s" ]]
then
if [[ ! -z "$3" ]];
then
path="$( find "$2" -regextype egrep -regex "$3" |fzf )"
else
path="$( find "$2" |fzf )"
fi
path="$(realpath "$path")"
ln -s "$path" "/home/$(whoami)/.webshare/"
qrcode
else
error
fi
}
cleanup()
{
echo 'cleanup operation '
rm -vrf ~/.webshare/*
}
error()
{
echo 'usage share [s/f] <filename/dir> <regex optional>'
}
trap cleanup 1 2 3 6 14 15 ;
[[ ! $# -lt 2 ]] && share "$1" "$2" "$3" || error