6 CONFIG_FILE="$HOME/.brisk_install"
8 apache_conf="/etc/apache2/sites-available/default"
13 brisk_auth_conf="brisk_spu_auth.conf.pho"
15 # brisk_debug="0xffff"
16 web_path="/home/nastasi/web/brisk"
17 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
18 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
19 usock_path="/home/nastasi/brisk-priv/brisk.sock"
21 legal_path="/home/nastasi/brisk-priv/brisk"
23 brisk_conf="brisk_spu.conf.pho"
31 echo "$1 chk - run lintian on all ph* files."
32 echo "$1 pkg - build brisk packages."
33 echo "$1 [-W] [-n 3|5] [-c 3|8] [-t <(n>=4)>] [-T <auth_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>]"
35 echo " -f use this config file"
36 echo " -p save preferences in the file"
37 echo " -W web files only"
38 echo " -A apache_conf - def. $apache_conf"
39 echo " -c number cards in hand - def. $card_hand"
40 echo " -n number of players - def. $players_n"
41 echo " -t number of tables - def. $tables_n"
42 echo " -T number of auth-only tables - def. $tables_auth_n"
43 echo " -a authorization file name - def. \"$brisk_auth_conf\""
44 echo " -d activate dabug - def. $brisk_debug"
45 echo " -w dir where place the web tree - def. \"$web_path\""
46 echo " -k dir where place ftok files - def. \"$ftok_path\""
47 echo " -l dir where save logs - def. \"$legal_path\""
48 echo " -y dir where place proxy files - def. \"$proxy_path\""
49 echo " -P prefix path - def. \"$prefix_path\""
50 echo " -C config filename - def. \"$brisk_conf\""
51 echo " -U unix socket path - def. \"$usock_path\""
52 echo " -u system user to run brisk dae - def. \"$sys_user\""
56 function get_param () {
57 echo "X$2" | grep -q "^X$1\$"
70 function searchetc() {
76 while [ "$pp" != "/" ]; do
77 if [ -d "$pp/$dname" ]; then
90 if [ "$1" = "chk" ]; then
95 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
99 taggit="$(git describe --tags | sed 's/^v//g')"
100 tagphp="$(grep "^\$G_brisk_version = " web/Obj/brisk.phh | sed 's/^[^"]\+"//g;s/".*//g')"
101 if [ "$taggit" != "v$tagphp" ]; then
103 echo "WARNING: taggit: [$taggit] tagphp: [$tagphp]"
109 # before all check errors on the sources
112 if [ "$1" = "pkg" ]; then
113 if [ "$2" != "" ]; then
116 tag="$(git describe)"
118 nam1="brisk_${tag}.tgz"
119 nam2="brisk-img_${tag}.tgz"
120 echo "Build packages ${nam1} and ${nam2}."
121 read -p "Proceed [y/n]: " a
122 if [ "$a" != "y" -a "$a" != "Y" ]; then
125 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
127 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
132 if [ -f "$CONFIG_FILE" ]; then
133 source "$CONFIG_FILE"
136 if [ "x$prefix_path" = "x" ]; then
137 prefix_path="$web_path"
141 while [ $# -gt 0 ]; do
142 # echo aa $1 xx $2 bb
145 -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;;
146 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
147 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
148 -c*) card_hand="$(get_param "-c" "$1" "$2")"; sh=$?;;
149 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
150 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
151 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
152 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
153 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
154 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
155 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
156 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
157 -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
158 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
159 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
160 -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
161 -u*) sys_user="$(get_param "-u" "$1" "$2")"; sh=$?;;
162 system) action=system;;
163 -W) web_only="TRUE";;
164 -h) usage $0; exit 0;;
165 *) usage $0; exit 1;;
167 if [ ! -z "$conffile" ]; then
168 if [ ! -f "$conffile" ]; then
169 echo "config file [$conffile] not found"
180 echo " outconf: \"$outconf\""
181 echo " apache_conf:\"$apache_conf\""
182 echo " card_hand: $card_hand"
183 echo " players_n: $players_n"
184 echo " tables_n: $tables_n"
185 echo " tables_auth_n: $tables_auth_n"
186 echo " brisk_auth_conf: \"$brisk_auth_conf\""
187 echo " brisk_debug:\"$brisk_debug\""
188 echo " web_path: \"$web_path\""
189 echo " ftok_path: \"$ftok_path\""
190 echo " legal_path: \"$legal_path\""
191 echo " proxy_path: \"$proxy_path\""
192 echo " prefix_path:\"$prefix_path\""
193 echo " brisk_conf: \"$brisk_conf\""
194 echo " usock_path: \"$usock_path\""
195 echo " sys_user: \"$sys_user\""
196 echo " web_only: \"$web_only\""
198 if [ ! -z "$outconf" ]; then
201 echo "# Produced automatically by brisk::INSTALL.sh"
203 echo "apache_conf=$apache_conf"
204 echo "card_hand=$card_hand"
205 echo "players_n=$players_n"
206 echo "tables_n=$tables_n"
207 echo "tables_auth_n=$tables_auth_n"
208 echo "brisk_auth_conf=\"$brisk_auth_conf\""
209 echo "brisk_debug=\"$brisk_debug\""
210 echo "web_path=\"$web_path\""
211 echo "ftok_path=\"$ftok_path\""
212 echo "proxy_path=\"$proxy_path\""
213 echo "legal_path=\"$legal_path\""
214 echo "prefix_path=\"$prefix_path\""
215 echo "brisk_conf=\"$brisk_conf\""
216 echo "usock_path=\"$usock_path\""
217 echo "sys_user=\"$sys_user\""
218 echo "web_only=\"$web_only\""
222 max_players=$((40 + players_n * tables_n))
224 if [ "$action" = "system" ]; then
225 scrname="$(echo "$prefix_path" | sed 's@^/@@g;s@/$@@g;s@/@_@g;')"
227 echo "script name: [$scrname]"
228 echo "brisk path: [$web_path]"
229 echo "private path: [$legal_path]"
230 echo "system user: [$sys_user]"
232 read -p "press enter to continue" sure
233 cp bin/brisk-init.sh brisk-init.sh.wrk
234 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
236 su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}"
241 echo "DON'T FORGET: after the first installation you MUST configure your run-levels accordingly"
243 echo "Example: su -c 'update-rc.d $scrname defaults'"
250 # check for etc path existence
251 dsta="$(dirname "$web_path")"
252 etc_path="$(searchetc "$dsta" Etc)"
253 if [ $? -ne 0 ]; then
254 echo "Etc directory not found"
263 ftokk_path="${ftok_path}k"
265 if [ $card_hand -lt 3 -o $card_hand -gt 8 ]; then
266 echo "card_hand ($card_hand) out of range (3 <= c <= 8)"
270 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
271 echo "players_n ($players_n) out of range (3|5)"
275 if [ "$web_only" = "FALSE" ]; then
276 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
277 echo "ftok_path (\"$ftok_path\") not exists"
280 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
281 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
284 if [ -d "$ftok_path" ]; then
285 mv "$ftok_path" "$ftokk_path"
287 touch $ftokk_path/spy.txt >/dev/null 2>&1
288 if [ $? -ne 0 ]; then
289 echo "ftokk_path (\"$ftokk_path\") write not allowed."
292 rm $ftokk_path/spy.txt
294 # create the fs subtree to enable ftok-ing
295 touch ${ftokk_path}/main
296 chmod 666 ${ftokk_path}/main
297 touch ${ftokk_path}/challenges
298 chmod 666 ${ftokk_path}/challenges
299 touch ${ftokk_path}/hardbans
300 chmod 666 ${ftokk_path}/hardbans
301 touch ${ftokk_path}/warrant
302 chmod 666 ${ftokk_path}/warrant
303 touch ${ftokk_path}/poll
304 chmod 666 ${ftokk_path}/poll
305 for i in $(seq 0 $max_players); do
306 touch ${ftokk_path}/user$i
307 chmod 666 ${ftokk_path}/user$i
310 if [ ! -d ${ftokk_path}/bin5 ]; then
311 mkdir ${ftokk_path}/bin5
312 chmod 777 ${ftokk_path}/bin5
315 for i in $(seq 0 $((tables_n - 1))); do
316 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
317 mkdir ${ftokk_path}/bin5/table$i
319 chmod 777 ${ftokk_path}/bin5/table$i
320 touch ${ftokk_path}/bin5/table$i/table
321 chmod 666 ${ftokk_path}/bin5/table$i/table
322 for e in $(seq 0 4); do
323 touch ${ftokk_path}/bin5/table$i/user$e
324 chmod 666 ${ftokk_path}/bin5/table$i/user$e
326 # create subdirectories in proxy path
327 if [ ! -d ${proxy_path}/bin5/table$i ]; then
328 mkdir -p ${proxy_path}/bin5/table$i
331 chmod -R 777 ${proxy_path}/bin5
334 install -d ${web_path}__
335 for i in $(find web -type d | sed 's/^....//g'); do
336 install -d ${web_path}__/$i
339 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
340 install -m 644 "web/$i" "${web_path}__/$i"
342 chmod 755 "${web_path}__/spush/brisk-spush.php"
344 prefix_path_len=$(echo -n "$prefix_path" | wc -c)
346 if [ $players_n -eq 5 ]; then
353 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]\+' {} \;)
354 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]\+' {} \;)
356 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]\+' {} \;)
358 # .ph[pho] substitutions
359 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]\+ *)" {} \;)
361 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]\+ *)" {} \;)
363 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]\+ *)" {} \;)
365 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',[^)]*)" {} \;)
367 sed -i "s@define *( *'SITE_PREFIX',[^)]*)@define('SITE_PREFIX', \"$prefix_path\")@g" ${web_path}__/Obj/sac-a-push.phh
369 sed -i "s@define *( *'SITE_PREFIX_LEN',[^)]*)@define('SITE_PREFIX_LEN', $prefix_path_len)@g" ${web_path}__/Obj/sac-a-push.phh
371 sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}__/spush/brisk-spush.phh
373 sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g" ${web_path}__/Obj/brisk.phh
375 sed -i "s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
377 sed -i "s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
379 sed -i "s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
381 sed -i "s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
383 sed -i "s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
385 sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
387 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@g" ${web_path}__/commons.js
389 sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}__/xynt-streaming.js
391 document_root="$(grep DocumentRoot "${apache_conf}" | grep -v '^[ ]*#' | awk '{ print $2 }')"
392 sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
394 if [ -d ${web_path} ]; then
395 mv ${web_path} ${web_path}.old
398 if [ -d ../brisk-img ]; then
400 ./INSTALL.sh -w ${web_path}__
404 # config file installation or diff
405 if [ -f "$etc_path/$brisk_conf" ]; then
406 echo "Config file $etc_path/$brisk_conf exists."
407 echo "=== Dump the diff. ==="
408 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
409 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 )
410 echo "=== End dump. ==="
412 echo "Config file $etc_path/$brisk_conf not exists."
413 echo "Install a template."
414 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
417 mv ${web_path}__ ${web_path}
418 if [ -d ${web_path}.old ]; then
419 rm -rf ${web_path}.old
421 if [ "$web_only" = "FALSE" ]; then
422 mv "$ftokk_path" "$ftok_path"
424 if [ -f WARNING.txt ]; then
425 echo ; echo " ==== WARNING ===="