clean of string stream added (we still need <script> objects clean)
[xynt.git] / INSTALL.sh
1 #!/bin/bash
2 # set -x
3 #
4 # Defaults
5 #
6 CONFIG_FILE="$HOME/.xynt_install"
7
8 web_path="/home/nastasi/web/brosk"
9
10 if [ "$1" = "pkg" ]; then
11     if [ "$2" != "" ]; then
12         tag="$2"
13     else
14         tag="$(git describe)"
15     fi
16     nam1="xynt_${tag}.tgz"
17     echo "Build packages ${nam1}."
18     read -p "Proceed [y/n]: " a
19     if [ "$a" != "y" -a  "$a" != "Y" ]; then
20         exit 1
21     fi
22     git archive --format=tar --prefix=xynt-${tag}/ $tag | gzip > ../$nam1
23     exit 0
24 fi
25     
26 if [ -f "$CONFIG_FILE" ]; then
27    source "$CONFIG_FILE"
28 fi
29
30 function usage () {
31     echo
32     echo "$1 -h"
33     echo "$1 pkg  - build xynt package."
34     echo "$1 [-p outfile] [-f conffile] [-w web_dir]"
35     echo "  -h this help"
36     echo "  -f use this config file"
37     echo "  -p save preferences in the file"
38     echo "  -w dir where place the web tree - def. \"$web_path\""
39     
40     echo
41 }
42
43 function get_param () {
44     echo "X$2" | grep -q "^X$1\$"
45     if [ $? -eq 0 ]; then
46         # echo "DECHE" >&2
47         echo "$3"
48         return 2
49     else
50         # echo "DELA" >&2
51         echo "$2" | cut -c 3-
52         return 1
53     fi
54     return 0
55 }
56
57 function searchetc() {
58     local dstart dname pp
59     dstart="$1"
60     dname="$2"
61
62     pp="$dstart"
63     while [ "$pp" != "/" ]; do
64         if [ -d "$pp/$dname" ]; then
65             echo "$pp/$dname"
66             return 0
67         fi
68         pp="$(dirname "$pp")"
69     done
70     
71     return 1
72 }
73
74 #
75 #  MAIN
76 #
77 while [ $# -gt 0 ]; do
78     # echo aa $1 xx $2 bb
79     conffile=""
80     case $1 in
81         -f*) conffile="$(get_param "-f" "$1" "$2")"; sh=$?;;
82         -p*) outconf="$(get_param "-p" "$1" "$2")"; sh=$?;;
83         -w*) web_path="$(get_param "-w" "$1" "$2")"; sh=$?;;
84         -h) usage $0; exit 0;;
85         *) usage $0; exit 1;;
86     esac
87     if [ ! -z "$conffile" ]; then
88         if [ ! -f "$conffile" ]; then
89             echo "config file [$conffile] not found"
90             exit 1
91         fi
92         . "$conffile"
93     fi
94     shift $sh
95 done
96
97 #
98 #  Show parameters
99 #
100 echo "    outconf:    \"$outconf\""
101 echo "    web_path:   \"$web_path\""
102
103 if [ ! -z "$outconf" ]; then
104   ( 
105     echo "#"
106     echo "#  Produced automatically by xynt::INSTALL.sh"
107     echo "#"
108     echo "web_path=\"$web_path\""
109   ) > "$outconf"
110 fi
111
112 max_players=$((40 + players_n * tables_n))
113 #
114 #  Pre-check
115 #
116 # check for etc path existence
117 # dsta="$(dirname "$web_path")"
118 # etc_path="$(searchetc "$dsta" Etc)"
119 # if [ $? -ne 0 ]; then
120 #     echo "Etc directory not found"
121 #     exit 1
122 # fi
123
124 #
125 #  Installation
126 #
127 if [ -d ${web_path}.old ]; then
128     rm -rf ${web_path}.old
129 fi
130
131 if [ -d ${web_path} ]; then
132     mv ${web_path} ${web_path}.old
133 fi
134
135 for i in $(find web -type d | sed 's/^....//g'); do
136     install -d ${web_path}/$i 
137 done
138
139 for i in $(find web -name '*.html' -o -name '*.php' -o -name '*.phh' -o -name '*.png' -o -name '*.pho' -o -name '*.css' -o -name '*.js' -o -name '*.mp3' -o -name '*.swf' -o -name '.htaccess' | sed 's/^....//g'); do
140     install -m 644 "web/$i" "${web_path}/$i"
141 done
142
143
144 # .js substitutions
145 sed -i '/^[\t \/]*console.log.*;[\t ]*$/d' $(find ${web_path} -type f -name '*.js' -exec grep -l '^[\t /]*console.log.*;[\t ]*$' {} \;)
146
147 exit 0