forked from fcerbell/jrs-extra-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·237 lines (219 loc) · 9.96 KB
/
install.sh
File metadata and controls
executable file
·237 lines (219 loc) · 9.96 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/bin/bash -e
BUILDOMATIC="/root/jasperreports-server-6.1.0-bin/buildomatic/"
TOMCATROOT="/var/lib/tomcat7/"
HTTPDROOT="/var/www/"
function Init(){ # Initializes the samples repository
aptitude -y update \
aptitude -y safe-upgrade \
&& aptitude -y dist-upgrade \
&& aptitude -y full-upgrade \
&& aptitude -y install git \
&& aptitude -y clean \
&& aptitude -y purge ~c
[ ! -d /jrs-extra-samples ] && git clone https://github.com/ernestoongaro/jrs-extra-samples.git /jrs-extra-samples
}
function Update(){ # Updates the local samples repository (no upgrade)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
cd /jrs-extra-samples
git pull
echo WARNING : The package file were updated to the latest revision which might not be compatible with
echo the versions of the software installed here.
}
function List(){ # Lists available samples
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
cd /jrs-extra-samples
for package in `find . -maxdepth 1 -type d | egrep -v '.git|^.$' | cut -d/ -f2-`; do
echo ${package}
done
}
function JRSImport(){ # Imports JRS repository for the specified sample (with update option)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -x ${BUILDOMATIC}/js-import.sh ] && echo "js-import script not found, edit configuration in ${0}." && exit 1
[ ! -d /jrs-extra-samples/${1}/repository ] && echo "No repository to import" && return
echo "Importing ${1} repository..."
cd ${BUILDOMATIC}
./js-import.sh --update --input-dir /jrs-extra-samples/${1}/repository
}
function MongoRestore(){ # Imports MondoDB DB for the specified sample (drops and recreates)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/database/mongodb/ ] && echo "No MongoDB database to import" && return
echo "Importing ${1} MongoDB database..."
mongorestore --drop /jrs-extra-samples/${1}/database/mongodb/
}
function SyncInfobright(){ # Makes a copy of a MySQL Schema to a Bighthouse schema
echo "Importing ${1} MySQL database in Infobright, too..."
db=${1}
[ -d /tmp/ibsync/${db} ] && rm -Rf /tmp/ibsync/${db}
mkdir -p /tmp/ibsync/${db}
chmod 777 /tmp/ibsync/${db}
cd /tmp/ibsync/${db}
echo "DROP DATABASE ${db};" | mysql-ib -proot || true
echo "CREATE DATABASE ${db};" | mysql-ib -proot
mysqldump -proot --skip-add-drop-table --no-data ${db} \
| sed 's#/\*[^*]*\*/##;s/^;//' \
| grep -v -- -- \
| sed ':a;N;$!ba;s/,\n \(UNIQUE \)\?KEY \+[^ ]\+ \+([^)]\+)//g' \
| sed ':a;N;$!ba;s/,\n PRIMARY KEY \+([^)]\+)//g' \
| sed 's/ AUTO_INCREMENT\(=[0-9]\+\)\?//' \
| sed 's/ decimal(\([0-9]\+\),\([0-9]\+\))/ dec(18,\2)/' \
| sed 's/ENGINE=MyISAM//' \
| tee /tmp/ibsync/${db}/${db}.sql \
| mysql-ib -proot ${db}
mysqldump -proot --tab=/tmp/ibsync/${db} --fields-terminated-by ';' --fields-optionally-enclosed-by '"' ${db}
for data in *.txt; do
sed -i 's/\\"//g' ${data}
echo "LOAD DATA INFILE '`pwd`/${data}' INTO TABLE \``basename ${data} .txt`\` FIELDS TERMINATED BY ';';" | mysql-ib -proot ${db}
done
cd /root
rm -Rf /tmp/ibsync/${db}
echo 'GRANT ALL PRIVILEGES ON *.* TO jasperdb@"%" IDENTIFIED BY "password"' | mysql-ib -proot
echo 'GRANT ALL PRIVILEGES ON *.* TO jasperdb@"localhost" IDENTIFIED BY "password"' | mysql-ib -proot
echo 'GRANT ALL PRIVILEGES ON *.* TO jasperdb@"127.0.0.1" IDENTIFIED BY "password"' | mysql-ib -proot
echo 'GRANT ALL PRIVILEGES ON *.* TO jasperdb@"'${GUEST}'" IDENTIFIED BY "password"' | mysql-ib -proot
}
function MySQLRestore(){ # Import a mySQL dump for the specified sample (drops and recreates)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/database/mysql/ ] && echo "No MySQL database to import" && return
echo "Importing ${1} MySQL database..."
for dump in /jrs-extra-samples/${1}/database/mysql/*.sql; do
if [ -f ${dump} ]; then
SCHEMA=`basename "$dump" .sql`
cat ${dump} | mysql -h localhost -uroot -proot
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'%' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'localhost' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot
SyncInfobright ${SCHEMA}
fi
done
for dump in /jrs-extra-samples/${1}/database/mysql/*.sql.gz; do
if [ -f ${dump} ]; then
SCHEMA=`basename "$dump" .sql.gz`
zcat ${dump} | mysql -h localhost -uroot -proot
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'%' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'localhost' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot
SyncInfobright ${SCHEMA}
fi
done
}
function PgRestore(){ # Import a PgSQL dump for the specified sample (drops and recreates)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/database/postgresql/ ] && echo "No PgSQL database to import" && return
echo "Importing ${1} PgSQL database..."
for dump in /jrs-extra-samples/${1}/database/postgresql/*.sql; do
if [ -f ${dump} ]; then
S=`basename "${dump}" .sql`
echo "DROP DATABASE ${S}" | su - postgres -c "psql"
echo "CREATE DATABASE ${S}" | su - postgres -c "psql"
cat ${dump} | su - postgres -c "psql ${S} "
fi
done
for dump in /jrs-extra-samples/${1}/database/postgresql/*.sql.gz; do
if [ -f ${dump} ]; then
S=`basename "${dump}" .sql.gz`
echo "DROP DATABASE ${S}" | su - postgres -c "psql"
echo "CREATE DATABASE ${S}" | su - postgres -c "psql"
zcat ${dump} | su - postgres -c "psql ${S} "
fi
done
}
function InfobrightRestore(){ # Import a mySQL dump for the specified sample (drops and recreates)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/database/infobright/ ] && echo "No Infobright database to import" && return
echo "Importing ${1} Infobright database..."
for dump in /jrs-extra-samples/${1}/database/infobright/*.sql; do
SCHEMA=`basename "$i" .sql`
cat ${dump} | mysql -h localhost -uroot -proot -P5029
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'%' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot -P5029
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'localhost' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot -P5029
done
for dump in /jrs-extra-samples/${1}/database/infobright/*.sql.gz; do
SCHEMA=`basename "$i" .sql.gz`
zcat ${dump} | mysql -h localhost -uroot -proot -P5029
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'%' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot -P5029
echo "GRANT ALL PRIVILEGES ON \`${SCHEMA}\`.* TO 'jasperdb'@'localhost' IDENTIFIED BY 'password';" | mysql -h localhost -uroot -proot -P5029
done
}
function InstallFiles(){ # Installs files in tomcat's root
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/filesystem/ ] && echo "No file to install" && return
echo "Installing ${1} files..."
if [ -d /jrs-extra-samples/${1}/filesystem/TOMCATROOT ]; then
TOMCATRESTART=1
cd /jrs-extra-samples/${1}/filesystem/TOMCATROOT
for file in `find ./ -type f`; do
rm -Rf ${TOMCATROOT}/${file}
mkdir -p ${TOMCATROOT}/${file}
rm -Rf ${TOMCATROOT}/${file}
cp ${file} ${TOMCATROOT}/${file}
chown tomcat7.tomcat7 ${TOMCATROOT}/${file}
done
fi
if [ -d /jrs-extra-samples/${1}/filesystem/HTTPDROOT ]; then
cd /jrs-extra-samples/${1}/filesystem/HTTPDROOT
for file in `find ./ -type f`; do
rm -Rf ${HTTPDROOT}/${file}
mkdir -p ${HTTPDROOT}/${file}
rm -Rf ${HTTPDROOT}/${file}
cp ${file} ${HTTPDROOT}/${file}
chown www-data.www-data ${HTTPDROOT}/${file}
done
fi
}
function InstallPatch(){ # Try to patch files (no overwrite)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/patch/ ] && echo "No file to patch" && return
echo "Installing ${1} patch"
cd /jrs-extra-samples/${1}/patch
for file in *.patch; do
TOMCATRESTART=1
FOLDER=`echo ${file} | tr '_' '/' | sed 's~\.patch$~~'`
cd ${FOLDER}
patch -p0 < /jrs-extra-samples/${1}/patch/${file}
cd -
done
}
function InstallScripts(){ # Installs Early/Late init scripts
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/scripts/ ] && echo "No scripts to install" && return
echo "Installing ${1} scripts"
REBOOT=1
cp -r /jrs-extra-samples/${1}/scripts /
chmod -R +x /scripts
}
function Install(){ # Installs a specific sample (Repo, DB, ...)
[ ! -d /jrs-extra-samples ] && echo "Samples repository not initialized, please 'init' first." && exit 1
[ ! -d /jrs-extra-samples/${1}/ ] && echo "Sample ${1} not found" && return
TOMCATRESTART=0
REBOOT=0
JRSImport ${1}
MongoRestore ${1}
MySQLRestore ${1}
InfobrightRestore ${1}
PgRestore ${1}
InstallFiles ${1}
InstallPatch ${1}
InstallScripts ${1}
if [ $REBOOT = 1 ]; then
rm -f /root/lastvalues.sh
echo '!!! Need to reboot !!!'
fi
if [ $TOMCATRESTART = 1 ]; then
echo '!!! Need to restart tomcat !!!'
/etc/init.d/tomcat7 stop
sleep 1
sync
rm -Rf /etc/tomcat7/Catalina/localhost/*
sync
sleep 1
/etc/init.d/tomcat7 start
fi
}
function Usage(){ # Help message
echo "${0} <COMMAND> [OPTIONS]"
echo
echo "Available commands :"
grep ^function ${0} | sort | grep -v Usage | sed 's/^function \([^(){]\+\).*#\(.*\)/- \1 : \2/'
}
if [ $# -lt 2 ]; then
Usage
fi
$*