-
Notifications
You must be signed in to change notification settings - Fork 1
/
runbot
executable file
·134 lines (120 loc) · 4.79 KB
/
runbot
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
echo "Hai!"
# classpath
cp="."
mkdir -p lib
# pircbot-ssl
pb="pircbot-1.5.0-ssl"
#see: https://github.com/mrenouf/pircbot-ssl ... with one simple code change, regular pircbot works too
[ -e "lib/${pb}.jar" ] || { echo "$pb not found"; exit 1; }
cp="${cp}:lib/${pb}.jar"
# boilerpipe
bp="boilerpipe-1.2.0"
[ -e "lib/$bp/$bp.jar" ] || {
echo "trying to get $bp"
cd lib
wget https://boilerpipe.googlecode.com/files/$bp-bin.tar.gz > /dev/null 2>&1
tar xvzf $bp-bin.tar.gz > /dev/null 2>&1
rm $bp-bin.tar.gz > /dev/null 2>&1
cd ..
[ -e "lib/$bp/$bp.jar" ] || { echo "getting $bp failed"; exit 1; }
echo "successfully got $bp"
}
cp="${cp}:lib/$bp/$bp.jar:lib/$bp/lib/nekohtml-1.9.13.jar:lib/$bp/lib/xerces-2.9.1.jar"
# prolog wordnet db
wn="WNprolog-3.0"
[ -e "lib/WordNet/wn_s2.db" ] || {
echo "trying to get $wn"
cd lib
wget http://wordnetcode.princeton.edu/3.0/$wn.tar.gz > /dev/null 2>&1
tar xvzf $wn.tar.gz > /dev/null 2>&1
rm $wn.tar.gz > /dev/null 2>&1
[ -e "prolog/wn_s.pl" ] || { echo "getting $wn failed"; exit 1; }
cd prolog
# deleting stuff because I have no space left on target machine :)
rm -f -- *.5 *.7 *.html *.pdf *.ps
# strip prolog syntax
echo "converting $wn"
for pl in *.pl; do
skip=$( echo $(expr length "$pl")-6+2 | bc )
cut -b $skip- -- "$pl" | awk 'sub("..$", "")' > "$(basename "$pl" .pl).db"
rm -f -- "$pl"
done
echo "compressing $wn"
cut -d, -f 1,3 wn_s.db > wn_s2.db
sed -i "s/,'/,/g" wn_s2.db
sed -i "s/'$//g" wn_s2.db
# stoplist and weights - you might want to do better than touch :)
touch stoplist weights
cd ..
mv prolog WordNet
cd ..
[ -e "lib/WordNet" ] || { echo "getting $wn failed"; exit 1; }
echo "successfully got $wn"
}
# bitlyj
bitly="bitlyj-2.0.0"
[ -e "lib/$bitly.jar" ] || {
echo "trying to get $bitly"
mkdir lib > /dev/null 2>&1
cd lib
wget http://bitlyj.googlecode.com/files/$bitly.jar > /dev/null 2>&1
cd ..
[ -e "lib/$bitly.jar" ] || { echo "getting $bitly failed"; exit 1; }
echo "successfully got $bitly"
}
cp="${cp}:lib/$bitly.jar"
[ "$(command -v scalac)" ] || {
scalaver="2.12.2"
if [ ! -e "scala-$scalaver/bin/scalac" ]; then
echo "trying to get scala-$scalaver"
wget http://downloads.typesafe.com/scala/$scalaver/scala-$scalaver.tgz > /dev/null 2>&1
tar -xvzf scala-$scalaver.tgz > /dev/null 2>&1
fi
PATH="${PATH}:scala-$scalaver/bin"
[ "$(command -v scalac)" ] || { echo "getting scala-$scalaver failed"; exit 1; }
echo "successfully got scala-$scalaver"
}
args="$1"
bot="haibot"
outdir="bin"
docdir="doc"
cp="${cp}:$outdir"
logdir="logs"
mkdir -p -- "$logdir"
mkdir -p -- "$outdir"
[ "$(command -v t)" ] || echo "$bot might work, if not, set up t - the twitter client."
[ "$(command -v fbcmd)" ] || echo "$bot might work, if not, set up fbcmd - the facebook client."
[ "$(command -v tesseract)" ] || echo "$bot might work, if not, sudo apt-get install tesseract-ocr"
[ "$(command -v gocr)" ] || echo "$bot might work, if not, sudo apt-get install gocr"
[ "$(command -v ocrad)" ] || echo "$bot might work, if not, sudo apt-get install ocrad"
[ "$(command -v convert)" ] || echo "$bot might work, if not, sudo apt-get install imagemagick"
compile() {
echo "compiling $bot"
rm -rf -- "$outdir" > /dev/null 2>&1
mkdir -p -- "$outdir"
warnings=$(scalac -Y 2>&1 | grep -- -Ywarn | cut -d' ' -f 3 | tr '\n' ' ' | sed 's/:<.*>//g')
scalac -version
scalac $SCALA_PLUGINS $warnings -Xlint -deprecation -feature -unchecked -opt:l:classpath -d $outdir -cp $cp -- *.scala
}
run() {
botname="org.psywerx.$bot"
runsecure="scala -Djava.security.manager -Djava.security.policy==haibot.policy -cp $cp"
rununsecure="scala -cp $cp"
case "$args" in
-c) echo "not gonna run $bot...";;
-d) echo "making docs..." && scaladoc $SCALA_PLUGINS -d $docdir -cp $cp -- *.scala;;
-fb) echo "starting findbugs" && findbugs -project findbugs.xml -effort:max;;
-s) echo "dropping into scala console" && $runsecure;;
-us) echo "dropping into unsecure scala console" && $rununsecure;;
-f) echo "running $bot..." && $runsecure $botname;;
-uf) echo "running $bot unsecurely..." && $rununsecure $botname;;
-nop) echo "doing nothing...";;
*) echo "putting $bot into background..." && { $runsecure $botname >> $logdir/$bot.log 2>&1 & }
esac
}
if [ "$args" = "-c" ] || [ $bot.scala -nt $outdir/org/psywerx/$bot.class ] || [ util.scala -nt $outdir/org/psywerx/util.class ] || [ OCR.scala -nt $outdir/org/psywerx/OCR.class ] || [ WordNet.scala -nt $outdir/org/psywerx/WordNet.class ] || [ Caption.scala -nt $outdir/org/psywerx/Caption.class ]; then
compile && run
else
run
fi