-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_project.sh
executable file
·194 lines (166 loc) · 5.38 KB
/
install_project.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
tmp_file="/tmp/tmp_install_project"
a2_vhosts_path="/etc/apache2/sites-available"
sys_hosts_path="/etc/hosts"
user="xanm"
group="xanm"
min_params_count="3"
max_params_count="4"
limb_version="3"
max_ip_n1="127"
max_ip_n2="0"
max_ip_n3="0"
max_ip_n4="1"
if [ $# -lt $min_params_count ]
then
echo "Needs params, like:"
echo "$0 <project_name> <sour_rep> <dest_dir> [limb_version]"
exit 1
elif [ $# -gt $max_params_count ]
then
echo "Needs params, like:"
echo "$0 <project_name> <sour_rep> <dest_dir> [limb_version]"
exit 2
fi
if [ $# -eq 4 ]; then
if [ "$4" -eq 1 ]; then
limb_version=$4
elif [ "$4" -eq 2 ]; then
limb_version=$4
fi
fi
if [ "root" != `whoami` ]
then
echo "Needs root premissions!"
exit 3
fi
project_name=$1
sour_rep=$2
dest_dir=$3
echo "Install host name!"
while read host
do
ip=`expr match "$host" '\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]*\)[ \t]*[^ \t]*'`
host_name=`expr match "$host" '[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*[ \t]*\([^ \t]*\)'`
if [ "$host_name" = "$project_name" ]; then
echo "Host name already exists in <$sys_hosts_path>"
exit 4
fi
if [ "$ip" != "" ]; then
ip_n1=`expr match "$host" '\([0-9]*\)\.[0-9]*\.[0-9]*\.[0-9]*[ \t]*[^ \t]*'`
ip_n2=`expr match "$host" '[0-9]*\.\([0-9]*\)\.[0-9]*\.[0-9]*[ \t]*[^ \t]*'`
ip_n3=`expr match "$host" '[0-9]*\.[0-9]*\.\([0-9]*\)\.[0-9]*[ \t]*[^ \t]*'`
ip_n4=`expr match "$host" '[0-9]*\.[0-9]*\.[0-9]*\.\([0-9]*\)[ \t]*[^ \t]*'`
if [ $ip_n1 -gt $max_ip_n1 ] ; then
max_ip_n1=$ip_n1
max_ip_n2=$ip_n2
max_ip_n3=$ip_n3
max_ip_n4=$ip_n4
elif [ $ip_n1 -eq $max_ip_n1 ] ; then
if [ $ip_n2 -gt $max_ip_n2 ] ; then
max_ip_n1=$ip_n1
max_ip_n2=$ip_n2
max_ip_n3=$ip_n3
max_ip_n4=$ip_n4
elif [ $ip_n2 -eq $max_ip_n2 ] ; then
if [ $ip_n3 -gt $max_ip_n3 ] ; then
max_ip_n1=$ip_n1
max_ip_n2=$ip_n2
max_ip_n3=$ip_n3
max_ip_n4=$ip_n4
elif [ $ip_n3 -eq $max_ip_n3 ] ; then
if [ $ip_n4 -gt $max_ip_n4 ] ; then
max_ip_n1=$ip_n1
max_ip_n2=$ip_n2
max_ip_n3=$ip_n3
max_ip_n4=$ip_n4
fi
fi
fi
fi
fi
done < $sys_hosts_path
let max_ip_n4=$max_ip_n4+1
max_host_ip="$max_ip_n1.$max_ip_n2.$max_ip_n3.$max_ip_n4"
for vhost_file in `ls $a2_vhosts_path`; do
if [ $vhost_file = $project_name ]; then
echo "Host file name already exists in <$a2_vhosts_path>"
exit 5
fi
done
echo "$max_host_ip $project_name" | sudo tee -a $sys_hosts_path
if [ $limb_version -eq 3 ]; then
cat > $a2_vhosts_path/$project_name << EOF
<VirtualHost $max_host_ip:80>
RewriteEngine on
ServerAdmin admin@localhost
DocumentRoot \${DEFAULT_PROJECTS_PATH}$project_name/www
ServerName $project_name
ServerAlias $project_name
ErrorLog \${DEFAULT_PROJECTS_PATH}apache_errors.log
CustomLog \${DEFAULT_PROJECTS_PATH}access.log combined
Alias /shared/wysiwyg \${DEFAULT_PROJECTS_PATH}$project_name/lib/limb/wysiwyg/shared
Alias /shared/js \${DEFAULT_PROJECTS_PATH}$project_name/lib/limb/js/shared
Alias /shared/calendar \${DEFAULT_PROJECTS_PATH}$project_name/lib/limb/calendar/shared
Alias /shared/base \${DEFAULT_PROJECTS_PATH}$project_name/lib/bitcms/base/shared
Alias /shared/cms \${DEFAULT_PROJECTS_PATH}$project_name/lib/limb/cms/shared
</VirtualHost>
EOF
elif [ $limb_version -eq 2 ]; then
cat > $a2_vhosts_path/$project_name << EOF
<VirtualHost $max_host_ip:80>
RewriteEngine on
ServerAdmin admin@localhost
DocumentRoot \${DEFAULT_PROJECTS_PATH}$project_name
ServerName $project_name
ServerAlias $project_name
ErrorLog \${DEFAULT_PROJECTS_PATH}apache_errors.log
CustomLog \${DEFAULT_PROJECTS_PATH}access.log combined
Alias /shared \${DEFAULT_PROJECTS_PATH}$project_name/external/limb/shared
</VirtualHost>
EOF
elif [ $limb_version -eq 1 ]; then
cat > $a2_vhosts_path/$project_name << EOF
<VirtualHost $max_host_ip:80>
RewriteEngine on
ServerAdmin admin@localhost
DocumentRoot \${DEFAULT_PROJECTS_PATH}$project_name
ServerName $project_name
ServerAlias $project_name
ErrorLog \${DEFAULT_PROJECTS_PATH}apache_errors.log
CustomLog \${DEFAULT_PROJECTS_PATH}access.log combined
Alias /shared \${DEFAULT_PROJECTS_PATH}$project_name/external/limb/shared
</VirtualHost>
EOF
fi
sudo a2ensite $project_name
sudo /etc/init.d/apache2 restart
echo "Host created!"
echo "install project from repo"
mkdir -p $dest_dir/$project_name
if [ "svn" = `expr match "$sour_rep" '.*\(svn\).*'` ]; then
svn checkout $sour_rep $dest_dir/$project_name
elif [ "git" = `expr match "$sour_rep" '.*\(git\).*'` ]; then
git clone $sour_rep $dest_dir/$project_name
php $sour_rep $dest_dir/$project_name/cli/export_externals.php
fi
sudo mkdir $dest_dir/$project_name/var
sudo chown -R $user:$group $dest_dir/$project_name
if [ $limb_version -eq 3 ]; then
echo "x"
#~ php $dest_dir/$project_name/cli/export_externals.php
elif [ $limb_version -eq 2 ]; then
cat > $dest_dir/$project_name/setup.override.php << EOF
<?php
define('DB_DSN', 'mysql://root:test@localhost/$project_name?charset=utf8');
EOF
elif [ $limb_version -eq 1 ]; then
cat > $dest_dir/$project_name/setup.override.php << EOF
<?php
define('DB_DSN', 'mysql://root:test@localhost/$project_name?charset=utf8');
EOF
fi
sudo chmod 777 $dest_dir/$project_name/var
php $dest_dir/$project_name/cli/load.php
#su -c "firefox $project_name" $user
#su -c "firefox $project_name/admin" $user