6 CONFIG_FILE="$HOME/.brisk_spu_install"
8 apache_conf="/etc/apache2/sites-available/default"
12 brisk_auth_conf="brisk_spu_auth.conf.pho"
14 # brisk_debug="0xffff"
15 web_path="/home/nastasi/web/brisk"
16 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
17 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
18 usock_path="/home/nastasi/brisk-priv/brisk.sock"
19 legal_path="/home/nastasi/brisk-priv/brisk"
21 brisk_conf="brisk_spu.conf.pho"
25 if [ "$1" = "chk" ]; then
30 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
36 # before all check errors on the sources
39 if [ "$1" = "pkg" ]; then
40 if [ "$2" != "" ]; then
45 nam1="brisk_${tag}.tgz"
46 nam2="brisk-img_${tag}.tgz"
47 echo "Build packages ${nam1} and ${nam2}."
48 read -p "Proceed [y/n]: " a
49 if [ "$a" != "y" -a "$a" != "Y" ]; then
52 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
54 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
59 if [ -f "$CONFIG_FILE" ]; then
63 if [ "x$prefix_path" = "x" ]; then
64 prefix_path="$web_path"
70 echo "$1 chk - run lintian on all ph* files."
71 echo "$1 pkg - build brisk packages."
72 echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path> [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>]"
74 echo " -f use this config file"
75 echo " -p save preferences in the file"
76 echo " -W web files only"
77 echo " -A apache_conf - def. $apache_conf"
78 echo " -n number of players - def. $players_n"
79 echo " -t number of tables - def. $tables_n"
80 echo " -T number of auth-only tables - def. $tables_auth_n"
81 echo " -a authorization file name - def. \"$brisk_auth_conf\""
82 echo " -d activate dabug - def. $brisk_debug"
83 echo " -w dir where place the web tree - def. \"$web_path\""
84 echo " -k dir where place ftok files - def. \"$ftok_path\""
85 echo " -l dir where save logs - def. \"$legal_path\""
86 echo " -y dir where place proxy files - def. \"$proxy_path\""
87 echo " -P prefix path - def. \"$prefix_path\""
88 echo " -C config filename - def. \"$brisk_conf\""
89 echo " -U unix socket path - def. \"$usock_path\""
94 function get_param () {
95 echo "X$2" | grep -q "^X$1\$"
102 echo "$2" | cut -c 3-
108 function searchetc() {
109 local dstart dname pp
114 while [ "$pp" != "/" ]; do
115 if [ -d "$pp/$dname" ]; then
119 pp="$(dirname "$pp")"
128 while [ $# -gt 0 ]; do
129 # echo aa $1 xx $2 bb
132 -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;;
133 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
134 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
135 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
136 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
137 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
138 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
139 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
140 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
141 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
142 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
143 -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
144 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
145 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
146 -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
147 -W) web_only="TRUE";;
148 -h) usage $0; exit 0;;
149 *) usage $0; exit 1;;
151 if [ ! -z "$conffile" ]; then
152 if [ ! -f "$conffile" ]; then
153 echo "config file [$conffile] not found"
164 echo " outconf: \"$outconf\""
165 echo " apache_conf:\"$apache_conf\""
166 echo " players_n: $players_n"
167 echo " tables_n: $tables_n"
168 echo " tables_auth_n: $tables_auth_n"
169 echo " brisk_auth_conf: \"$brisk_auth_conf\""
170 echo " brisk_debug:\"$brisk_debug\""
171 echo " web_path: \"$web_path\""
172 echo " ftok_path: \"$ftok_path\""
173 echo " legal_path: \"$legal_path\""
174 echo " proxy_path: \"$proxy_path\""
175 echo " prefix_path:\"$prefix_path\""
176 echo " brisk_conf:\"$brisk_conf\""
177 echo " usock_path: \"$usock_path\""
178 echo " web_only: \"$web_only\""
180 if [ ! -z "$outconf" ]; then
183 echo "# Produced automatically by brisk::INSTALL.sh"
185 echo "apache_conf=$apache_conf"
186 echo "players_n=$players_n"
187 echo "tables_n=$tables_n"
188 echo "tables_auth_n=$tables_auth_n"
189 echo "brisk_auth_conf=\"$brisk_auth_conf\""
190 echo "brisk_debug=\"$brisk_debug\""
191 echo "web_path=\"$web_path\""
192 echo "ftok_path=\"$ftok_path\""
193 echo "proxy_path=\"$proxy_path\""
194 echo "legal_path=\"$legal_path\""
195 echo "prefix_path=\"$prefix_path\""
196 echo "brisk_conf=\"$brisk_conf\""
197 echo "usock_path=\"$usock_path\""
198 echo "web_only=\"$web_only\""
202 max_players=$((40 + players_n * tables_n))
206 # check for etc path existence
207 dsta="$(dirname "$web_path")"
208 etc_path="$(searchetc "$dsta" Etc)"
209 if [ $? -ne 0 ]; then
210 echo "Etc directory not found"
219 ftokk_path="${ftok_path}k"
221 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
222 echo "players_n ($players_n) out of range (3|5)"
226 if [ "$web_only" = "FALSE" ]; then
227 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
228 echo "ftok_path (\"$ftok_path\") not exists"
231 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
232 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
235 if [ -d "$ftok_path" ]; then
236 mv "$ftok_path" "$ftokk_path"
238 touch $ftokk_path/spy.txt >/dev/null 2>&1
239 if [ $? -ne 0 ]; then
240 echo "ftokk_path (\"$ftokk_path\") write not allowed."
243 rm $ftokk_path/spy.txt
245 # create the fs subtree to enable ftok-ing
246 touch ${ftokk_path}/main
247 chmod 666 ${ftokk_path}/main
248 touch ${ftokk_path}/challenges
249 chmod 666 ${ftokk_path}/challenges
250 touch ${ftokk_path}/hardbans
251 chmod 666 ${ftokk_path}/hardbans
252 touch ${ftokk_path}/warrant
253 chmod 666 ${ftokk_path}/warrant
254 touch ${ftokk_path}/poll
255 chmod 666 ${ftokk_path}/poll
256 for i in $(seq 0 $max_players); do
257 touch ${ftokk_path}/user$i
258 chmod 666 ${ftokk_path}/user$i
261 if [ ! -d ${ftokk_path}/bin5 ]; then
262 mkdir ${ftokk_path}/bin5
263 chmod 777 ${ftokk_path}/bin5
266 for i in $(seq 0 $((tables_n - 1))); do
267 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
268 mkdir ${ftokk_path}/bin5/table$i
270 chmod 777 ${ftokk_path}/bin5/table$i
271 touch ${ftokk_path}/bin5/table$i/table
272 chmod 666 ${ftokk_path}/bin5/table$i/table
273 for e in $(seq 0 4); do
274 touch ${ftokk_path}/bin5/table$i/user$e
275 chmod 666 ${ftokk_path}/bin5/table$i/user$e
277 # create subdirectories in proxy path
278 if [ ! -d ${proxy_path}/bin5/table$i ]; then
279 mkdir -p ${proxy_path}/bin5/table$i
282 chmod -R 777 ${proxy_path}/bin5
285 install -d ${web_path}__
286 for i in $(find web -type d | sed 's/^....//g'); do
287 install -d ${web_path}__/$i
290 for i in $(find web -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' | sed 's/^....//g'); do
291 install -m 644 "web/$i" "${web_path}__/$i"
293 chmod 755 "${web_path}__/spush/brisk-spush.php"
295 prefix_path_len=$(echo -n "$prefix_path" | wc -c)
297 if [ $players_n -eq 5 ]; then
304 sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $players_n/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;)
306 sed -i "s/^var G_send_time *= *[0-9]\+/var G_send_time = $send_time/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l '^var G_send_time *= *[0-9]\+' {} \;)
308 # .ph[pho] substitutions
309 sed -i "s/define *( *'PLAYERS_N', *[0-9]\+ *)/define('PLAYERS_N', $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'PLAYERS_N', *[0-9]\+ *)" {} \;)
311 sed -i "s/define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)/define('BIN5_PLAYERS_N', $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'BIN5_PLAYERS_N', *[0-9]\+ *)" {} \;)
313 sed -i "s@define *( *'FTOK_PATH',[^)]*)@define('FTOK_PATH', \"$ftok_path\")@g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'FTOK_PATH',[^)]*)" {} \;)
315 sed -i "s@define *( *'SITE_PREFIX',[^)]*)@define('SITE_PREFIX', \"$prefix_path\")@g" ${web_path}__/Obj/sac-a-push.phh
317 sed -i "s@define *( *'SITE_PREFIX_LEN',[^)]*)@define('SITE_PREFIX_LEN', $prefix_path_len)@g" ${web_path}__/Obj/sac-a-push.phh
319 sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}__/spush/brisk-spush.phh
321 sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g" ${web_path}__/Obj/brisk.phh
323 sed -i "s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
325 sed -i "s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
327 sed -i "s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
329 sed -i "s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
331 sed -i "s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
333 sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
335 sed -i "s@\( \+xhr_rd_cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/http_streaming.js
336 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@g" ${web_path}__/commons.js
338 document_root="$(grep DocumentRoot "${apache_conf}" | awk '{ print $2 }')"
339 sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
341 if [ -d ${web_path} ]; then
342 mv ${web_path} ${web_path}.old
345 if [ -d ../brisk-img ]; then
347 ./INSTALL.sh -w ${web_path}__
351 # config file installation or diff
352 if [ -f "$etc_path/$brisk_conf" ]; then
353 echo "Config file $etc_path/$brisk_conf exists."
354 echo "=== Dump the diff. ==="
355 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
356 diff -u <(cat "$etc_path/$brisk_conf" | grep '\$[a-zA-Z_ ]\+=' | sed 's/ = .*/ = /g' | sort | uniq) <(cat "${web_path}__""/Obj/brisk.conf-templ.pho" | grep '\$[a-zA-Z_ ]\+=' | sed 's/ = .*/ = /g' | sort | uniq )
357 echo "=== End dump. ==="
359 echo "Config file $etc_path/$brisk_conf not exists."
360 echo "Install a template."
361 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
364 mv ${web_path}__ ${web_path}
365 if [ -d ${web_path}.old ]; then
366 rm -rf ${web_path}.old
368 if [ "$web_only" = "FALSE" ]; then
369 mv "$ftokk_path" "$ftok_path"