6 CONFIG_FILE="$HOME/.brisk_install"
8 apache_path="/etc/apache2/sites-available/"
14 brisk_auth_conf="brisk_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 legal_path="/home/nastasi/brisk-priv/brisk"
22 brisk_conf="brisk.conf.pho"
26 if [ "$1" = "chk" ]; then
31 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
37 # before all check errors on the sources
40 if [ "$1" = "pkg" ]; then
41 if [ "$2" != "" ]; then
46 nam1="brisk_${tag}.tgz"
47 nam2="brisk-img_${tag}.tgz"
48 echo "Build packages ${nam1} and ${nam2}."
49 read -p "Proceed [y/n]: " a
50 if [ "$a" != "y" -a "$a" != "Y" ]; then
53 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
55 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
60 if [ -f "$CONFIG_FILE" ]; then
64 if [ "x$cookie_path" = "x" ]; then
71 echo "$1 chk - run lintian on all ph* files."
72 echo "$1 pkg - build brisk packages."
73 echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-a <auth_file_name>] [-f conffile] [-p outconf] [-d TRUE|FALSE] [-w web_dir] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-c <cookie_path>]"
75 echo " -f use this config file"
76 echo " -p save preferences in the file"
77 echo " -W web files only"
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 " -c cookie path - def. \"$cookie_path\""
88 echo " -C config filename - def. \"$brisk_conf\""
93 function get_param () {
94 echo "X$2" | grep -q "^X$1\$"
101 echo "$2" | cut -c 3-
107 function searchetc() {
108 local dstart dname pp
113 while [ "$pp" != "/" ]; do
114 if [ -d "$pp/$dname" ]; then
118 pp="$(dirname "$pp")"
127 while [ $# -gt 0 ]; do
128 # echo aa $1 xx $2 bb
131 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
132 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
133 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
134 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
135 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
136 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
137 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
138 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
139 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
140 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
141 -c*) cookie_path="$(get_param "-c" "$1" "$2")"; sh=$?;;
142 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
143 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
144 -W) web_only="TRUE";;
145 -h) usage $0; exit 0;;
146 *) usage $0; exit 1;;
148 if [ ! -z "$conffile" ]; then
149 if [ ! -f "$conffile" ]; then
150 echo "config file [$conffile] not found"
161 echo " outconf: \"$outconf\""
162 echo " players_n: $players_n"
163 echo " tables_n: $tables_n"
164 echo " tables_auth_n: $tables_auth_n"
165 echo " brisk_auth_conf: \"$brisk_auth_conf\""
166 echo " brisk_debug:\"$brisk_debug\""
167 echo " web_path: \"$web_path\""
168 echo " ftok_path: \"$ftok_path\""
169 echo " legal_path: \"$legal_path\""
170 echo " proxy_path: \"$proxy_path\""
171 echo " cookie_path:\"$cookie_path\""
172 echo " brisk_conf:\"$brisk_conf\""
173 echo " web_only: \"$web_only\""
175 if [ ! -z "$outconf" ]; then
178 echo "# Produced automatically by brisk::INSTALL.sh"
180 echo "players_n=$players_n"
181 echo "tables_n=$tables_n"
182 echo "tables_auth_n=$tables_auth_n"
183 echo "brisk_auth_conf=\"$brisk_auth_conf\""
184 echo "brisk_debug=\"$brisk_debug\""
185 echo "web_path=\"$web_path\""
186 echo "ftok_path=\"$ftok_path\""
187 echo "proxy_path=\"$proxy_path\""
188 echo "legal_path=\"$legal_path\""
189 echo "cookie_path=\"$cookie_path\""
190 echo "brisk_conf=\"$brisk_conf\""
191 echo "web_only=\"$web_only\""
195 max_players=$((40 + players_n * tables_n))
199 # check for etc path existence
200 dsta="$(dirname "$web_path")"
201 etc_path="$(searchetc "$dsta" Etc)"
202 if [ $? -ne 0 ]; then
203 echo "Etc directory not found"
212 ftokk_path="${ftok_path}k"
214 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
215 echo "players_n ($players_n) out of range (3|5)"
219 if [ "$web_only" = "FALSE" ]; then
220 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
221 echo "ftok_path (\"$ftok_path\") not exists"
224 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
225 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
228 if [ -d "$ftok_path" ]; then
229 mv "$ftok_path" "$ftokk_path"
231 touch $ftokk_path/spy.txt >/dev/null 2>&1
232 if [ $? -ne 0 ]; then
233 echo "ftokk_path (\"$ftokk_path\") write not allowed."
236 rm $ftokk_path/spy.txt
238 # create the fs subtree to enable ftok-ing
239 touch ${ftokk_path}/main
240 chmod 666 ${ftokk_path}/main
241 touch ${ftokk_path}/challenges
242 chmod 666 ${ftokk_path}/challenges
243 touch ${ftokk_path}/hardbans
244 chmod 666 ${ftokk_path}/hardbans
245 touch ${ftokk_path}/warrant
246 chmod 666 ${ftokk_path}/warrant
247 touch ${ftokk_path}/poll
248 chmod 666 ${ftokk_path}/poll
249 for i in $(seq 0 $max_players); do
250 touch ${ftokk_path}/user$i
251 chmod 666 ${ftokk_path}/user$i
254 if [ ! -d ${ftokk_path}/bin5 ]; then
255 mkdir ${ftokk_path}/bin5
256 chmod 777 ${ftokk_path}/bin5
259 for i in $(seq 0 $((tables_n - 1))); do
260 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
261 mkdir ${ftokk_path}/bin5/table$i
263 chmod 777 ${ftokk_path}/bin5/table$i
264 touch ${ftokk_path}/bin5/table$i/table
265 chmod 666 ${ftokk_path}/bin5/table$i/table
266 for e in $(seq 0 4); do
267 touch ${ftokk_path}/bin5/table$i/user$e
268 chmod 666 ${ftokk_path}/bin5/table$i/user$e
270 # create subdirectories in proxy path
271 if [ ! -d ${proxy_path}/bin5/table$i ]; then
272 mkdir -p ${proxy_path}/bin5/table$i
275 chmod -R 777 ${proxy_path}/bin5
278 install -d ${web_path}__
279 for i in $(find web -type d | sed 's/^....//g'); do
280 install -d ${web_path}__/$i
283 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
284 install -m 644 "web/$i" "${web_path}__/$i"
286 chmod 755 "${web_path}__/spush/brisk-spush.php"
288 if [ $players_n -eq 5 ]; then
295 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]\+' {} \;)
297 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]\+' {} \;)
299 # .ph[pho] substitutions
300 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]\+ *)' {} \;)
302 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]\+ *)' {} \;)
304 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',[^)]*)' {} \;)
306 sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g" ${web_path}__/Obj/brisk.phh
308 sed -i "s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
310 sed -i "s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
312 sed -i "s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
314 sed -i "s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
316 sed -i "s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
318 sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
320 sed -i "s@\( \+xhr_rd_cookiepath *: *\)\"[^\"]*\" *,@\1 \"$cookie_path\",@g" ${web_path}__/http_streaming.js
321 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
323 document_root="$(grep DocumentRoot "${apache_path}${apache_conf}" | awk '{ print $2 }')"
324 sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}__/spush/*.ph*
326 if [ -d ${web_path} ]; then
327 mv ${web_path} ${web_path}.old
330 if [ -d ../brisk-img ]; then
332 ./INSTALL.sh -w ${web_path}__
336 # config file installation or diff
337 if [ -f "$etc_path/$brisk_conf" ]; then
338 echo "Config file $etc_path/$brisk_conf exists."
339 echo "=== Dump the diff. ==="
340 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
341 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 )
342 echo "=== End dump. ==="
344 echo "Config file $etc_path/$brisk_conf not exists."
345 echo "Install a template."
346 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
349 mv ${web_path}__ ${web_path}
350 if [ -d ${web_path}.old ]; then
351 rm -rf ${web_path}.old
353 if [ "$web_only" = "FALSE" ]; then
354 mv "$ftokk_path" "$ftok_path"