1 |
mocchiut |
1.1 |
#!/bin/bash --norc |
2 |
|
|
THISDIR=`pwd` |
3 |
|
|
USERNAME=${PAM_DBUSER} |
4 |
|
|
HOST="" |
5 |
|
|
DBNAME="" |
6 |
|
|
COUNT=0;for word in `echo ${PAM_DBHOST} | tr [\/] [" "] |sed 's/mysql://g' `; do if [ $COUNT -eq 0 ]; then HOST=`echo $word`; fi; if [ $COUNT -eq 1 ]; then DBNAME=`echo $word`; fi; let COUNT=$COUNT+1; done |
7 |
|
|
PASSWORD=${PAM_DBPSW} |
8 |
|
|
if [ $# -gt 0 ]; then |
9 |
mocchiut |
1.2 |
for INPUT in $*; do |
10 |
mocchiut |
1.1 |
if [ $INPUT == "--help" ] || [ $INPUT == "-h" ]; then |
11 |
|
|
echo "" |
12 |
|
|
echo " Usage: ./install_DB.sh [options] " |
13 |
|
|
echo "" |
14 |
|
|
echo " Options: " |
15 |
|
|
echo "" |
16 |
|
|
echo " --user=username : MySQL username. " |
17 |
|
|
echo "" |
18 |
|
|
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
19 |
|
|
echo "" |
20 |
|
|
echo " --psw=password : MySQL password" |
21 |
|
|
echo "" |
22 |
|
|
exit 0 |
23 |
|
|
fi |
24 |
|
|
TEST=`echo $INPUT | sed 's/--user=//g'` |
25 |
|
|
if [ $TEST != $INPUT ]; then |
26 |
|
|
USERNAME=`echo $TEST` |
27 |
|
|
export USERNAME; |
28 |
|
|
fi |
29 |
|
|
TEST=`echo $INPUT | sed 's/--host=//g'` |
30 |
|
|
if [ $TEST != $INPUT ]; then |
31 |
|
|
COUNT=0;for word in `echo $TEST | tr [\/] [" "] |sed 's/mysql://g' `; do if [ $COUNT -eq 0 ]; then HOST=`echo $word`; fi; if [ $COUNT -eq 1 ]; then DBNAME=`echo $word`; fi; let COUNT=$COUNT+1; done |
32 |
|
|
export DBNAME; |
33 |
|
|
export HOST; |
34 |
|
|
fi |
35 |
|
|
TEST=`echo $INPUT | sed 's/--psw=//g'` |
36 |
|
|
if [ $TEST != $INPUT ]; then |
37 |
|
|
PASSWORD=`echo $TEST` |
38 |
|
|
export PASSWORD; |
39 |
|
|
fi |
40 |
|
|
done |
41 |
|
|
else |
42 |
|
|
if [ "$USERNAME" == "" ] || [ "$HOST" == "" ] || [ "$DBNAME" == "" ]; then |
43 |
|
|
echo "" |
44 |
|
|
echo " Usage: ./install_GL_PARAM.sh [options] " |
45 |
|
|
echo "" |
46 |
|
|
echo " Options: " |
47 |
|
|
echo "" |
48 |
|
|
echo " --user=username : MySQL username. " |
49 |
|
|
echo "" |
50 |
|
|
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
51 |
|
|
echo "" |
52 |
|
|
echo " --psw=password : MySQL password" |
53 |
|
|
echo "" |
54 |
|
|
exit 0 |
55 |
|
|
fi |
56 |
|
|
fi; |
57 |
|
|
echo "" |
58 |
|
|
echo " Installing DB $DBNAME on $HOST with user $USERNAME and password $PASSWORD " |
59 |
|
|
echo "" |
60 |
|
|
echo " WARNING: if already existing the DB will be RECREATED and you will LOSE all data! " |
61 |
|
|
echo "" |
62 |
|
|
echo " =======> You have 30 seconds to stop me using CTRL+c <======= " |
63 |
|
|
echo "" |
64 |
|
|
sleep 30; |
65 |
|
|
# |
66 |
|
|
rm -rf ${THISDIR}/temp.sql |
67 |
|
|
# |
68 |
|
|
cat ${THISDIR}/PAMELAProductionDB.sql | sed 's/dbname/'${DBNAME}'/g' >> ${THISDIR}/temp.sql |
69 |
|
|
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST < ${THISDIR}/temp.sql |
70 |
|
|
echo " done! " |
71 |
|
|
echo "" |
72 |
|
|
rm -rf ${THISDIR}/temp.sql |