6 CONFIG_FILE="$HOME/.brisk_install"
11 brisk_auth_conf="brisk_auth.conf.pho"
13 # brisk_debug="0xffff"
14 web_path="/home/nastasi/web/brisk"
15 ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
16 proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
17 legal_path="/home/nastasi/brisk-priv/brisk"
19 brisk_conf="brisk.conf.pho"
23 if [ "$1" = "chk" ]; then
28 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
34 # before all check errors on the sources
37 if [ "$1" = "pkg" ]; then
38 if [ "$2" != "" ]; then
43 nam1="brisk_${tag}.tgz"
44 nam2="brisk-img_${tag}.tgz"
45 echo "Build packages ${nam1} and ${nam2}."
46 read -p "Proceed [y/n]: " a
47 if [ "$a" != "y" -a "$a" != "Y" ]; then
50 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
52 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
57 if [ -f "$CONFIG_FILE" ]; then
61 if [ "x$cookie_path" = "x" ]; then
68 echo "$1 chk - run lintian on all ph* files."
69 echo "$1 pkg - build brisk packages."
70 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>]"
72 echo " -f use this config file"
73 echo " -p save preferences in the file"
74 echo " -W web files only"
75 echo " -n number of players - def. $players_n"
76 echo " -t number of tables - def. $tables_n"
77 echo " -T number of auth-only tables - def. $tables_auth_n"
78 echo " -a authorization file name - def. \"$brisk_auth_conf\""
79 echo " -d activate dabug - def. $brisk_debug"
80 echo " -w dir where place the web tree - def. \"$web_path\""
81 echo " -k dir where place ftok files - def. \"$ftok_path\""
82 echo " -l dir where save logs - def. \"$legal_path\""
83 echo " -y dir where place proxy files - def. \"$proxy_path\""
84 echo " -c cookie path - def. \"$cookie_path\""
85 echo " -C config filename - def. \"$brisk_conf\""
90 function get_param () {
91 echo "X$2" | grep -q "^X$1\$"
104 function searchetc() {
105 local dstart dname pp
110 while [ "$pp" != "/" ]; do
111 if [ -d "$pp/$dname" ]; then
115 pp="$(dirname "$pp")"
124 while [ $# -gt 0 ]; do
125 # echo aa $1 xx $2 bb
128 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
129 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
130 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
131 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
132 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
133 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
134 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
135 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
136 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
137 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
138 -c*) cookie_path="$(get_param "-c" "$1" "$2")"; sh=$?;;
139 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
140 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
141 -W) web_only="TRUE";;
142 -h) usage $0; exit 0;;
143 *) usage $0; exit 1;;
145 if [ ! -z "$conffile" ]; then
146 if [ ! -f "$conffile" ]; then
147 echo "config file [$conffile] not found"
158 echo " outconf: \"$outconf\""
159 echo " players_n: $players_n"
160 echo " tables_n: $tables_n"
161 echo " tables_auth_n: $tables_auth_n"
162 echo " brisk_auth_conf: \"$brisk_auth_conf\""
163 echo " brisk_debug:\"$brisk_debug\""
164 echo " web_path: \"$web_path\""
165 echo " ftok_path: \"$ftok_path\""
166 echo " legal_path: \"$legal_path\""
167 echo " proxy_path: \"$proxy_path\""
168 echo " cookie_path:\"$cookie_path\""
169 echo " brisk_conf:\"$brisk_conf\""
170 echo " web_only: \"$web_only\""
172 if [ ! -z "$outconf" ]; then
175 echo "# Produced automatically by brisk::INSTALL.sh"
177 echo "players_n=$players_n"
178 echo "tables_n=$tables_n"
179 echo "tables_auth_n=$tables_auth_n"
180 echo "brisk_auth_conf=\"$brisk_auth_conf\""
181 echo "brisk_debug=\"$brisk_debug\""
182 echo "web_path=\"$web_path\""
183 echo "ftok_path=\"$ftok_path\""
184 echo "proxy_path=\"$proxy_path\""
185 echo "legal_path=\"$legal_path\""
186 echo "cookie_path=\"$cookie_path\""
187 echo "brisk_conf=\"$brisk_conf\""
188 echo "web_only=\"$web_only\""
192 max_players=$((40 + players_n * tables_n))
196 # check for etc path existence
197 dsta="$(dirname "$web_path")"
198 etc_path="$(searchetc "$dsta" Etc)"
199 if [ $? -ne 0 ]; then
200 echo "Etc directory not found"
209 ftokk_path="${ftok_path}k"
211 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
212 echo "players_n ($players_n) out of range (3|5)"
216 if [ "$web_only" = "FALSE" ]; then
217 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
218 echo "ftok_path (\"$ftok_path\") not exists"
221 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
222 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
225 if [ -d "$ftok_path" ]; then
226 mv "$ftok_path" "$ftokk_path"
228 touch $ftokk_path/spy.txt >/dev/null 2>&1
229 if [ $? -ne 0 ]; then
230 echo "ftokk_path (\"$ftokk_path\") write not allowed."
233 rm $ftokk_path/spy.txt
235 # create the fs subtree to enable ftok-ing
236 touch ${ftokk_path}/main
237 chmod 666 ${ftokk_path}/main
238 touch ${ftokk_path}/challenges
239 chmod 666 ${ftokk_path}/challenges
240 touch ${ftokk_path}/hardbans
241 chmod 666 ${ftokk_path}/hardbans
242 touch ${ftokk_path}/warrant
243 chmod 666 ${ftokk_path}/warrant
244 touch ${ftokk_path}/poll
245 chmod 666 ${ftokk_path}/poll
246 for i in $(seq 0 $max_players); do
247 touch ${ftokk_path}/user$i
248 chmod 666 ${ftokk_path}/user$i
251 if [ ! -d ${ftokk_path}/bin5 ]; then
252 mkdir ${ftokk_path}/bin5
253 chmod 777 ${ftokk_path}/bin5
256 for i in $(seq 0 $((tables_n - 1))); do
257 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
258 mkdir ${ftokk_path}/bin5/table$i
260 chmod 777 ${ftokk_path}/bin5/table$i
261 touch ${ftokk_path}/bin5/table$i/table
262 chmod 666 ${ftokk_path}/bin5/table$i/table
263 for e in $(seq 0 4); do
264 touch ${ftokk_path}/bin5/table$i/user$e
265 chmod 666 ${ftokk_path}/bin5/table$i/user$e
267 # create subdirectories in proxy path
268 if [ ! -d ${proxy_path}/bin5/table$i ]; then
269 mkdir -p ${proxy_path}/bin5/table$i
272 chmod -R 777 ${proxy_path}/bin5
275 install -d ${web_path}__
276 for i in $(find web -type d | sed 's/^....//g'); do
277 install -d ${web_path}__/$i
280 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
281 install -m 644 "web/$i" "${web_path}__/$i"
284 if [ $players_n -eq 5 ]; then
291 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]\+' {} \;)
293 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]\+' {} \;)
295 # .ph[pho] substitutions
296 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]\+ *)' {} \;)
298 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]\+ *)' {} \;)
300 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,[^)]*)' {} \;)
302 sed -i "s@define *( *TABLES_N,[^)]*)@define(TABLES_N, $tables_n)@g" ${web_path}__/Obj/brisk.phh
304 sed -i "s@define *( *TABLES_AUTH_N,[^)]*)@define(TABLES_AUTH_N, $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
306 sed -i "s@define *( *BRISK_DEBUG,[^)]*)@define(BRISK_DEBUG, $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
308 sed -i "s@define *( *LEGAL_PATH,[^)]*)@define(LEGAL_PATH, \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
310 sed -i "s@define *( *PROXY_PATH,[^)]*)@define(PROXY_PATH, \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
312 sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
314 sed -i "s@define *( *BRISK_AUTH_CONF,[^)]*)@define(BRISK_AUTH_CONF, \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
316 sed -i "s@\( \+xhr_rd_cookiepath *: *\)\"[^\"]*\" *,@\1 \"$cookie_path\",@g" ${web_path}__/http_streaming.js
317 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
319 if [ -d ${web_path} ]; then
320 mv ${web_path} ${web_path}.old
323 if [ -d ../brisk-img ]; then
325 ./INSTALL.sh -w ${web_path}__
329 # config file installation or diff
330 if [ -f "$etc_path/$brisk_conf" ]; then
331 echo "Config file $etc_path/$brisk_conf exists."
332 echo "=== Dump the diff. ==="
333 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
334 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 )
335 echo "=== End dump. ==="
337 echo "Config file $etc_path/$brisk_conf not exists."
338 echo "Install a template."
339 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
342 mv ${web_path}__ ${web_path}
343 if [ -d ${web_path}.old ]; then
344 rm -rf ${web_path}.old
346 if [ "$web_only" = "FALSE" ]; then
347 mv "$ftokk_path" "$ftok_path"