Commit cfccef7de7eb64e5175aa5db98bfb1c97aa8a859
0 parents
first commit
Showing
2 changed files
with
273 additions
and
0 deletions
README.md
0 → 100644
1 | +++ a/README.md | ... | ... |
spod-manager.sh
0 → 100755
1 | +++ a/spod-manager.sh | |
1 | +#!/bin/bash | |
2 | +######################################################################## | |
3 | +#SPOD INSTALLATION SCRIPT############################################### | |
4 | +#FIRST VERSION 29/09/2015############################################### | |
5 | +######################################################################## | |
6 | +################OXWALL CONFIGURATION DATA############################### | |
7 | +CONFIG0=" | |
8 | +<?php | |
9 | + | |
10 | +define('OW_URL_HOME', '" | |
11 | +CONFIG1="'); | |
12 | + | |
13 | +define('OW_DB_HOST', 'localhost'); | |
14 | +define('OW_DB_PORT', null); | |
15 | +define('OW_DB_USER', 'root'); | |
16 | +define('OW_DB_PASSWORD', 'is15rdc'); | |
17 | +define('OW_DB_NAME', 'oxwall'); | |
18 | + | |
19 | +define('OW_DB_PREFIX', 'ow_'); | |
20 | + | |
21 | +define('OW_DIR_USERFILES', OW_DIR_ROOT.'ow_userfiles'.DS); | |
22 | +define('OW_DIR_STATIC', OW_DIR_ROOT.'ow_static'.DS); | |
23 | +define('OW_URL_STATIC', OW_URL_HOME.'ow_static/'); | |
24 | +define('OW_URL_USERFILES', OW_URL_HOME.'ow_userfiles/'); | |
25 | +define('OW_DIR_PLUGINFILES', OW_DIR_ROOT.'ow_pluginfiles/'); | |
26 | + | |
27 | +define('OW_PASSWORD_SALT', 'UzYBYBE6yWA4EhaD'); | |
28 | + | |
29 | +define('OW_DIR_CORE', OW_DIR_ROOT.'ow_core'.DS); | |
30 | +define('OW_DIR_INC', OW_DIR_ROOT.'ow_includes'.DS); | |
31 | +define('OW_DIR_LIB', OW_DIR_ROOT.'ow_libraries'.DS); | |
32 | +define('OW_DIR_UTIL', OW_DIR_ROOT.'ow_utilities'.DS); | |
33 | +define('OW_DIR_PLUGIN', OW_DIR_ROOT.'ow_plugins'.DS); | |
34 | +define('OW_DIR_THEME', OW_DIR_ROOT.'ow_themes'.DS); | |
35 | +define('OW_DIR_SYSTEM_PLUGIN', OW_DIR_ROOT.'ow_system_plugins'.DS); | |
36 | +define('OW_DIR_SMARTY', OW_DIR_ROOT.'ow_smarty'.DS); | |
37 | + | |
38 | +define('OW_USE_CLOUDFILES', false); | |
39 | + | |
40 | +if ( defined('OW_CRON') ) | |
41 | +{ | |
42 | + define('OW_DEBUG_MODE', false); | |
43 | + define('OW_DEV_MODE', false); | |
44 | + define('OW_PROFILER_ENABLE', false); | |
45 | +} | |
46 | +else | |
47 | +{" | |
48 | +CONFIG2=" | |
49 | + define('OW_DEBUG_MODE', false); | |
50 | + define('OW_DEV_MODE', true); | |
51 | + define('OW_PROFILER_ENABLE', false); | |
52 | +}" | |
53 | +CONFIG3=" | |
54 | + define('OW_DEBUG_MODE', false); | |
55 | + define('OW_DEV_MODE', false); | |
56 | + define('OW_PROFILER_ENABLE', false); | |
57 | +}" | |
58 | +############################################################################# | |
59 | +#Checking if it is root access | |
60 | +if [ "$EUID" -ne 0 ]; | |
61 | +then | |
62 | + echo "Please run as root"; | |
63 | + exit -1; | |
64 | +fi | |
65 | +############################################################################# | |
66 | +#Checking Apche installation on local machine | |
67 | +APACHE=$(which apache2) | |
68 | +if [ -z "$APACHE" ]; then | |
69 | + echo "Apache server is required." | |
70 | + exit -2 | |
71 | +fi | |
72 | +############################################################################# | |
73 | +SCRIPT_NAME="spod-manager.sh" | |
74 | +#Arguments | |
75 | +OPTIONS=$(getopt -o ha:b:m:n:o:p:q:r:s:w:d: -l help,action:,backup-dir:,mysql-username:,mysql-password:,mysql-address:,spod-git-username:,spod-git-email:,spod-git-password:,spod-git-address:,spod-hostname:,spod-database-version: -- "$@") | |
76 | + | |
77 | +if [ $? -ne 0 ]; then | |
78 | + echo "error in parameters." | |
79 | + exit -1 | |
80 | +fi | |
81 | + | |
82 | +eval set -- $OPTIONS | |
83 | +MYSQLHOST="127.0.0.1" | |
84 | +GITSPOD="service.routetopa.eu:7480" | |
85 | +BACKUPDIR=$(pwd) | |
86 | +DB="db_dump/oxwall1709.sql" | |
87 | +while true; do | |
88 | + case "$1" in | |
89 | + -h|--help) | |
90 | + echo "$SCRIPT_NAME is manager tool for SPOD application of ROUTE-TO-PA European project all rights are reserved. 2015" | |
91 | + echo " " | |
92 | + echo "list of arguments:" | |
93 | + echo "-h, --help show commands help" | |
94 | + echo "-a, --action=ACTION specify an action install, uninstall, update and backup." | |
95 | + echo "-m, --mysql-username=username specify the username of mysql (*)." | |
96 | + echo "-n, --mysql-password=password specify the password of mysql server (*)." | |
97 | + echo "-o, --mysql-address=address specify the address of mysql server (deafult is localhost)." | |
98 | + echo "-p, --spod-git-username=user specify the user name of SPOD git server (*)." | |
99 | + echo "-q, --spod-git-email=email specify the email of SPOD git server (*)." | |
100 | + echo "-r, --spod-git-password=password specify the passoword of SPOD git server (*)." | |
101 | + echo "-s, --spod-git-address=address:port specify the SPOD git server (deafult is service.routetopa.eu:7480)." | |
102 | + echo "-w, --spod-hostname=hostname specify the SPOD host name (example http://spod.routetopa.eu/)." | |
103 | + echo "-d, --spod-database-version=db specify the SPOD db git path located in db_dump of SPOD git core (example oxwall_v.0.1_antares.sql, deafults is really simple SPOD and Oxwall installation)." | |
104 | + echo "-b, --backup-dir=DIR specify the directory where store the spod backup (default is current directory)." | |
105 | + echo "* the arguments is required." | |
106 | + exit 0; | |
107 | + ;; | |
108 | + -a|--action) | |
109 | + ACTION="$2"; shift | |
110 | + ;; | |
111 | + -b|--backup-dir) | |
112 | + BACKUPDIR="$2"; shift | |
113 | + ;; | |
114 | + -m|--mysql-username) | |
115 | + MYSQLUSERNAME="$2"; shift | |
116 | + ;; | |
117 | + -n|--mysql-password) | |
118 | + MYSQLPASSWORD="$2"; shift | |
119 | + ;; | |
120 | + -o|--mysql-address) | |
121 | + MYSQLHOST="$2"; shift | |
122 | + ;; | |
123 | + -p|--spod-git-username) | |
124 | + GITUSER="$2"; shift | |
125 | + ;; | |
126 | + -q|--spod-git-email) | |
127 | + GITEMAIL="$2"; shift | |
128 | + ;; | |
129 | + -r|--spod-git-password) | |
130 | + GITPASSWORD="$2"; shift | |
131 | + ;; | |
132 | + -s|--spod-git-address) | |
133 | + GITHOST="$2"; shift | |
134 | + ;; | |
135 | + -w|--spod-hostname) | |
136 | + HOSTNAMESPOD="$2"; shift | |
137 | + ;; | |
138 | + -d|--spod-database-version) | |
139 | + DB="$2"; shift | |
140 | + ;; | |
141 | + --) shift; break | |
142 | + ;; | |
143 | + *) | |
144 | + echo "unknown option: $1" ; exit 1 ;; | |
145 | + esac | |
146 | + shift | |
147 | +done | |
148 | + | |
149 | +############################################################################# | |
150 | +############################################################################# | |
151 | +############################################################################# | |
152 | +############################################################################# | |
153 | +############################################################################# | |
154 | +#Script Actions | |
155 | +if [ -z "$ACTION" ]; | |
156 | +then | |
157 | + echo "You must specify a valid action."; | |
158 | + exit -2; | |
159 | +fi | |
160 | +if [ $# -ne 0 ]; then | |
161 | + echo "unknown option(s): $@"; | |
162 | + exit 1; | |
163 | +fi | |
164 | + | |
165 | +echo "SPOD MANAGER Action: $ACTION ..." | |
166 | + | |
167 | + case "$ACTION" in | |
168 | + "install") | |
169 | + if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] || [ -z "$GITUSER" ] || [ -z "$GITEMAIL" ] || [ -z "$GITPASSWORD" ] [ -z "$HOSTNAMESPOD" ]; | |
170 | + then | |
171 | + echo "You must specify the mysql password - username; git user - email - password; SPOD hostname in order to unistall SPOD." | |
172 | + exit -2 | |
173 | + fi | |
174 | + git config --global user.name "$GITUSER" | |
175 | + git config --global user.email "$GITEMAIL" | |
176 | + cd /var/www | |
177 | + git init | |
178 | + git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-core.git | |
179 | + git pull origin master | |
180 | + mkdir /var/www/ow_plugins | |
181 | + cd /var/www/ow_plugins | |
182 | + git init | |
183 | + git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-plugins.git | |
184 | + git pull origin master | |
185 | + mkdir /var/www/ow_themes | |
186 | + cd /var/www/ow_themes | |
187 | + git init | |
188 | + git remote add origin http://$GITUSER:$GITPASSWORD@$GITSPOD/isislab/spod-themes.git | |
189 | + git pull origin master | |
190 | + mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "create database if not exists oxwall;" | |
191 | + mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST --database=oxwall < /var/www/db_dump/$DB | |
192 | + chown www-data:www-data -R /var/www | |
193 | + rm -f /var/www/ow_includes/config.php | |
194 | + echo $CONFIG0$HOSTNAMESPOD$CONFIG1$CONFIG2 >> /var/www/ow_includes/config.php | |
195 | + service apache2 restart | |
196 | + wget -q -O /dev/null http://localhost/ | |
197 | + rm -f /var/www/ow_includes/config.php | |
198 | + echo $CONFIG0$HOSTNAMESPOD$CONFIG1$CONFIG3 >> /var/www/ow_includes/config.php | |
199 | + CRONCHECK=$(crontab -l); | |
200 | + if [[ $CRONCHECK == *"http://localhost/ow_cron/run.php"* ]]; | |
201 | + then | |
202 | + echo "Cron job already exists"; | |
203 | + else | |
204 | + crontab -l | { cat; echo "* * * * * wget -q -O /dev/null http://localhost/ow_cron/run.php"; } | crontab - | |
205 | + fi | |
206 | + ;; | |
207 | + "uninstall") | |
208 | + if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] ; | |
209 | + then | |
210 | + echo "You must specify the mysql password and username to unistall SPOD." | |
211 | + echo " sudo ./spod-manager.sh -a uninstall -m user -n password" | |
212 | + exit -2 | |
213 | + fi | |
214 | + mysql -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST -e "drop database oxwall;" | |
215 | + rm -rf /var/www/* | |
216 | + rm -rf /var/www/.[^.]* | |
217 | + crontab -l | sed '/http:\/\/localhost\/ow_cron\/run\.php/d' | crontab - | |
218 | + ;; | |
219 | + "backup") | |
220 | + if [ -z "$MYSQLUSERNAME" ] || [ -z "$MYSQLPASSWORD" ] ; | |
221 | + then | |
222 | + echo "You must specify the mysql password and username to unistall SPOD." | |
223 | + exit -2 | |
224 | + fi | |
225 | + service apache2 stop | |
226 | + | |
227 | + DATEDIR=$(date +%Y-%m-%d-%N) | |
228 | + IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') | |
229 | + | |
230 | + mkdir -p $BACKUPDIR/$DATEDIR | |
231 | + mysqldump -u $MYSQLUSERNAME -p$MYSQLPASSWORD --host=$MYSQLHOST oxwall | gzip > $BACKUPDIR/$DATEDIR/db_backup_spod.sql.gz | |
232 | + | |
233 | + mkdir $BACKUPDIR/$DATEDIR/var | |
234 | + cp -r /var/www $BACKUPDIR/$DATEDIR/var | |
235 | + service apache2 start | |
236 | + ;; | |
237 | + "update") | |
238 | + if [ -z "$GITUSER" ] || [ -z "$GITEMAIL" ] || [ -z "$GITPASSWORD" ] ; | |
239 | + then | |
240 | + echo "You must specify the SPOD git credentials." | |
241 | + exit -2 | |
242 | + fi | |
243 | + git config --global user.name "$GITUSER" | |
244 | + git config --global user.email "$GITEMAIL" | |
245 | + if [ -x /var/www/.git ] && [ -x /var/www/ow_plugins ] && [ -x /var/www/ow_themes ]; then | |
246 | + cd /var/www | |
247 | + git pull origin master | |
248 | + | |
249 | + cd /var/www/ow_plugins | |
250 | + git pull origin master | |
251 | + | |
252 | + cd /var/www/ow_themes | |
253 | + git pull origin master | |
254 | + | |
255 | + service apache2 restart | |
256 | + wget -q -O /dev/null http://localhost/ow_cron/run.php | |
257 | + else | |
258 | + echo "Your SPOD installation is corrupt, please uninstall and istall it again. Your database will be erased." | |
259 | + exit -2 | |
260 | + fi | |
261 | + ;; | |
262 | + *) | |
263 | + echo "No valid action found."; | |
264 | + exit -1; | |
265 | + ;; | |
266 | +esac | |
267 | +############################################################################################## | |
268 | +############################################################################################## | |
269 | +############################################################################################## | |
270 | +############################################################################################## | |
271 | +############################################################################################## | |
272 | +############################################################################################## | |
273 | +############################################################################################## | ... | ... |