6 CONFIG_FILE="$HOME/.brisk_install"
11 brisk_auth_conf="brosk_auth.conf.pho"
13 # brisk_debug="0xffff"
14 web_path="/home/nastasi/web/brosk"
15 ftok_path="/home/nastasi/brisk-priv/ftok/brosk"
16 proxy_path="/home/nastasi/brisk-priv/proxy/brosk"
17 legal_path="/home/nastasi/brisk-priv/brosk"
19 brisk_conf="brosk.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"
207 ftokk_path="${ftok_path}k"
209 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
210 echo "players_n ($players_n) out of range (3|5)"
214 if [ "$web_only" = "FALSE" ]; then
215 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
216 echo "ftok_path (\"$ftok_path\") not exists"
219 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
220 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
223 if [ -d "$ftok_path" ]; then
224 mv "$ftok_path" "$ftokk_path"
226 touch $ftokk_path/spy.txt >/dev/null 2>&1
227 if [ $? -ne 0 ]; then
228 echo "ftokk_path (\"$ftokk_path\") write not allowed."
231 rm $ftokk_path/spy.txt
233 # create the fs subtree to enable ftok-ing
234 touch ${ftokk_path}/main
235 chmod 666 ${ftokk_path}/main
236 touch ${ftokk_path}/challenges
237 chmod 666 ${ftokk_path}/challenges
238 touch ${ftokk_path}/hardbans
239 chmod 666 ${ftokk_path}/hardbans
240 touch ${ftokk_path}/warrant
241 chmod 666 ${ftokk_path}/warrant
242 touch ${ftokk_path}/poll
243 chmod 666 ${ftokk_path}/poll
244 for i in $(seq 0 $max_players); do
245 touch ${ftokk_path}/user$i
246 chmod 666 ${ftokk_path}/user$i
249 if [ ! -d ${ftokk_path}/bin5 ]; then
250 mkdir ${ftokk_path}/bin5
251 chmod 777 ${ftokk_path}/bin5
254 for i in $(seq 0 $((tables_n - 1))); do
255 if [ ! -d ${ftokk_path}/bin5/table$i ]; then
256 mkdir ${ftokk_path}/bin5/table$i
258 chmod 777 ${ftokk_path}/bin5/table$i
259 touch ${ftokk_path}/bin5/table$i/table
260 chmod 666 ${ftokk_path}/bin5/table$i/table
261 for e in $(seq 0 4); do
262 touch ${ftokk_path}/bin5/table$i/user$e
263 chmod 666 ${ftokk_path}/bin5/table$i/user$e
265 # create subdirectories in proxy path
266 if [ ! -d ${proxy_path}/bin5/table$i ]; then
267 mkdir -p ${proxy_path}/bin5/table$i
270 chmod -R 777 ${proxy_path}/bin5
273 install -d ${web_path}__
274 for i in $(find web -type d | grep -v /CVS | sed 's/^....//g'); do
275 install -d ${web_path}__/$i
278 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
279 install -m 644 web/$i ${web_path}__/$i
283 find . -name '.htaccess' -exec install -m 644 {} ${web_path}__/{} \;
286 if [ $players_n -eq 5 ]; then
293 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]\+' {} \;)
295 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]\+' {} \;)
297 # .ph[pho] substitutions
298 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]\+ *)' {} \;)
300 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]\+ *)' {} \;)
302 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,[^)]*)' {} \;)
304 sed -i "s@define *( *TABLES_N,[^)]*)@define(TABLES_N, $tables_n)@g" ${web_path}__/Obj/brisk.phh
306 sed -i "s@define *( *TABLES_AUTH_N,[^)]*)@define(TABLES_AUTH_N, $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
308 sed -i "s@define *( *BRISK_DEBUG,[^)]*)@define(BRISK_DEBUG, $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
310 sed -i "s@define *( *LEGAL_PATH,[^)]*)@define(LEGAL_PATH, \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
312 sed -i "s@define *( *PROXY_PATH,[^)]*)@define(PROXY_PATH, \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
314 sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
316 sed -i "s@define *( *BRISK_AUTH_CONF,[^)]*)@define(BRISK_AUTH_CONF, \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
318 sed -i "s@var \+xhr_rd_cookiepath \+= \+\"[^\"]*\";@var xhr_rd_cookiepath = \"$cookie_path\";@g" ${web_path}__/xhr.js
319 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
321 if [ -d ${web_path} ]; then
322 mv ${web_path} ${web_path}.old
325 if [ -d ../brisk-img ]; then
327 ./INSTALL.sh -w ${web_path}__
331 # config file installation or diff
332 if [ -f "$etc_path/$brisk_conf" ]; then
333 echo "Config file $etc_path/$brisk_conf exists."
334 echo "=== Dump the diff. ==="
335 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
336 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 )
337 echo "=== End dump. ==="
339 echo "Config file $etc_path/$brisk_conf not exists."
340 echo "Install a template."
341 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
344 mv ${web_path}__ ${web_path}
345 if [ -d ${web_path}.old ]; then
346 rm -rf ${web_path}.old
348 if [ "$web_only" = "FALSE" ]; then
349 mv "$ftokk_path" "$ftok_path"