1 |
#!/bin/bash --norc |
2 |
THISDIR=`pwd` |
3 |
USERNAME=${PAM_DBUSER} |
4 |
HOST="" |
5 |
DBNAME="" |
6 |
FORCE="no" |
7 |
GPAMELA="no" |
8 |
COUNT=0;for word in `echo ${PAM_DBHOST} | tr [\/] [" "] |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 |
9 |
PASSWORD=${PAM_DBPSW} |
10 |
if [ $# -gt 0 ]; then |
11 |
for INPUT in $*; do |
12 |
if [ $INPUT == "--help" ] || [ $INPUT == "-h" ]; then |
13 |
echo "" |
14 |
echo " Usage: ./install_DB.sh [options] " |
15 |
echo "" |
16 |
echo " Options: " |
17 |
echo "" |
18 |
echo " --user=username : MySQL username. " |
19 |
echo "" |
20 |
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
21 |
echo "" |
22 |
echo " --psw=password : MySQL password" |
23 |
echo "" |
24 |
echo " --force : do not wait [default: wait]" |
25 |
echo "" |
26 |
exit 0 |
27 |
fi |
28 |
TEST=`echo $INPUT | sed 's/--user=//g'` |
29 |
if [ $TEST != $INPUT ]; then |
30 |
USERNAME=`echo $TEST` |
31 |
export USERNAME; |
32 |
fi |
33 |
TEST=`echo $INPUT | sed 's/--host=//g'` |
34 |
if [ $TEST != $INPUT ]; then |
35 |
COUNT=0;for word in `echo $TEST | tr [\/] [" "] | 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 |
36 |
export DBNAME; |
37 |
export HOST; |
38 |
fi |
39 |
TEST=`echo $INPUT | sed 's/--psw=//g'` |
40 |
if [ $TEST != $INPUT ]; then |
41 |
PASSWORD=`echo $TEST` |
42 |
export PASSWORD; |
43 |
fi |
44 |
if [ "$INPUT" == "--force" ]; then |
45 |
FORCE="yes"; |
46 |
export FORCE; |
47 |
fi |
48 |
if [ "$INPUT" == "--gpamela" ]; then |
49 |
GPAMELA="yes"; |
50 |
export GPAMELA; |
51 |
fi |
52 |
done |
53 |
else |
54 |
if [ "$USERNAME" == "" ] || [ "$HOST" == "" ] || [ "$DBNAME" == "" ]; then |
55 |
echo "" |
56 |
echo " Usage: ./install_DB.sh [options] " |
57 |
echo "" |
58 |
echo " Options: " |
59 |
echo "" |
60 |
echo " --user=username : MySQL username. " |
61 |
echo "" |
62 |
echo " --host=mysql://localhost/pamelaprod : MySQL host and DB name." |
63 |
echo "" |
64 |
echo " --psw=password : MySQL password" |
65 |
echo "" |
66 |
exit 0 |
67 |
fi |
68 |
fi; |
69 |
echo "" |
70 |
echo " Installing DB $DBNAME on $HOST with user $USERNAME and password $PASSWORD " |
71 |
echo "" |
72 |
if [ "$FORCE" == "no" ]; then |
73 |
echo " WARNING: if already existing the DB will be RECREATED and you will LOSE all data! " |
74 |
echo "" |
75 |
echo " =======> You have 30 seconds to stop me using CTRL+c <======= " |
76 |
echo "" |
77 |
sleep 30; |
78 |
fi; |
79 |
# |
80 |
rm -rf ${THISDIR}/temp.sql |
81 |
# |
82 |
cat ${THISDIR}/PAMELAProductionDB.sql | sed 's/dbname/'${DBNAME}'/g' >> ${THISDIR}/temp.sql |
83 |
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST < ${THISDIR}/temp.sql |
84 |
echo " done! " |
85 |
# |
86 |
# |
87 |
# |
88 |
if [ "$GPAMELA" == "yes" ]; then |
89 |
echo "" |
90 |
echo " Adapting GL_PARAM table to be used with simulated data " |
91 |
echo "" |
92 |
# |
93 |
rm -rf ${THISDIR}/temp.sql |
94 |
# |
95 |
cat ${THISDIR}/GP_PARAM.sql | sed 's/dbname/'${DBNAME}'/g' >> ${THISDIR}/temp.sql |
96 |
mysql --user=$USERNAME --password=$PASSWORD --host=$HOST < ${THISDIR}/temp.sql |
97 |
# |
98 |
echo " done! " |
99 |
fi; |
100 |
# |
101 |
echo "" |
102 |
rm -rf ${THISDIR}/temp.sql |