8 legal_path="$HOME/brisk-priv"
9 ftok_path="$HOME/brisk-priv/ftok"
10 proxy_path="$HOME/brisk-priv/proxy"
12 brisk_conf="brisk.conf.pho"
14 if [ -f $HOME/.trusty_install ]; then
15 . $HOME/.trusty_install
17 if [ "x$cookie_path" = "x" ]; then
23 echo "$1 [-W] [-n 3|5] [-f conffile] [-p outconf] [-d TRUE|FALSE] [-w web_dir] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-c <cookie_path>]"
25 echo " -f use this config file"
26 echo " -p save preferences in the file"
27 echo " -W web files only"
28 echo " -n number of players - def. $n_players"
29 echo " -d activate dabug - def. $brisk_debug"
30 echo " -w dir where place the web tree - def. \"$web_path\""
31 echo " -k dir where place ftok files - def. \"$ftok_path\""
32 echo " -l dir where save logs - def. \"$legal_path\""
33 echo " -y dir where place proxy files - def. \"$proxy_path\""
34 echo " -c cookie path - def. \"$cookie_path\""
35 echo " -C config filename - def. \"$brisk_conf\""
40 function get_param () {
41 echo "X$2" | grep -q "^X$1\$"
54 function searchetc() {
60 while [ "$pp" != "/" ]; do
61 if [ -d "$pp/$dname" ]; then
74 while [ $# -gt 0 ]; do
78 -f*) conffile="`get_param "-f" "$1" "$2"`"; sh=$?;;
79 -p*) outconf="`get_param "-p" "$1" "$2"`"; sh=$?;;
80 -n*) n_players="`get_param "-n" "$1" "$2"`"; sh=$?;;
81 -d*) brisk_debug="`get_param "-d" "$1" "$2"`"; sh=$?;;
82 -w*) web_path="`get_param "-w" "$1" "$2"`"; sh=$?;;
83 -k*) ftok_path="`get_param "-k" "$1" "$2"`"; sh=$?;;
84 -y*) proxy_path="`get_param "-y" "$1" "$2"`"; sh=$?;;
85 -c*) cookie_path="`get_param "-c" "$1" "$2"`"; sh=$?;;
86 -C*) brisk_conf="`get_param "-C" "$1" "$2"`"; sh=$?;;
87 -l*) legal_path="`get_param "-l" "$1" "$2"`"; sh=$?;;
89 -h) usage $0; exit 0;;
92 if [ ! -z "$conffile" ]; then
93 if [ ! -f "$conffile" ]; then
94 echo "config file [$conffile] not found"
105 echo " outconf: \"$outconf\""
106 echo " n_players: $n_players"
107 echo " brisk_debug:\"$brisk_debug\""
108 echo " web_path: \"$web_path\""
109 echo " ftok_path: \"$ftok_path\""
110 echo " legal_path: \"$legal_path\""
111 echo " proxy_path: \"$proxy_path\""
112 echo " cookie_path:\"$cookie_path\""
113 echo " brisk_conf:\"$brisk_conf\""
114 echo " web_only: \"$web_only\""
116 if [ ! -z "$outconf" ]; then
119 echo "# Produced automatically by brisk::INSTALL.sh"
121 echo "n_players=$n_players"
122 echo "brisk_debug=\"$brisk_debug\""
123 echo "web_path=\"$web_path\""
124 echo "ftok_path=\"$ftok_path\""
125 echo "proxy_path=\"$proxy_path\""
126 echo "legal_path=\"$legal_path\""
127 echo "cookie_path=\"$cookie_path\""
128 echo "brisk_conf=\"$brisk_conf\""
129 echo "web_only=\"$web_only\""
135 # check for etc path existence
136 dsta="`dirname "$web_path"`"
137 etc_path="`searchetc "$dsta" Etc`"
138 if [ $? -ne 0 ]; then
139 echo "Etc directory not found"
146 ftokk_path="${ftok_path}k"
148 if [ $n_players -ne 3 -a $n_players -ne 5 ]; then
149 echo "n_players ($n_players) out of range (3|5)"
152 if [ "$web_only" = "FALSE" ]; then
153 if [ ! -d "$ftok_path" -a ! -d "$ftokk_path" ]; then
154 echo "ftok_path (\"$ftok_path\") not exists"
157 if [ -d "$ftok_path" -a -d "$ftokk_path" ]; then
158 echo "ftok_path (\"$ftok_path\") and ftokk_path (\"$ftokk_path\") exist, cannot continue"
161 if [ -d "$ftok_path" ]; then
162 mv "$ftok_path" "$ftokk_path"
164 touch $ftokk_path/spy.txt >/dev/null 2>&1
165 if [ $? -ne 0 ]; then
166 echo "ftokk_path (\"$ftokk_path\") write not allowed."
169 rm $ftokk_path/spy.txt
171 # create the fs subtree to enable ftok-ing
172 touch ${ftokk_path}/main
173 chmod 666 ${ftokk_path}/main
174 touch ${ftokk_path}/challenges
175 chmod 666 ${ftokk_path}/challenges
176 touch ${ftokk_path}/hardbans
177 chmod 666 ${ftokk_path}/hardbans
178 touch ${ftokk_path}/warrant
179 chmod 666 ${ftokk_path}/warrant
180 touch ${ftokk_path}/poll
181 chmod 666 ${ftokk_path}/poll
182 for i in `seq 0 99`; do
183 touch ${ftokk_path}/table$i
184 chmod 666 ${ftokk_path}/table$i
187 install -d ${web_path}__
188 for i in `find web -type d | grep -v /CVS | sed 's/^....//g'`; do
189 install -d ${web_path}__/$i
192 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
193 install -m 644 web/$i ${web_path}__/$i
197 find . -name '.htaccess' -exec install -m 644 {} ${web_path}__/{} \;
200 if [ $n_players -eq 5 ]; then
207 sed -i "s/PLAYERS_N *= *[0-9]\+/PLAYERS_N = $n_players/g" `find ${web_path}__ -type f -name '*.js' -exec grep -l 'PLAYERS_N *= *[0-9]\+' {} \;`
209 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]\+' {} \;`
211 # .ph[pho] substitutions
212 sed -i "s/define *( *PLAYERS_N, *[0-9]\+ *)/define(PLAYERS_N, $n_players)/g" `find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *PLAYERS_N, *[0-9]\+ *)' {} \;`
214 sed -i "s/define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)/define(BRISKIN5_PLAYERS_N, $n_players)/g" `find ${web_path}__ -type f -name '*.ph*' -exec grep -l 'define *( *BRISKIN5_PLAYERS_N, *[0-9]\+ *)' {} \;`
216 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,[^)]*)' {} \;`
218 sed -i "s@define *( *BRISK_DEBUG,[^)]*)@define(BRISK_DEBUG, $brisk_debug)@g" ${web_path}__/Obj/brisk.phh
220 sed -i "s@define *( *LEGAL_PATH,[^)]*)@define(LEGAL_PATH, \"$legal_path\")@g" ${web_path}__/Obj/brisk.phh
222 sed -i "s@define *( *PROXY_PATH,[^)]*)@define(PROXY_PATH, \"$proxy_path\")@g" ${web_path}__/Obj/brisk.phh
224 sed -i "s@define *( *BRISK_CONF,[^)]*)@define(BRISK_CONF, \"$brisk_conf\")@g" ${web_path}__/Obj/brisk.phh
226 sed -i "s@var \+xhr_rd_cookiepath \+= \+\"[^\"]*\";@var xhr_rd_cookiepath = \"$cookie_path\";@g" ${web_path}__/xhr.js
227 sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$cookie_path\";@g" ${web_path}__/commons.js
229 if [ -d ${web_path} ]; then
230 mv ${web_path} ${web_path}.old
233 if [ -d ../brisk-img ]; then
235 ./INSTALL.sh -w ${web_path}__
239 # config file installation or diff
240 if [ -f "$etc_path/$brisk_conf" ]; then
241 echo "Config file $etc_path/$brisk_conf exists."
242 echo "=== Dump the diff. ==="
243 diff -u "$etc_path/$brisk_conf" "${web_path}__""/Obj/brisk.conf-templ.pho"
244 echo "=== End dump. ==="
246 echo "Config file $etc_path/$brisk_conf not exists."
247 echo "Install a template."
248 cp "${web_path}__""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
251 mv ${web_path}__ ${web_path}
252 if [ -d ${web_path}.old ]; then
253 rm -rf ${web_path}.old
255 if [ "$web_only" = "FALSE" ]; then
256 mv "$ftokk_path" "$ftok_path"