9 brisk_auth_conf="brisk_auth2.conf.pho"
11 web_path="$HOME/brisk"
12 legal_path="$HOME/brisk-priv"
13 ftok_path="$HOME/brisk-priv/ftok"
14 proxy_path="$HOME/brisk-priv/proxy"
16 brisk_conf="brisk.conf.pho"
18 if [ "$1" = "chk" ]; then
23 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
29 # before all check errors on the sources
32 if [ "$1" = "pkg" ]; then
33 if [ "$2" != "" ]; then
38 nam1="brisk_${tag}.tgz"
39 nam2="brisk-img_${tag}.tgz"
40 echo "Build packages ${nam1} and ${nam2}."
41 read -p "Proceed [y/n]: " a
42 if [ "$a" != "y" -a "$a" != "Y" ]; then
45 git archive --format=tar --prefix=brisk-${tag}/brisk/ $tag | gzip > ../$nam1
47 git archive --format=tar --prefix=brisk-${tag}/brisk-img/ $tag | gzip > ../$nam2
52 if [ -f $HOME/.brisk_install ]; then
53 . $HOME/.brisk_install
56 if [ "x$cookie_path" = "x" ]; then
63 echo "$1 chk - run lintian on all ph* files."
64 echo "$1 pkg - build brisk packages."
65 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>]"
67 echo " -f use this config file"
68 echo " -p save preferences in the file"
69 echo " -W web files only"
70 echo " -n number of players - def. $players_n"
71 echo " -t number of tables - def. $tables_n"
72 echo " -T number of auth-only tables - def. $tables_auth_n"
73 echo " -a authorization file name - def. \"$brisk_auth_conf\""
74 echo " -d activate dabug - def. $brisk_debug"
75 echo " -w dir where place the web tree - def. \"$web_path\""
76 echo " -k dir where place ftok files - def. \"$ftok_path\""
77 echo " -l dir where save logs - def. \"$legal_path\""
78 echo " -y dir where place proxy files - def. \"$proxy_path\""
79 echo " -c cookie path - def. \"$cookie_path\""
80 echo " -C config filename - def. \"$brisk_conf\""
85 function get_param () {
86 echo "X$2" | grep -q "^X$1\$"
99 function searchetc() {
100 local dstart dname pp
105 while [ "$pp" != "/" ]; do
106 if [ -d "$pp/$dname" ]; then
110 pp="$(dirname "$pp")"
119 while [ $# -gt 0 ]; do
120 # echo aa $1 xx $2 bb
123 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
124 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
125 -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
126 -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
127 -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
128 -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
129 -d*) brisk_debug="$(get_param "-d" "$1" "$2")"; sh=$?;;
130 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
131 -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
132 -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
133 -c*) cookie_path="$(get_param "-c" "$1" "$2")"; sh=$?;;
134 -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
135 -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
136 -W) web_only="TRUE";;
137 -h) usage $0; exit 0;;
138 *) usage $0; exit 1;;
140 if [ ! -z "$conffile" ]; then
141 if [ ! -f "$conffile" ]; then
142 echo "config file [$conffile] not found"
153 echo " outconf: \"$outconf\""
154 echo " players_n: $players_n"
155 echo " tables_n: $tables_n"
156 echo " tables_auth_n: $tables_auth_n"
157 echo " brisk_auth_conf: \"$brisk_auth_conf\""
158 echo " brisk_debug:\"$brisk_debug\""
159 echo " web_path: \"$web_path\""
160 echo " ftok_path: \"$ftok_path\""
161 echo " legal_path: \"$legal_path\""
162 echo " proxy_path: \"$proxy_path\""
163 echo " cookie_path:\"$cookie_path\""
164 echo " brisk_conf:\"$brisk_conf\""
165 echo " web_only: \"$web_only\""
167 if [ ! -z "$outconf" ]; then
170 echo "# Produced automatically by brisk::INSTALL.sh"
172 echo "players_n=$players_n"
173 echo "tables_n=$tables_n"
174 echo "tables_auth_n=$tables_auth_n"
175 echo "brisk_auth_conf=\"$brisk_auth_conf\""
176 echo "brisk_debug=\"$brisk_debug\""
177 echo "web_path=\"$web_path\""
178 echo "ftok_path=\"$ftok_path\""
179 echo "proxy_path=\"$proxy_path\""
180 echo "legal_path=\"$legal_path\""
181 echo "cookie_path=\"$cookie_path\""
182 echo "brisk_conf=\"$brisk_conf\""
183 echo "web_only=\"$web_only\""
187 max_players=$((40 + players_n * tables_n))
191 # check for etc path existence
192 dsta="$(dirname "$web_path")"
193 etc_path="$(searchetc "$dsta" Etc)"
194 if [ $? -ne 0 ]; then
195 echo "Etc directory not found"
202 ftokk_path="${ftok_path}k"
204 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
205 echo "players_n ($players_n) out of range (3|5)"
209 if [ "$web_only" = "FALSE" ]; then
210 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
211 echo "ftok_path (\"$ftok_path\") not exists"
214 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
215 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
218 if [ -d "$ftok_path" ]; then
219 mv "$ftok_path" "$ftokk_path"
221 touch $ftokk_path/spy.txt >/dev/null 2>&1
222 if [ $? -ne 0 ]; then
223 echo "ftokk_path (\"$ftokk_path\") write not allowed."
226 rm $ftokk_path/spy.txt
228 # create the fs subtree to enable ftok-ing
229 touch ${ftokk_path}/main
230 chmod 666 ${ftokk_path}/main
231 touch ${ftokk_path}/challenges
232 chmod 666 ${ftokk_path}/challenges
233 touch ${ftokk_path}/hardbans
234 chmod 666 ${ftokk_path}/hardbans
235 touch ${ftokk_path}/warrant
236 chmod 666 ${ftokk_path}/warrant
237 touch ${ftokk_path}/poll
238 chmod 666 ${ftokk_path}/poll
239 for i in $(seq 0 $max_players); do
240 touch ${ftokk_path}/user$i
241 chmod 666 ${ftokk_path}/user$i
244 if [ ! -d ${ftokk_path}/bin5 ]; then
245 mkdir ${ftokk_path}/bin5
246 chmod 777 ${ftokk_path}/bin5
249 for i in $(seq 0 $max_players); do
250 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
251 mkdir ${ftokk_path}/bin5/table$i
253 chmod 777 ${ftokk_path}/bin5/table$i
254 touch ${ftokk_path}/bin5/table$i/table
255 chmod 666 ${ftokk_path}/bin5/table$i/table
256 for e in $(seq 0 4); do
257 touch ${ftokk_path}/bin5/table$i/user$e
258 chmod 666 ${ftokk_path}/bin5/table$i/user$e
262 # create subdirectories in proxy path
263 if [ ! -d ${proxy_path}/bin5 ]; then
264 mkdir ${proxy_path}/bin5
266 chmod 777 ${proxy_path}/bin5
268 install -d ${web_path}__
269 for i in $(find web -type d | grep -v /CVS | sed 's/^....//g'); do
270 install -d ${web_path}__/$i
273 for i in $(find web -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' | grep -v /CVS | sed 's/^....//g'); do
274 install -m 644 web/$i ${web_path}__/$i
278 find . -name '.htaccess' -exec install -m 644 {} ${web_path}__/{} \;
281 if [ $players_n -eq 5 ]; then
288 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]\+' {} \;)
290 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]\+' {} \;)
292 # .ph[pho] substitutions
293 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]\+ *)' {} \;)
295 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]\+ *)' {} \;)
297 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,[^)]*)' {} \;)
299 sed -i "s@define *( *TABLES_N,[^)]*)@define(TABLES_N, $tables_n)@g" ${web_path}__/Obj/brisk.phh
301 sed -i "s@define *( *TABLES_AUTH_N,[^)]*)@define(TABLES_AUTH_N, $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
303 sed -i "s@define *( *BRISK_DEBUG,[^)]*)@define(BRISK_DEBUG, $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
305 sed -i "s@define *( *LEGAL_PATH,[^)]*)@define(LEGAL_PATH, \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
307 sed -i "s@define *( *PROXY_PATH,[^)]*)@define(PROXY_PATH, \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
309 sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
311 sed -i "s@define *( *BRISK_AUTH_CONF,[^)]*)@define(BRISK_AUTH_CONF, \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
313 sed -i "s@var \+xhr_rd_cookiepath \+= \+\"[^\"]*\";@var xhr_rd_cookiepath = \"$cookie_path\";@g" ${web_path}__/xhr.js
314 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
316 if [ -d ${web_path} ]; then
317 mv ${web_path} ${web_path}.old
320 if [ -d ../brisk-img ]; then
322 ./INSTALL.sh -w ${web_path}__
326 # config file installation or diff
327 if [ -f "$etc_path/$brisk_conf" ]; then
328 echo "Config file $etc_path/$brisk_conf exists."
329 echo "=== Dump the diff. ==="
330 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
331 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 )
332 echo "=== End dump. ==="
334 echo "Config file $etc_path/$brisk_conf not exists."
335 echo "Install a template."
336 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
339 mv ${web_path}__ ${web_path}
340 if [ -d ${web_path}.old ]; then
341 rm -rf ${web_path}.old
343 if [ "$web_only" = "FALSE" ]; then
344 mv "$ftokk_path" "$ftok_path"