-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.sh
49 lines (42 loc) · 1.29 KB
/
lib.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/sh -eu
version=0.1
rshell="ssh -F /dev/null -i"
sftpgroup="fpc"
# Directory that collects the boxes' PCAP files
data=/data
# $1 command and params to execute
remoteexec() { # {{{
# try to avoid ControlPersistent settings, see pushnetconfig for details
$rshell $key ${LOGIN}@$IP "$1"
} # }}}
# copy $@ to $IP:$BASE
pushfiles() { # {{{
#echo key: ${masterkey:-$KEY}
#echo rsync -rp -e "$rshell ${masterkey:-$KEY}" $@ ${LOGIN}@$IP:$BASE
rsync -rp -e "$rshell ${masterkey:-$KEY}" $@ ${LOGIN}@${IP}:${BASE}
} # }}}
readconfig() { # {{{
. ./$1
export KEY=${1%.conf}.key
export LOGIN=${LOGIN:-fpc}
export BASE=${BASE:-/home/${LOGIN}}
export box=${1%.conf}
export newip=$IP
# optionally overwrite with an optional IP
export IP=${currip:-$IP}
} # }}}
# create a new public/private key pair $1{,.pub}
genkey() { # {{{
# create key without a passphrase, change if you like
ssh-keygen -q -t rsa -b 2048 -f $1 -P ''
} # }}}
# TODO make sure ssh exits immediately after starting sniff-fpc.sh!
start() { # {{{
remoteexec "rm -f $BASE/stop"
remoteexec "$BASE/sniff-fpc.sh \& disown" &
} # }}}
stop() { # {{{
remoteexec "touch $BASE/stop"
remoteexec "killall -q -s SIGINT tcpdump" || true &
remoteexec "find $BASE -maxdepth 1 -name '*pcap' -type f -exec mv '{}' $BASE/archive \;"
} # }}}