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\""
189 # check for etc path existence
190 dsta="$(dirname "$web_path")"
191 etc_path="$(searchetc "$dsta" Etc)"
192 if [ $? -ne 0 ]; then
193 echo "Etc directory not found"
200 ftokk_path="${ftok_path}k"
202 if [ $players_n -ne 3 -a $players_n -ne 5 ]; then
203 echo "players_n ($players_n) out of range (3|5)"
207 if [ "$web_only" = "FALSE" ]; then
208 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
209 echo "ftok_path (\"$ftok_path\") not exists"
212 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
213 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
216 if [ -d "$ftok_path" ]; then
217 mv "$ftok_path" "$ftokk_path"
219 touch $ftokk_path/spy.txt >/dev/null 2>&1
220 if [ $? -ne 0 ]; then
221 echo "ftokk_path (\"$ftokk_path\") write not allowed."
224 rm $ftokk_path/spy.txt
226 # create the fs subtree to enable ftok-ing
227 touch ${ftokk_path}/main
228 chmod 666 ${ftokk_path}/main
229 touch ${ftokk_path}/challenges
230 chmod 666 ${ftokk_path}/challenges
231 touch ${ftokk_path}/hardbans
232 chmod 666 ${ftokk_path}/hardbans
233 touch ${ftokk_path}/warrant
234 chmod 666 ${ftokk_path}/warrant
235 touch ${ftokk_path}/poll
236 chmod 666 ${ftokk_path}/poll
237 for i in $(seq 0 99); do
238 touch ${ftokk_path}/table$i
239 chmod 666 ${ftokk_path}/table$i
241 for i in $(seq 0 299); do
242 touch ${ftokk_path}/user$i
243 chmod 666 ${ftokk_path}/user$i
246 install -d ${web_path}__
247 for i in $(find web -type d | grep -v /CVS | sed 's/^....//g'); do
248 install -d ${web_path}__/$i
251 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
252 install -m 644 web/$i ${web_path}__/$i
256 find . -name '.htaccess' -exec install -m 644 {} ${web_path}__/{} \;
259 if [ $players_n -eq 5 ]; then
266 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]\+' {} \;)
268 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]\+' {} \;)
270 # .ph[pho] substitutions
271 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]\+ *)' {} \;)
273 sed -i "s/define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)/define(BRISKIN5_PLAYERS_N, $players_n)/g" $(find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)' {} \;)
275 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,[^)]*)' {} \;)
277 sed -i "s@define *( *TABLES_N,[^)]*)@define(TABLES_N, $tables_n)@g" ${web_path}__/Obj/brisk.phh
279 sed -i "s@define *( *TABLES_AUTH_N,[^)]*)@define(TABLES_AUTH_N, $tables_auth_n)@g" ${web_path}__/Obj/brisk.phh
281 sed -i "s@define *( *BRISK_DEBUG,[^)]*)@define(BRISK_DEBUG, $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
283 sed -i "s@define *( *LEGAL_PATH,[^)]*)@define(LEGAL_PATH, \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
285 sed -i "s@define *( *PROXY_PATH,[^)]*)@define(PROXY_PATH, \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
287 sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
289 sed -i "s@define *( *BRISK_AUTH_CONF,[^)]*)@define(BRISK_AUTH_CONF, \"$brisk_auth_conf\")@g" ${web_path}__/Obj/auth.phh
291 sed -i "s@var \+xhr_rd_cookiepath \+= \+\"[^\"]*\";@var xhr_rd_cookiepath = \"$cookie_path\";@g" ${web_path}__/xhr.js
292 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
294 if [ -d ${web_path} ]; then
295 mv ${web_path} ${web_path}.old
298 if [ -d ../brisk-img ]; then
300 ./INSTALL.sh -w ${web_path}__
304 # config file installation or diff
305 if [ -f "$etc_path/$brisk_conf" ]; then
306 echo "Config file $etc_path/$brisk_conf exists."
307 echo "=== Dump the diff. ==="
308 # diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
309 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 )
310 echo "=== End dump. ==="
312 echo "Config file $etc_path/$brisk_conf not exists."
313 echo "Install a template."
314 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
317 mv ${web_path}__ ${web_path}
318 if [ -d ${web_path}.old ]; then
319 rm -rf ${web_path}.old
321 if [ "$web_only" = "FALSE" ]; then
322 mv "$ftokk_path" "$ftok_path"