forked from nlplab/brat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·188 lines (146 loc) · 5.25 KB
/
install.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
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
#!/bin/sh
# Install script for brat server
#
# Author: Sampo Pyysalo <smp is s u tokyo ac jp>
# Author: Pontus Stenetorp <pontus is s u tokyo ac jp>
# Version: 2012-02-09
# defaults
WORK_DIR=work
DATA_DIR=data
CONFIG_TEMPLATE=config_template.py
CONFIG=config.py
# Absolute data and work paths
base_dir=`(cd \`dirname $0\`; pwd)`
SCRIPT_NAME=`basename $0`
work_dir_abs="$base_dir/$WORK_DIR"
data_dir_abs="$base_dir/$DATA_DIR"
USAGE="Usage: ${SCRIPT_NAME} [-u] [-q]"
# Options
UNPRIVILEGED=false
QUICK=false
while getopts uq OPT; do
case "${OPT}" in
u)
UNPRIVILEGED=true
;;
q)
QUICK=true
UNPRIVILEGED=true
;;
\?)
echo ${USAGE} 1>&2
exit 1
;;
esac
done
shift `expr $OPTIND - 1`
if [ "$QUICK" = true ]; then
user_name='default'
password=`python -c 'import string; import random; print "".join(random.choice(string.ascii_letters+string.digits) for _ in range(10))'`
echo "Quick install: set user name to \"$user_name\" and password to \"$password\""
admin_email='unconfigured@example.com'
else
# not quick; ask details for config
while true; do
echo 'Please enter the user name that you want to use when logging into brat:'
read user_name
if [ -n "$user_name" ]; then
break
fi
done
while true; do
echo "Please enter a brat password (this shows on screen):"
read password
if [ -n "$password" ]; then
break
fi
done
echo "Please enter the administrator contact email:"
read admin_email
fi
# Put a configuration in place.
(echo "# This configuration was automatically generated by ${SCRIPT_NAME}"
cat "$base_dir/$CONFIG_TEMPLATE" | \
awk 'NR==1 { print "from os.path import dirname, join as path_join" } $1' | \
sed \
-e 's|\(ADMIN_CONTACT_EMAIL = \).*|\1'\'$admin_email\''|' \
-e "s|\(BASE_DIR = \).*|\1dirname(__file__)|" \
-e "s|\(DATA_DIR = \).*|\1path_join(BASE_DIR, '${DATA_DIR}')|" \
-e "s|\(WORK_DIR = \).*|\1path_join(BASE_DIR, '${WORK_DIR}')|" \
-e '/\(USER_PASSWORD *= *{.*\)/a\
\ '\'"$user_name"\'': '\'"$password"\'',') > "$base_dir/$CONFIG"
# Create data and word directories and set up data (unless they exist already)
if [ -d $work_dir_abs ] && [ -d $data_dir_abs ]; then
echo "Data and work directories $DATA_DIR/ and $WORK_DIR/ exist, skipping setup."
else
mkdir -p $work_dir_abs
mkdir -p $data_dir_abs
# Try to determine Apache user and group
apache_user=`ps aux | grep -v 'tomcat' | grep '[a]pache\|[h]ttpd' | cut -d ' ' -f 1 | grep -v '^root$' | head -n 1`
apache_group=`groups $apache_user | head -n 1 | sed 's/ .*//'`
# Place example data
cp -r ${base_dir}/example-data/corpora ${DATA_DIR}/examples
cp -r ${base_dir}/example-data/tutorials ${DATA_DIR}/tutorials
# Place example configs
cp ${base_dir}/configurations/example-conf/*.conf ${DATA_DIR}
# Make $work_dir_abs and $data_dir_abs writable by Apache
group_ok=0
if [ "${UNPRIVILEGED}" != 'true' -a -n "$apache_group" -a -n "$apache_user" ] ; then
echo "Assigning owner of the following directories to apache ($apache_group):"
echo " \"$work_dir_abs/\""
echo "and"
echo " \"$data_dir_abs/\""
echo "(this requires sudo; please enter your password if prompted)"
sudo chgrp -R $apache_group $data_dir_abs $work_dir_abs
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
chmod -R g+rwx $data_dir_abs $work_dir_abs
group_ok=1
else
echo "WARNING: failed to change group."
fi
else
if [ "${UNPRIVILEGED}" != 'true' ]; then
echo "WARNING: failed to determine Apache group."
fi
fi
if [ $group_ok -eq 0 ]; then
echo
echo "Setting global read and write permissions to directories"
echo " \"$work_dir_abs/\" and"
echo " \"$data_dir_abs/\""
echo "(you may wish to consider fixing this manually)"
chmod -R 777 $data_dir_abs $work_dir_abs
fi
fi
# Extract the most important library dependencies.
# ( cd server/lib && tar xfz simplejson-2.1.5.tar.gz )
# Dump some last instructions to the user
if [ "$QUICK" = true ]; then
cat << EOF
Quick install: finished. To test brat, run the standalone server as
python standalone.py
Please consider re-installing without "-q" for extended use (recommended).
EOF
else
cat << EOF
The installation has finished, you are almost done.
1.) If you are installing brat on a webserver, make sure you have
followed the steps described in the brat manual to enable CGI:
http://brat.nlplab.org/installation.html
2.) Please verify that brat is running by accessing your installation
using a web browser.
You can automatically diagnose some common installation issues using:
tools/troubleshooting.sh URL_TO_BRAT_INSTALLATION
If there are issues not detected by the above script, please contact the
brat developers and/or file a bug to the brat bug tracker:
https://github.com/nlplab/brat/issues'
3.) Once brat is running, put your data in the data directory. Or use
the example data placed there by the installation:
${data_dir_abs}
4.) You can find configuration files to place in your data directory in
the configurations directory, see the manual for further details:
${base_dir}/configurations
5.) Then, you (and your team?) are ready to start annotating!
EOF
fi