6 CONFIG_FILE="$HOME/.brisk_install"
8 apache_conf="/etc/apache2/sites-available/default"
14 brisk_auth_conf="brisk_spu_auth.conf.pho"
16 # brisk_debug="0xffff"
17 web_path="/home/nastasi/web/brisk"
18 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
19 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
20 usock_path="/home/nastasi/brisk-priv/brisk.sock"
22 legal_path="/home/nastasi/brisk-priv/brisk"
24 brisk_conf="brisk_spu.conf.pho"
32 echo "$1 chk - run lintian on all ph* files."
33 echo "$1 pkg - build brisk packages."
34 echo "$1 [-W] [-n 3|5] [-c 3|8] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
36 echo " -f use this config file"
37 echo " -p save preferences in the file"
38 echo " -W web files only"
39 echo " -A apache_conf - def. $apache_conf"
40 echo " -c number cards in hand - def. $card_hand"
41 echo " -n number of players - def. $players_n"
42 echo " -t number of tables - def. $tables_n"
43 echo " -T number of auth-only tables - def. $tables_auth_n"
44 echo " -G number of cert-only tables - def. $tables_cert_n"
45 echo " -a authorization file name - def. \"$brisk_auth_conf\""
46 echo " -d activate dabug - def. $brisk_debug"
47 echo " -w dir where place the web tree - def. \"$web_path\""
48 echo " -k dir where place ftok files - def. \"$ftok_path\""
49 echo " -l dir where save logs - def. \"$legal_path\""
50 echo " -y dir where place proxy files - def. \"$proxy_path\""
51 echo " -P prefix path - def. \"$prefix_path\""
52 echo " -C config filename - def. \"$brisk_conf\""
53 echo " -U unix socket path - def. \"$usock_path\""
54 echo " -u system user to run brisk dae - def. \"$sys_user\""
55 echo " -x copy tests as normal php - def. \"$test_add\""
59 function get_param () {
60 echo "X$2" | grep -q "^X$1\$"
73 function searchetc() {
79 while [ "$pp" != "/" ]; do
80 if [ -d "$pp/$dname" ]; then
93 if [ "$1" = "chk" ]; then
98 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
102 taggit="$(git describe --tags | sed 's/^v//g')"
103 tagphp="$(grep "^\$G_brisk_version = " web/Obj/brisk.phh | sed 's/^[^"]\+"//g;s/".*//g')"
104 if [ "$taggit" != "$tagphp" ]; then
106 echo "WARNING: taggit: [$taggit] tagphp: [$tagphp]"
112 # before all check errors on the sources
115 if [ "$1" = "pkg" ]; then
116 if [ "$2" != "" ]; then
119 tag="$(git describe)"
121 nam1="brisk_${tag}.tgz"
122 nam2="brisk-img_${tag}.tgz"
123 echo "Build packages ${nam1} and ${nam2}."
124 read -p "Proceed [y/n]: " a
125 if [ "$a" != "y" -a "$a" != "Y" ]; then
128 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
130 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
135 if [ -f "$CONFIG_FILE" ]; then
136 source "$CONFIG_FILE"
139 if [ "x$prefix_path" = "x" ]; then
140 prefix_path="$web_path"
144 while [ $# -gt 0 ]; do
145 # echo aa $1 xx $2 bb
148 -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;;
149 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
150 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
151 -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;;
152 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
153 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
154 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
155 -G*) tables_cert_n="$(get_param "-G" "$1" "$2")"; sh=$?;;
156 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
157 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
158 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
159 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
160 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
161 -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
162 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
163 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
164 -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
165 -u*) sys_user="$(get_param "-u" "$1" "$2")"; sh=$?;;
166 system) action=system;;
167 -W) web_only="TRUE";;
168 -x) test_add="TRUE";;
169 -h) usage $0; exit 0;;
170 *) usage $0; exit 1;;
172 if [ ! -z "$conffile" ]; then
173 if [ ! -f "$conffile" ]; then
174 echo "config file [$conffile] not found"
185 echo " outconf: \"$outconf\""
186 echo " apache_conf:\"$apache_conf\""
187 echo " card_hand: $card_hand"
188 echo " players_n: $players_n"
189 echo " tables_n: $tables_n"
190 echo " tables_auth_n: $tables_auth_n"
191 echo " tables_cert_n: $tables_cert_n"
192 echo " brisk_auth_conf: \"$brisk_auth_conf\""
193 echo " brisk_debug:\"$brisk_debug\""
194 echo " web_path: \"$web_path\""
195 echo " ftok_path: \"$ftok_path\""
196 echo " legal_path: \"$legal_path\""
197 echo " proxy_path: \"$proxy_path\""
198 echo " prefix_path:\"$prefix_path\""
199 echo " brisk_conf: \"$brisk_conf\""
200 echo " usock_path: \"$usock_path\""
201 echo " sys_user: \"$sys_user\""
202 echo " web_only: \"$web_only\""
203 echo " test_add: \"$test_add\""
205 if [ ! -z "$outconf" ]; then
208 echo "# Produced automatically by brisk::INSTALL.sh"
210 echo "apache_conf=$apache_conf"
211 echo "card_hand=$card_hand"
212 echo "players_n=$players_n"
213 echo "tables_n=$tables_n"
214 echo "tables_auth_n=$tables_auth_n"
215 echo "tables_cert_n=$tables_cert_n"
216 echo "brisk_auth_conf=\"$brisk_auth_conf\""
217 echo "brisk_debug=\"$brisk_debug\""
218 echo "web_path=\"$web_path\""
219 echo "ftok_path=\"$ftok_path\""
220 echo "proxy_path=\"$proxy_path\""
221 echo "legal_path=\"$legal_path\""
222 echo "prefix_path=\"$prefix_path\""
223 echo "brisk_conf=\"$brisk_conf\""
224 echo "usock_path=\"$usock_path\""
225 echo "sys_user=\"$sys_user\""
226 echo "web_only=\"$web_only\""
227 echo "test_add=\"$test_add\""
231 max_players=$((40 + players_n * tables_n))
233 if [ "$action" = "system" ]; then
234 scrname="$(echo "$prefix_path" | sed 's@^/@@g;s@/$@@g;s@/@_@g;')"
236 echo "script name: [$scrname]"
237 echo "brisk path: [$web_path]"
238 echo "private path: [$legal_path]"
239 echo "system user: [$sys_user]"
241 read -p "press enter to continue" sure
242 cp bin/brisk-init.sh brisk-init.sh.wrk
243 sed -i "s@^BPATH=.*@BPATH=\"${web_path}\"@g;s@^PPATH=.*@PPATH=\"${legal_path}\"@g;s@^SSUFF=.*@SSUFF=\"${scrname}\"@g;s@^BUSER=.*@BUSER=\"${sys_user}\"@g" brisk-init.sh.wrk
245 su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}"
250 echo "DON'T FORGET: after the first installation you MUST configure your run-levels accordingly"
252 echo "Example: su -c 'update-rc.d $scrname defaults'"
259 # check for etc path existence
260 dsta="$(dirname "$web_path")"
261 etc_path="$(searchetc "$dsta" Etc)"
262 if [ $? -ne 0 ]; then
263 echo "Etc directory not found"
272 ftokk_path="${ftok_path}k"
274 if [ $card_hand -lt 3 -o $card_hand -gt 8 ]; then
275 echo "card_hand ($card_hand) out of range (3 <= c <= 8)"
279 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
280 echo "players_n ($players_n) out of range (3|5)"
284 if [ "$web_only" = "FALSE" ]; then
285 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
286 echo "ftok_path (\"$ftok_path\") not exists"
289 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
290 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
293 if [ -d "$ftok_path" ]; then
294 mv "$ftok_path" "$ftokk_path"
296 touch $ftokk_path/spy.txt >/dev/null 2>&1
297 if [ $? -ne 0 ]; then
298 echo "ftokk_path (\"$ftokk_path\") write not allowed."
301 rm $ftokk_path/spy.txt
303 # create the fs subtree to enable ftok-ing
304 touch ${ftokk_path}/main
305 chmod 666 ${ftokk_path}/main
306 touch ${ftokk_path}/challenges
307 chmod 666 ${ftokk_path}/challenges
308 touch ${ftokk_path}/hardbans
309 chmod 666 ${ftokk_path}/hardbans
310 touch ${ftokk_path}/warrant
311 chmod 666 ${ftokk_path}/warrant
312 touch ${ftokk_path}/poll
313 chmod 666 ${ftokk_path}/poll
314 for i in $(seq 0 $max_players); do
315 touch ${ftokk_path}/user$i
316 chmod 666 ${ftokk_path}/user$i
319 if [ ! -d ${ftokk_path}/bin5 ]; then
320 mkdir ${ftokk_path}/bin5
321 chmod 777 ${ftokk_path}/bin5
324 for i in $(seq 0 $((tables_n - 1))); do
325 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
326 mkdir ${ftokk_path}/bin5/table$i
328 chmod 777 ${ftokk_path}/bin5/table$i
329 touch ${ftokk_path}/bin5/table$i/table
330 chmod 666 ${ftokk_path}/bin5/table$i/table
331 for e in $(seq 0 4); do
332 touch ${ftokk_path}/bin5/table$i/user$e
333 chmod 666 ${ftokk_path}/bin5/table$i/user$e
335 # create subdirectories in proxy path
336 if [ ! -d ${proxy_path}/bin5/table$i ]; then
337 mkdir -p ${proxy_path}/bin5/table$i
340 chmod -R 777 ${proxy_path}/bin5
343 install -d ${web_path}__
344 for i in $(find web -type d | sed 's/^....//g'); do
345 install -d ${web_path}__/$i
348 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' -o -name 'terms-of-service*' | sed 's/^....//g'); do
349 install -m 644 "web/$i" "${web_path}__/$i"
351 if [ "$test_add" = "TRUE" ]; then
352 for i in $(find webtest -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^........//g'); do
353 install -m 644 "webtest/$i" "${web_path}__/$i"
357 chmod 755 "${web_path}__/spush/brisk-spush.php"
359 prefix_path_len=$(echo -n "$prefix_path" | wc -c)
361 if [ $players_n -eq 5 ]; then
368 sed -i "s/CARD_HAND *= *[0-9]\+/CARD_HAND = $card_hand/g" $(find ${web_path}__ -type f -name '*.js' -exec grep -l 'CARD_HAND *= *[0-9]\+' {} \;)
369 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]\+' {} \;)
371 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]\+' {} \;)
373 # .ph[pho] substitutions
374 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]\+ *)" {} \;)
376 sed -i "s/define *( *'BIN5_CARD_HAND', *[0-9]\+ *)/define('BIN5_CARD_HAND', $card_hand)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l "define *( *'BIN5_CARD_HAND', *[0-9]\+ *)" {} \;)
378 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]\+ *)" {} \;)
380 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',[^)]*)" {} \;)
382 sed -i "s@define *( *'SITE_PREFIX',[^)]*)@define('SITE_PREFIX', \"$prefix_path\")@g;
383 s@define *( *'SITE_PREFIX_LEN',[^)]*)@define('SITE_PREFIX_LEN', $prefix_path_len)@g" ${web_path}__/Obj/sac-a-push.phh
385 sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}__/spush/brisk-spush.phh
387 sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g;
388 s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g;
389 s@define *( *'TABLES_CERT_N',[^)]*)@define('TABLES_CERT_N', $tables_cert_n)@g;
390 s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g;
391 s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g;
392 s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g;
393 s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g;" ${web_path}__/Obj/brisk.phh
395 sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
397 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@g" ${web_path}__/commons.js
399 sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/xynt-streaming.js
401 document_root="$(grep DocumentRoot "${apache_conf}" | grep -v '^[ ]*#' | awk '{ print $2 }')"
402 sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
404 if [ -d ${web_path} ]; then
405 mv ${web_path} ${web_path}.old
408 if [ -d ../brisk-img ]; then
410 ./INSTALL.sh -w ${web_path}__
414 # config file installation or diff
415 if [ -f "$etc_path/$brisk_conf" ]; then
416 echo "Config file $etc_path/$brisk_conf exists."
417 echo "=== Dump the diff. ==="
418 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
419 diff -u <(cat "$etc_path/$brisk_conf" | egrep -v '^//|^#' | grep '\$[a-zA-Z_ ]\+=' | sed 's/ \+= .*/ = /g' | sort | uniq) <(cat "${web_path}__""/Obj/brisk.conf-templ.pho" | egrep -v '^//|^#' | grep '\$[a-zA-Z_ ]\+=' | sed 's/ \+= .*/ = /g' | sort | uniq )
420 echo "=== End dump. ==="
422 echo "Config file $etc_path/$brisk_conf not exists."
423 echo "Install a template."
424 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
427 mv ${web_path}__ ${web_path}
428 if [ -d ${web_path}.old ]; then
429 rm -rf ${web_path}.old
431 if [ "$web_only" = "FALSE" ]; then
432 mv "$ftokk_path" "$ftok_path"
434 if [ -f WARNING.txt ]; then
435 echo ; echo " ==== WARNING ===="