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