6 CONFIG_FILE="$HOME/.curl-de-sac_install"
8 apache_conf="/etc/apache2/sites-available/default"
10 web_path="/home/nastasi/web/curl-de-sacccc"
11 web_url="http://localhost/curl-de-sac"
12 tor_chk_url="http://localhost/curl-de-sac/test/tor_mock.php"
13 proxy_chk_url="http://localhost/curl-de-sac/test/proxy_mock.php"
15 # ftok_path="/home/nastasi/brisk-priv/ftok/brisk"
16 # proxy_path="/home/nastasi/brisk-priv/proxy/brisk"
18 # legal_path="/home/nastasi/brisk-priv/brisk"
19 # prefix_path="/brisk/"
20 # brisk_conf="brisk_spu.conf.pho"
29 echo "$1 chk - run lintian on all ph* files."
30 # echo "$1 pkg - build brisk packages."
31 echo "$1 [-w <web_dir>] [-f <conffile>] [-p <outconf>] [-t <tor_chk_url>] [-P <proxy_chk_url>]" # [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
32 # echo "$1 [-W] [-n 3|5] [-t <(n>=4)>] [-T <auth_tab>] [-G <cert_tab>] [-A <apache-conf>] [-a <auth_file_name>] [-f <conffile>] [-p <outconf>] [-U <usock_path>] [-u <sys_user>] [-d <TRUE|FALSE>] [-w <web_dir>] [-k <ftok_dir>] [-l <legal_path>] [-y <proxy_path>] [-P <prefix_path>] [-x]"
33 echo "$1 [-w <web_dir>]"
35 echo " -f use this config file"
36 echo " -p save preferences in the file"
37 # echo " -W web files only"
38 # echo " -A apache_conf - def. $apache_conf"
39 # echo " -n number of players - def. $players_n"
40 # echo " -t number of tables - def. $tables_n"
41 # echo " -T number of auth-only tables - def. $tables_auth_n"
42 # echo " -G number of cert-only tables - def. $tables_cert_n"
43 # echo " -a authorization file name - def. \"$brisk_auth_conf\""
44 echo " -d set debug level - def. $dbg_level"
45 echo " -w dir where place the web tree - def. \"$web_path\""
46 echo " -U web url to retrieve test pages - def. \"$web_url\""
47 echo " -t tor chk url - def. \"$tor_chk_url\""
48 echo " -P proxy chk url - def. \"$proxy_chk_url\""
49 # echo " -k dir where place ftok files - def. \"$ftok_path\""
50 # echo " -l dir where save logs - def. \"$legal_path\""
51 # echo " -y dir where place proxy files - def. \"$proxy_path\""
52 # echo " -P prefix path - def. \"$prefix_path\""
53 # echo " -C config filename - def. \"$brisk_conf\""
54 # echo " -U unix socket path - def. \"$usock_path\""
55 # echo " -u system user to run brisk dae - def. \"$sys_user\""
56 echo " -x copy tests as normal php - def. \"$test_add\""
60 function get_param () {
61 echo "X$2" | grep -q "^X$1\$"
74 function searchetc() {
80 while [ "$pp" != "/" ]; do
81 if [ -d "$pp/$dname" ]; then
94 if [ "$1" = "chk" ]; then
99 for i in $(find -name '*.pho' -o -name '*.phh' -o -name '*.php'); do
103 taggit="$(git describe --tags | sed 's/^v//g')"
104 tagphp="$(grep "^\$G_curl_de_sac_version = " web/Obj/curl-de-sac.phh | sed 's/^[^"]\+"//g;s/".*//g')"
105 if [ "$taggit" != "$tagphp" ]; then
107 echo "WARNING: taggit: [$taggit] tagphp: [$tagphp]"
113 # before all check errors on the sources
116 if [ "$1" = "pkg" ]; then
117 if [ "$2" != "" ]; then
120 tag="$(git describe)"
122 nam1="curl-de-sac_${tag}.tgz"
123 echo "Build packages ${nam1}."
124 read -p "Proceed [y/n]: " a
125 if [ "$a" != "y" -a "$a" != "Y" ]; then
128 git archive --format=tar --prefix=brisk-${tag}/curl-de-sac/ $tag | gzip > ../$nam1
133 if [ -f "$CONFIG_FILE" ]; then
134 source "$CONFIG_FILE"
137 if [ "x$prefix_path" = "x" ]; then
138 prefix_path="$web_path"
142 while [ $# -gt 0 ]; do
143 # echo aa $1 xx $2 bb
146 # -A*) apache_conf="$(get_param "-A" "$1" "$2")"; sh=$?;;
147 -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
148 -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
149 # -n*) players_n="$(get_param "-n" "$1" "$2")"; sh=$?;;
150 # -t*) tables_n="$(get_param "-t" "$1" "$2")"; sh=$?;;
151 # -T*) tables_auth_n="$(get_param "-T" "$1" "$2")"; sh=$?;;
152 # -G*) tables_cert_n="$(get_param "-G" "$1" "$2")"; sh=$?;;
153 # -a*) brisk_auth_conf="$(get_param "-a" "$1" "$2")"; sh=$?;;
154 -d*) dbg_level="$(get_param "-d" "$1" "$2")"; sh=$?;;
155 -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
156 -U*) web_url="$(get_param "-U" "$1" "$2")" ; sh=$?;;
157 -t*) tor_chk_url="$(get_param "-t" "$1" "$2")" ; sh=$?;;
158 -P*) proxy_chk_url="$(get_param "-P" "$1" "$2")" ; sh=$?;;
159 # -k*) ftok_path="$(get_param "-k" "$1" "$2")"; sh=$?;;
160 # -y*) proxy_path="$(get_param "-y" "$1" "$2")"; sh=$?;;
161 # -P*) prefix_path="$(get_param "-P" "$1" "$2")"; sh=$?;;
162 # -C*) brisk_conf="$(get_param "-C" "$1" "$2")"; sh=$?;;
163 # -l*) legal_path="$(get_param "-l" "$1" "$2")"; sh=$?;;
164 # -U*) usock_path="$(get_param "-U" "$1" "$2")"; sh=$?;;
165 # -u*) sys_user="$(get_param "-u" "$1" "$2")"; sh=$?;;
166 # system) action=system;;
167 # -W) web_only="TRUE";;
168 -x) test_add="TRUE";;
169 -h) usage $0; exit 0;;
170 *) usage $0; exit 1;;
172 if [ ! -z "$conffile" ]; then
173 if [ ! -f "$conffile" ]; then
174 echo "config file [$conffile] not found"
185 echo " outconf: \"$outconf\""
186 # echo " apache_conf:\"$apache_conf\""
187 # echo " players_n: $players_n"
188 # echo " tables_n: $tables_n"
189 # echo " tables_auth_n: $tables_auth_n"
190 # echo " tables_cert_n: $tables_cert_n"
191 # echo " brisk_auth_conf: \"$brisk_auth_conf\""
192 echo " dbg_level: $dbg_level"
193 echo " web_path: \"$web_path\""
194 echo " web_url: \"$web_url\""
195 echo " tor_chk_url: \"$tor_chk_url\""
196 echo " proxy_chk_url: \"$proxy_chk_url\""
198 # echo " ftok_path: \"$ftok_path\""
199 # echo " legal_path: \"$legal_path\""
200 # echo " proxy_path: \"$proxy_path\""
201 # echo " prefix_path:\"$prefix_path\""
202 # echo " brisk_conf: \"$brisk_conf\""
203 # echo " usock_path: \"$usock_path\""
204 # echo " sys_user: \"$sys_user\""
205 # echo " web_only: \"$web_only\""
206 # echo " test_add: \"$test_add\""
208 if [ ! -z "$outconf" ]; then
211 echo "# Produced automatically by curl-de-sac::INSTALL.sh"
213 # echo "apache_conf=$apache_conf"
214 # echo "players_n=$players_n"
215 # echo "tables_n=$tables_n"
216 # echo "tables_auth_n=$tables_auth_n"
217 # echo "tables_cert_n=$tables_cert_n"
218 # echo "brisk_auth_conf=\"$brisk_auth_conf\""
219 echo "dbg_level=$dbg_level"
220 echo "web_path=\"$web_path\""
221 echo "web_url=\"$web_url\""
222 echo "tor_chk_url=\"$tor_chk_url\""
223 echo "proxy_chk_url=\"$proxy_chk_url\""
224 # echo "ftok_path=\"$ftok_path\""
225 # echo "proxy_path=\"$proxy_path\""
226 # echo "legal_path=\"$legal_path\""
227 # echo "prefix_path=\"$prefix_path\""
228 # echo "brisk_conf=\"$brisk_conf\""
229 # echo "usock_path=\"$usock_path\""
230 # echo "sys_user=\"$sys_user\""
231 # echo "web_only=\"$web_only\""
232 echo "test_add=\"$test_add\""
236 if [ 1 -eq 0 -a "$action" = "system" ]; then
238 scrname="$(echo "$prefix_path" | sed 's@^/@@g;s@/$@@g;s@/@_@g;')"
240 echo "script name: [$scrname]"
241 echo "brisk path: [$web_path]"
242 echo "private path: [$legal_path]"
243 echo "system user: [$sys_user]"
245 read -p "press enter to continue" sure
246 cp bin/brisk-init.sh brisk-init.sh.wrk
247 sed -i "s@^BPATH=.*@BPATH=\"${web_path}\"@g;s@^PPATH=.*@PPATH=\"${legal_path}\"@g;s@^SSUFF=.*@SSUFF=\"${scrname}\"@g;s@^BUSER=.*@BUSER=\"${sys_user}\"@g" brisk-init.sh.wrk
249 su -c "cp brisk-init.sh.wrk /etc/init.d/${scrname}"
254 echo "DON'T FORGET: after the first installation you MUST configure your run-levels accordingly"
256 echo "Example: su -c 'update-rc.d $scrname defaults'"
263 # check for etc path existence
264 dsta="$(dirname "$web_path")"
265 etc_path="$(searchetc "$dsta" Etc)"
266 if [ $? -ne 0 ]; then
267 echo "Etc directory not found"
276 # ftokk_path="${ftok_path}k"
279 if [ "$web_only" != "TRUE" ]; then
280 # here code una tantum
283 install -d ${web_path}
284 for i in $(find web -type d | grep '/' | sed 's/^....//g'); do
285 install -d ${web_path}/$i
288 for i in $(find web -name '.htaccess' -o -name '*.php' -o -name '*.phh' -o -name '*.pho' -o -name '*.html' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^....//g'); do
289 install -m 644 "web/$i" "${web_path}/$i"
291 if [ "$test_add" = "TRUE" ]; then
292 for i in $(find webtest -type d | grep '/' | sed 's/^........//g'); do
293 install -d ${web_path}/test/$i
296 for i in $(find webtest -name '.htaccess' -o -name '*.phh' -o -name '*.pho' -o -name '*.html' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name 'terms-of-service*' | sed 's/^........//g'); do
297 install -m 644 "webtest/$i" "${web_path}/test/$i"
299 for i in $(find webtest -name '*.php' | sed 's/^........//g'); do
300 install -m 755 "webtest/$i" "${web_path}/test/$i"
304 # # .js substitutions
305 # 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]\+' {} \;)
307 # 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]\+' {} \;)
309 # # .ph[pho] substitutions
310 sed -i "s@^define *( *'WEB_URL', *'[^']\+' *)@define('WEB_URL', '$web_url')@g;\
311 s@define *( *'DBG_LEVEL', *[0-9]\+ *)@define('DBG_LEVEL', $dbg_level)@g;\
312 s@define *( *'TOR_CHK_URL', *'[^']\+' *)@define('TOR_CHK_URL', '$tor_chk_url')@g;\
313 s@define *( *'PROXY_CHK_URL', *'[^']\+' *)@define('PROXY_CHK_URL', '$proxy_chk_url')@g" $(find ${web_path} -type f -name '*.ph*')
315 # 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]\+ *)" {} \;)
317 # 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',[^)]*)" {} \;)
319 # sed -i "s@define *( *'SITE_PREFIX',[^)]*)@define('SITE_PREFIX', \"$prefix_path\")@g;
320 # s@define *( *'SITE_PREFIX_LEN',[^)]*)@define('SITE_PREFIX_LEN', $prefix_path_len)@g" ${web_path}/Obj/sac-a-push.phh
322 # sed -i "s@define *( *'USOCK_PATH',[^)]*)@define('USOCK_PATH', \"$usock_path\")@g" ${web_path}/spush/brisk-spush.phh
324 # sed -i "s@define *( *'TABLES_N',[^)]*)@define('TABLES_N', $tables_n)@g;
325 # s@define *( *'TABLES_AUTH_N',[^)]*)@define('TABLES_AUTH_N', $tables_auth_n)@g;
326 # s@define *( *'TABLES_CERT_N',[^)]*)@define('TABLES_CERT_N', $tables_cert_n)@g;
327 # s@define *( *'BRISK_DEBUG',[^)]*)@define('BRISK_DEBUG', $brisk_debug)@g;
328 # s@define *( *'LEGAL_PATH',[^)]*)@define('LEGAL_PATH', \"$legal_path\")@g;
329 # s@define *( *'PROXY_PATH',[^)]*)@define('PROXY_PATH', \"$proxy_path\")@g;
330 # s@define *( *'BRISK_CONF',[^)]*)@define('BRISK_CONF', \"$brisk_conf\")@g;" ${web_path}/Obj/brisk.phh
332 # sed -i "s@define *( *'BRISK_AUTH_CONF',[^)]*)@define('BRISK_AUTH_CONF', \"$brisk_auth_conf\")@g" ${web_path}/Obj/auth.phh
334 # sed -i "s@var \+cookiepath \+= \+\"[^\"]*\";@var cookiepath = \"$prefix_path\";@g" ${web_path}/commons.js
336 # sed -i "s@\( \+cookiepath *: *\)\"[^\"]*\" *,@\1 \"$prefix_path\",@g" ${web_path}/xynt-streaming.js
338 # document_root="$(grep DocumentRoot "${apache_conf}" | grep -v '^[ ]*#' | awk '{ print $2 }')"
339 # sed -i "s@^\(\$DOCUMENT_ROOT *= *[\"']\)[^\"']*\([\"']\)@\1$document_root\2@g" ${web_path}/spush/*.ph*
341 # # config file installation or diff
342 # if [ -f "$etc_path/$brisk_conf" ]; then
343 # echo "Config file $etc_path/$brisk_conf exists."
344 # echo "=== Dump the diff. ==="
345 # # diff -u "$etc_path/$brisk_conf" "${web_path}""/Obj/brisk.conf-templ.pho"
346 # diff -u <(cat "$etc_path/$brisk_conf" | egrep -v '^//|^#' | grep '\$[a-zA-Z_ ]\+=' | sed 's/ \+= .*/ = /g' | sort | uniq) <(cat "${web_path}""/Obj/brisk.conf-templ.pho" | egrep -v '^//|^#' | grep '\$[a-zA-Z_ ]\+=' | sed 's/ \+= .*/ = /g' | sort | uniq )
347 # echo "=== End dump. ==="
349 # echo "Config file $etc_path/$brisk_conf not exists."
350 # echo "Install a template."
351 # cp "${web_path}""/Obj/brisk.conf-templ.pho" "$etc_path/$brisk_conf"
354 if [ -f WARNING.txt ]; then
355 echo ; echo " ==== WARNING ===="