-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·201 lines (173 loc) · 3.99 KB
/
Copy pathinstall
File metadata and controls
executable file
·201 lines (173 loc) · 3.99 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/sh
#Command-line options
IFLAG=''
SFLAG=''
#get options
while getopts a:A:his option
do case "$option" in
a)
APIKEY=$OPTARG
;;
A)
APIKEY=$(cat $OPTARG)
;;
h)
echo "Usage: install.sh [-his] [-a <api-key>] [-A <api-key file>]"
echo "======= Options ========"
echo "a : Specify your slack api token for setup."
echo "A : Specify a file containing your api token for setup"
echo "h : Display this help text and exit."
echo "i : Install dependancies (will attempt to determine your package manager if necessary, but yum is NOT supported)."
echo "s : systemd-less install (bot daemon will be placed in /var/www/botd)."
exit 0
;;
i)
IFLAG='t'
;;
s)
SFLAG='t'
;;
[?])
echo "Try 'install.sh -h' for help"
exit 1
;;
esac
done
#check for proper permissions
if [ $(id -u) -ne 0 ]
then
if [ $DISPLAY ] && [ $(which gksudo) ]
then
gksudo "$0"
exit 0
fi
if [ $(which sudo) ]
then
sudo "$0"
exit 0
fi
echo "This script must be run with root permissions, and you don't appear to have sudo so we can't do it ourselves"
exit 2
fi
#if -i is specified, we must find a package manager
if [ $(which apt-get) ]
then
PKG='apt'
elif [ $(which pacman) ]
then
PKG='pac'
else
echo "-i option was specified, but a suitable package manager could not be found."
echo "Either install dependancies manually, or continue without the -i option."
exit 4
fi
echo "Checking for dependancies..."
#####################################
### CHECK FOR DEPENDANCIES ###
#####################################
#$PATH/python -> */python3
if [ ! $(which python) ] && [ ! $(which python3) ]
then
if [ -n $IFLAG ]
then
echo "You do not appear to have python in your `$PATH`, if you would like us to try to install it run 'install.sh -i', otherwise you must either install it yourself or ensure that it is in your `$PATH`."
exit 3
elif [ $PKG = 'apt' ]
then
apt-get install python3
elif [ $PKG = 'pac' ]
then
pacman -S python3
fi
#python is version 3+
elif [ ! $(python --version | sed 's/.*\s//' | sed 's/\..*//') = 3 ]
then
if [ ! -n $IFLAG ]
then
if [ $PKG = 'apt' ]
then
apt-get install python3
elif [ $PKG = 'pac' ]
then
pacman -S python3
fi
else
echo "Python is not version 3+, you must link /usr/bin/python to a python3 executable, install python3 and then link, or use the '-i' option."
exit 3
fi
fi
echo "\tPython is version 3+..."
#pip is version 3+
if [ ! $(which pip3) ]
then
if [ ! -n $IFLAG ]
then
if [ $PKG = 'apt' ]
then
apt-get install python3-pip
elif [ $PKG = 'pac' ]
then
pacman -S python3-pip
fi
else
echo "Pip version 3+ could not be found, you must install pip3 or use the '-i' option."
exit 3
fi
fi
echo "\tPip version 3+ found..."
#systemd is installed
if [ ! -d /lib/systemd/system/ ]
then
if [ -n $SFLAG ]
then
echo "You do not have systemd, if you wish to install anyway, run this script with the '-s' option"
echo "NOTE: bot daemon will be placed in /var/www/slackbot/botd"
exit 3
fi
SYSTEMD='f'
fi
echo "Done."
#Library installation
echo "installing python libraries..."
pip3 install pep3143daemon
pip3 install slacker
echo "Done."
echo "Installing l2p..."
BUILD_DIR=$(mktemp -d)
ORIG_DIR=$(pwd)
cd $BUILD_DIR
wget http://redsymbol.net/static/software/l2p/dist/l2p-1.1.1.tgz
tar -xvf ./l2p-1.1.1.tgz
mv ./l2p-1.1.1/l2p /usr/bin/
cd $ORIG_DIR
rm -rf $BUILD_DIR
echo "Done."
echo "Setting up files and directories..."
#Directory setup
mkdir -p /var/www/slackbot/modules
cp commander.py /var/www/slackbot
echo "Installing modules..."
for module in $(ls ./modules); do
if [ -d "modules/$module" ] && [ ! "$module" = "__pycache__" ]; then
cd modules/$module
./install.sh
cd -
echo "module $module installed"
fi
done
echo "...modules installed."
cp botd /var/www/slackbot/
if [ -n $SFLAG ]
then
cp slackbot.service /lib/systemd/system/
fi
touch /var/log/slackbot.log
touch /var/run/slackbot.pid
mkdir -p /etc/slackbot
if [ ! -z $APIKEY ]
then
echo $APIKEY > /etc/slackbot/API
else
touch /etc/slackbot/API
fi
echo "Done."