6 CONFIG_FILE="$HOME/.brisk_install"
8 apache_conf="/etc/apache2/sites-available/default"
15 brisk_auth_conf="brisk_spu_auth.conf.pho"
17 # brisk_debug="0xffff"
18 web_path="/home/nastasi/web/brisk"
19 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
20 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
21 usock_path="/home/nastasi/brisk-priv/brisk.sock"
23 legal_path="/home/nastasi/brisk-priv/brisk"
25 brisk_conf="brisk_spu.conf.pho"
33 echo "$1 chk - run lintian on all ph* files."
34 echo "$1 pkg - build brisk packages."
35 echo "$1 [-W] [-n 3|5] [-c 2|8] [-t <(n>=4)>] [-T <auth_tab>] [-r <appr_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]"
37 echo " -f use this config file"
38 echo " -p save preferences in the file"
39 echo " -W web files only"
40 echo " -A apache_conf - def. $apache_conf"
41 echo " -c number cards in hand - def. $card_hand"
42 echo " -n number of players - def. $players_n"
43 echo " -t number of tables - def. $tables_n"
44 echo " -r number of appr-only tables - def. $tables_appr_n"
45 echo " -T number of auth-only tables - def. $tables_auth_n"
46 echo " -G number of cert-only tables - def. $tables_cert_n"
47 echo " -a authorization file name - def. \"$brisk_auth_conf\""
48 echo " -d activate dabug - def. $brisk_debug"
49 echo " -w dir where place the web tree - def. \"$web_path\""
50 echo " -k dir where place ftok files - def. \"$ftok_path\""
51 echo " -l dir where save logs - def. \"$legal_path\""
52 echo " -y dir where place proxy files - def. \"$proxy_path\""
53 echo " -P prefix path - def. \"$prefix_path\""
54 echo " -C config filename - def. \"$brisk_conf\""
55 echo " -U unix socket path - def. \"$usock_path\""
56 echo " -u system user to run brisk dae - def. \"$sys_user\""
57 echo " -x copy tests as normal php - def. \"$test_add\""
61 function get_param () {
62 echo "X$2" | grep -q "^X$1\$"
75 function searchetc() {
81 while [ "$pp" != "/" ]; do
82 if [ -d "$pp/$dname" ]; then
96 if [ "$1" = "chk" ]; then
101 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
105 taggit="$(git describe --tags | sed 's/^v//g')"
106 tagphp="$(grep "^\$G_brisk_version = " web/Obj/brisk.phh | sed 's/^[^"]\+"//g;s/".*//g')" # ' emacs hell
107 if [ "$taggit" != "$tagphp" ]; then
109 echo "WARNING: taggit: [$taggit] tagphp: [$tagphp]"
115 # before all check errors on the sources
117 if [ "$1" = "pkg" ]; then
118 if [ "$2" != "" ]; then
121 tag="$(git describe)"
123 nam=("brisk" "brisk-img" "fieldify")
126 if [ -d ../curl-de-sac ]; then
127 nam[$nam_idx]="curl-de-sac"
128 nam_idx=$((nam_idx + 1))
132 for i in $( seq 0 $((${#nam[@]} - 1)) ); do
134 nam_gz[$i]="${nam[$i]}_${tag}.tgz"
135 pkg_list="${pkg_list}${sep}${nam_gz[$i]}"
139 echo "Build packages ${pkg_list} ."
140 read -p "Proceed [y/n]: " a
141 if [ "$a" != "y" -a "$a" != "Y" ]; then
144 for i in $( seq 0 $((${#nam[@]} - 1)) ); do
146 git archive --format=tar --prefix=brisk-${tag}/${nam[$i]}/ $tag | gzip > ../${nam_gz[$i]}
152 if [ -f "$CONFIG_FILE" ]; then
153 source "$CONFIG_FILE"
154 conffile_in="$CONFIG_FILE"
157 if [ "x$prefix_path" = "x" ]; then
158 prefix_path="$web_path"
162 while [ $# -gt 0 ]; do
163 # echo aa $1 xx $2 bb
166 -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;;
167 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
168 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
169 -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;;
170 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
171 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
172 -r*) tables_appr_n="$(get_param "-r" "$1" "$2")"; sh=$?;;
173 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
174 -G*) tables_cert_n="$(get_param "-G" "$1" "$2")"; sh=$?;;
175 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
176 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
177 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
178 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
179 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
180 -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
181 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
182 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
183 -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
184 -u*) sys_user="$(get_param "-u" "$1" "$2")"; sh=$?;;
185 system) action=system;;
186 -W) web_only="TRUE";;
187 -x) test_add="TRUE";;
188 -h) usage $0; exit 0;;
189 *) usage $0; exit 1;;
191 if [ ! -z "$conffile" ]; then
192 if [ ! -f "$conffile" ]; then
193 echo "config file [$conffile] not found"
197 conffile_in="$conffile"
205 echo " outconf: \"$outconf\""
206 echo " apache_conf:\"$apache_conf\""
207 echo " card_hand: $card_hand"
208 echo " players_n: $players_n"
209 echo " tables_n: $tables_n"
210 echo " tables_appr_n: $tables_appr_n"
211 echo " tables_auth_n: $tables_auth_n"
212 echo " tables_cert_n: $tables_cert_n"
213 echo " brisk_auth_conf: \"$brisk_auth_conf\""
214 echo " brisk_debug:\"$brisk_debug\""
215 echo " web_path: \"$web_path\""
216 echo " ftok_path: \"$ftok_path\""
217 echo " legal_path: \"$legal_path\""
218 echo " proxy_path: \"$proxy_path\""
219 echo " prefix_path:\"$prefix_path\""
220 echo " brisk_conf: \"$brisk_conf\""
221 echo " usock_path: \"$usock_path\""
222 echo " sys_user: \"$sys_user\""
223 echo " web_only: \"$web_only\""
224 echo " test_add: \"$test_add\""
226 if [ ! -z "$outconf" ]; then
229 echo "# Produced automatically by brisk::INSTALL.sh"
231 echo "apache_conf=$apache_conf"
232 echo "card_hand=$card_hand"
233 echo "players_n=$players_n"
234 echo "tables_n=$tables_n"
235 echo "tables_appr_n=$tables_appr_n"
236 echo "tables_auth_n=$tables_auth_n"
237 echo "tables_cert_n=$tables_cert_n"
238 echo "brisk_auth_conf=\"$brisk_auth_conf\""
239 echo "brisk_debug=\"$brisk_debug\""
240 echo "web_path=\"$web_path\""
241 echo "ftok_path=\"$ftok_path\""
242 echo "proxy_path=\"$proxy_path\""
243 echo "legal_path=\"$legal_path\""
244 echo "prefix_path=\"$prefix_path\""
245 echo "brisk_conf=\"$brisk_conf\""
246 echo "usock_path=\"$usock_path\""
247 echo "sys_user=\"$sys_user\""
248 echo "web_only=\"$web_only\""
249 echo "test_add=\"$test_add\""
253 max_players=$((40 + players_n * tables_n))
255 if [ "$action" = "system" ]; then
256 scrname="$(echo "$prefix_path" | sed 's@^/@@g;s@/$@@g;s@/@_@g;')"
258 echo "script name: [$scrname]"
259 echo "brisk path: [$web_path]"
260 echo "private path: [$legal_path]"
261 echo "system user: [$sys_user]"
263 read -p "press enter to continue" sure
264 cp bin/brisk-init.sh brisk-init.sh.wrk
265 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
267 su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}"
272 echo "DON'T FORGET: after the first installation you MUST configure your run-levels accordingly"
274 echo "Example: su -c 'update-rc.d $scrname defaults'"
281 # check for etc path existence
282 dsta="$(dirname "$web_path")"
283 etc_path="$(searchetc "$dsta" Etc)"
284 if [ $? -ne 0 ]; then
285 echo "Etc directory not found"
294 ftokk_path="${ftok_path}k"
296 if [ $card_hand -lt 2 -o $card_hand -gt 8 ]; then
297 echo "card_hand ($card_hand) out of range (2 <= c <= 8)"
301 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
302 echo "players_n ($players_n) out of range (3|5)"
306 if [ "$web_only" = "FALSE" ]; then
307 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
308 echo "ftok_path (\"$ftok_path\") not exists"
311 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
312 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
315 if [ -d "$ftok_path" ]; then
316 mv "$ftok_path" "$ftokk_path"
318 touch $ftokk_path/spy.txt >/dev/null 2>&1
319 if [ $? -ne 0 ]; then
320 echo "ftokk_path (\"$ftokk_path\") write not allowed."
323 rm $ftokk_path/spy.txt
325 # create the fs subtree to enable ftok-ing
326 touch ${ftokk_path}/main
327 chmod 666 ${ftokk_path}/main
328 touch ${ftokk_path}/challenges
329 chmod 666 ${ftokk_path}/challenges
330 touch ${ftokk_path}/hardbans
331 chmod 666 ${ftokk_path}/hardbans
332 touch ${ftokk_path}/warrant
333 chmod 666 ${ftokk_path}/warrant
334 touch ${ftokk_path}/poll
335 chmod 666 ${ftokk_path}/poll
336 for i in $(seq 0 $max_players); do
337 touch ${ftokk_path}/user$i
338 chmod 666 ${ftokk_path}/user$i
341 if [ ! -d ${ftokk_path}/bin5 ]; then
342 mkdir ${ftokk_path}/bin5
343 chmod 777 ${ftokk_path}/bin5
346 for i in $(seq 0 $((tables_n - 1))); do
347 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
348 mkdir ${ftokk_path}/bin5/table$i
350 chmod 777 ${ftokk_path}/bin5/table$i
351 touch ${ftokk_path}/bin5/table$i/table
352 chmod 666 ${ftokk_path}/bin5/table$i/table
353 for e in $(seq 0 4); do
354 touch ${ftokk_path}/bin5/table$i/user$e
355 chmod 666 ${ftokk_path}/bin5/table$i/user$e
357 # create subdirectories in proxy path
358 if [ ! -d ${proxy_path}/bin5/table$i ]; then
359 mkdir -p ${proxy_path}/bin5/table$i
362 chmod -R 777 ${proxy_path}/bin5
365 install -d ${web_path}__
366 for i in $(find web -type d | grep '/' | sed 's/^....//g'); do
367 install -d ${web_path}__/$i
370 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
371 install -m 644 "web/$i" "${web_path}__/$i"
373 if [ "$test_add" = "TRUE" ]; then
374 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
375 install -m 644 "webtest/$i" "${web_path}__/$i"
379 chmod 755 "${web_path}__/spush/brisk-spush.php"
381 prefix_path_len=$(echo -n "$prefix_path" | wc -c)
383 if [ $players_n -eq 5 ]; then
390 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]\+' {} \;)
391 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]\+' {} \;)
393 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]\+' {} \;)
395 # .ph[pho] substitutions
396 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]\+ *)" {} \;)
398 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]\+ *)" {} \;)
400 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]\+ *)" {} \;)
402 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',[^)]*)" {} \;)
404 sed -i "s@define *( *'SITE_PREFIX',[^)]*)@define('SITE_PREFIX', \"$prefix_path\")@g;
405 s@define *( *'SITE_PREFIX_LEN',[^)]*)@define('SITE_PREFIX_LEN', $prefix_path_len)@g" ${web_path}__/Obj/sac-a-push.phh
407 sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}__/spush/brisk-spush.phh
409 sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g;
410 s@define *( *'TABLES_APPR_N',[^)]*)@define('TABLES_APPR_N', $tables_appr_n)@g;
411 s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g;
412 s@define *( *'TABLES_CERT_N',[^)]*)@define('TABLES_CERT_N', $tables_cert_n)@g;
413 s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g;
414 s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g;
415 s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g;
416 s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g;" ${web_path}__/Obj/brisk.phh
418 sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
420 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@g" ${web_path}__/commons.js
422 sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/xynt-streaming.js
424 document_root="$(grep DocumentRoot "${apache_conf}" | grep -v '^[ ]*#' | awk '{ print $2 }')"
425 sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
427 if [ -d ../fieldify ]; then
430 ./INSTALL.sh -s "$pw" -w ${web_path}__
433 if [ -d ../brisk-img ]; then
435 ./INSTALL.sh -w ${web_path}__
438 if [ -d ../curl-de-sac ]; then
440 if [ ! -z "$conffile_in" ]; then
441 ./INSTALL.sh -f "$conffile_in" -w ${web_path}__
443 ./INSTALL.sh -w ${web_path}__
448 # config file installation or diff
449 if [ -f "$etc_path/$brisk_conf" ]; then
450 echo "Config file $etc_path/$brisk_conf exists."
451 echo "=== Dump the diff. ==="
452 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
453 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 )
454 echo "=== End dump. ==="
456 echo "Config file $etc_path/$brisk_conf not exists."
457 echo "Install a template."
458 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
461 if [ -d ${web_path} ]; then
462 mv ${web_path} ${web_path}.old
465 mv ${web_path}__ ${web_path}
466 if [ -d ${web_path}.old ]; then
467 rm -rf ${web_path}.old
469 if [ "$web_only" = "FALSE" ]; then
470 mv "$ftokk_path" "$ftok_path"
472 if [ -f WARNING.txt ]; then
473 echo ; echo " ==== WARNING ===="