forked from geirha/shbot
/
evalcmd
executable file
·64 lines (55 loc) · 1.43 KB
/
evalcmd
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
if [[ $1 = -n ]]; then
nopaste=1
shift
fi
t=${1:-4}
declare -A triggers='()'
while read -r trigger shell; do
triggers[$trigger]=$shell
done < ./triggers
[[ ${triggers[$t]} ]] || exit
if [[ -f manpages && $2 = "man "[![:blank:]]* ]]; then
read -r cmd args <<< "$2"
source ./manpages &&
if [[ ${manpages[$args]} ]]; then
printf '%s: %s\n' "$2" "${manpages[$args]}"
exit
fi
elif [[ -f helppages && $2 = "help "[![:blank:]]* ]]; then
read -r cmd args <<< "$2"
source ./helppages &&
if [[ ${helppages[$args]} ]]; then
printf '%s\n' "${helppages[$args]}"
exit
fi
fi
output=$(./limitcmd.pl "${triggers[$t]}" "$2" | expand | head -c 4242 | tr -d '\r' | awk '{ do { print substr($0, 1, 120); $0 = substr($0, 121); } while(length($0)>0); }'; exit ${PIPESTATUS[0]}; )
result=$?
lines=$(wc -l <<< "$output")
shopt -s extglob
if [[ $output == *( ) ]]
then
if (( result > 0 ))
then
echo "no output within the time limit"
else
echo "no output"
fi
exit 0
fi
if ((nopaste)); then
printf '%s\n' "$output"
else
if (( lines <= 3 )); then
printf '%s\n' "$output";
exit 0
fi
if url=$(curl -sfF 'f:1=<-' http://ix.io <<< "$output"); then
etc="etc... ( $url )"
else
etc="and so forth... (but now the pastebin is sick of me)"
fi
printf '%s\n' "$output" | head -n 2
printf '%s\n' "$etc"
fi